Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

BPSK Demodulation

Hello again, I am still struggling with BPSK demodulation :)

OK, now I am trying to implement Costas Loop for carrier synchronization, which involves Inphase and Quadrature Phase paths.

Inphase is looking good, and works as expected, however, the Q component looks awkward. Take a look at these waveforms:

http://www.alteraforum.com/forum/attachment.php?attachmentid=10363&stc=1

I understand that multiplying sin * cos will produce a high frequency component, which is a sin modulated by half amplitude of the data signal.

BPSK(t) * sin(2*pi*f*t) = 0.5 * [DATA(t) * sin(0) + DATA(t) * sin(2*pi*f*t)]

=> 0.5 * DATA(t) * sin(2*pi*f*t)

=> LPF{0.5 * DATA(t) * sin(2*pi*f*t)} = 0

I feel that problem is in my LPF. I used the same Matched RRC filter that I used in the in-phase arm.

Papers I read didn't mention that these two filters should be different, that's why I used the same filter.

(I think those are unpractical DSP writers, KAZ :D )

So, should I use a separate Loop Filter for Q component? How do I determine it's parameters?

66 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    1- Isn't that the supposed situation? I mean, I am expected to provide a fixed frequency and the carrier synchronizer has the job of recovering the phase, isn't it?

    2- Do I understand that the first design (sin*cos) tracks phase only, while the above design (using sign circuitry) tracks frequency?

    3- Surprisingly, before you post I was trying to simulate this design using my original BPSK signal, and the above design failed to demodulate properly even though the loop locked. I eventually did as you mentioned, I used the sin*cos approach and eliminated the "Phase Accumulator" and used the PhErr signal to control NCO. It did demodulate and lock! I tried to shift the local NCO phase and tried to set fc at 0.050001 (TX's fc is 0.05) and it locked.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    There is here misunderstanding and it is difficult.

    A true receiver (for wireless QAM) needs first to have clock recovery circuit to lock to Tx clock and this is a nightmare.

    Once clock is recovered then other things are clocked by this pace maker.

    The carrier tracking at Rx needs to lock to both rf frequency and phase. You may know the nominal Tx frequency centre but due to oscillator jitter and shift at both ends (and any mobile Rx) it will have to follow it. The phase must also lock at least in one qaudrant terms(1 of 4 quadrants for a cycle). It is no good locking to same freq but a changing or tilted phase.

    The difficulty here is to understand these two concepts (freq and phase). If you can control phase of two different freqs you control both. freq and phase. If you control freq only you control freq ONLY.

    some designs control either or both.

    Your 1st design requires somebody else to control freq (apparently as we couldn't see any useful sense of error to be useful to push signal to baseband) but if given two inputs at same freq centre then it does give enough error to lock to one quadrant of cycle.

    To test it keep rf and nco freqs at .1 then change the phase rf and see error.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    The difficulty here is to understand these two concepts (freq and phase). If you can control phase of two different freqs you control both. freq and phase. If you control freq only you control freq ONLY.

    --- Quote End ---

    This exactly what I'm doing and think I've done. Costas loop is meant to give PHASE error which happens to be very sensitive to small differences (2 times delta theta). And as you've just said, controlling phase means controlling both freq and phase.

    --- Quote Start ---

    Your 1st design requires somebody else to control freq (apparently as we couldn't see any useful sense of error to be useful to push signal to baseband) but if given two inputs at same freq centre then it does give enough error to lock to one quadrant of cycle.

    To test it keep rf and nco freqs at .1 then change the phase rf and see error.

    --- Quote End ---

    The later design is pretty much the first one except that I used a loop filter now, and it seemed that I tested phase offsets in a wrong way in the first design (maybe it was good and working... anyway, this is better).

    I tested as you said, I set RF and NCO at 0.05, then changed the phase of NCO by pi/8, pi/7, pi/3 and it demodulated and locked in all tests.

    Do I say Yuppie now? :D
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Yuppie Yupp. Is that Uni project? I won't tell anybody

    --- Quote End ---

    Yuppieeeeeeeeeeeeeeeeeeeeee!! I am always afraid from your comments to have my designs wrong LOL! But this one is the best :D

    Yes it is my graduation project... Titled "SoC FPGA-Based Software-Defined Radio" and I think you deserve to mention your name in the thanks page :D

    Why won't you tell anybody? Hhhhhhhhhh
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    In this one, you are using a rf-signal (cosine wave). How this one can be BPSK signal?

    1.What is inside RRC.mat?

    2.How did you choose Bandwith = 200 hz.

    Please reply to my questions.

    --- Quote Start ---

    Hello Kazem :)

    I think I did it this time. Please take your time and test it at your leisure before judging :D

    
    clear
    clc
    load RRC.mat
    fc = 0.1 % 0.11  %0.09
    rf_signal = cos(2*pi*(1:5000)*0.1);
    N = length(rf_signal);
    bb = zeros(1, N);
    bb_f = zeros(1, N);
    I_f = zeros(1, N);
    Q_f = zeros(1, N);
    I_r = zeros(1, N);
    Q_r = zeros(1, N);
    error = zeros(1, N);
    PhErr = zeros(1, N);
    error_integral = zeros(1, N);
    Theta = zeros(1, N);
    % Loop Filter Coefficients
    BW = 200;  % Hz
    loop_theta = 2*pi*BW;
    C1 = 4*(loop_theta)^2/(1+sqrt(2)*loop_theta+loop_theta^2);
    C2 = 2*sqrt(2)*loop_theta/(1+sqrt(2)*loop_theta+loop_theta^2);
    for i = 2:N
        % Downconverting to Baseband
        bb(i) = rf_signal(i).*exp(j*2*pi*fc*i).*exp(j*Theta(i-1));
        % Filtering
        bb_f = filter(RRC, bb(1:i));
        I_f(i) = real(bb_f(i));
        Q_f(i) = imag(bb_f(i));
        
        % Slicing
        if I_f(i) > 0
            I_r(i) = 1;
        else
            I_r(i) = -1;
        end
        
        if Q_f(i) > 0
            Q_r(i) = 1;
        else
            Q_r(i) = -1;
        end
        
        % Error
        error(i) = I_f(i) .* Q_r(i) - Q_f(i) .* I_r(i);
        
        % Loop Filter
        error_integral(i) = error(i).*C1 + error_integral(i-1);
        PhErr(i) = error(i).*C2 + error_integral(i);
        
        % Phase Accumulator
        Theta(i) = Theta(i-1) + PhErr(i);
        
    end
    figure
    subplot 221
    plot(real(bb))
    title('I Channel')
    subplot 222
    plot(imag(bb))
    title('Q Channel')
    subplot 223
    plot(I_f)
    title('I Channel Filter')
    subplot 224
    plot(Q_f)
    title('Q Channel Filter')
    figure; subplot 311; plot(error); title('Phase Error');
    subplot 312; plot(PhErr); title('Loop Filter');
    subplot 313; plot(Theta); title('Control Signal \theta');
    

    Just to motivate you, look at these signals:

    http://www.alteraforum.com/forum/attachment.php?attachmentid=10422&stc=1

    http://www.alteraforum.com/forum/attachment.php?attachmentid=10423&stc=1

    --- Quote End ---