Forum Discussion
Altera_Forum
Honored Contributor
11 years agoBPSK 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
Honored Contributor
Hello Mr Kazem. Back to work :)
--- Quote Start --- the filter must pass dc but cut highband at 0.2 (of Fs) the function fir1 that I used cuts off at 0.3 of Nyquist (i.e. 0.3/2 of Fs = 0.15 so is just right for single tone). --- Quote End --- 1- I checked the frequency response of this filter using freqz. But it shows the cutoff frequency at 0.3 not 0.15. 2- Regarding the control of NCO, I just have this thought and please explain. If we control frequency as you suggest, suppose that the RF carrier is 0.2 and I tuned my radio to 0.1, the loop will push until it reaches 0.2, right? Will the loop span all the range from 0.1 to 0.2 to lock? Suppose there is another RF signal with carrier 0.15, don't you think it might lock on it while it's looking for 0.2? I just have this thought nagging on me for a while, I hope you explain it. 3- You told me that variable 'i' in the 'for' loop represents phase, why not time? 4- I attached a simulation of Costas Loop I found on MATLAB FileExchange. I hope you check it. - Altera_Forum
Honored Contributor
freqz displays f normalised in radians so 1 means 0.5 of Fs and 0.3 means 0.15Fs.
Your thinking is right about loop and if somebody wants to jam you on .15 then take him to court. If he is doing legally adjacent to your band then set your nominal nco to a closer start such as .20 i is index of sample (time/period) and phase then equals that index as part of the gang i*2*pi *inc for the cos/sin values. Time here has no meaning until you apply specific Fs. - Altera_Forum
Honored Contributor
--- Quote Start --- freqz displays f normalised in radians so 1 means 0.5 of Fs and 0.3 means 0.15Fs. Your thinking is right about loop and if somebody wants to jam you on .15 then take him to court. If he is doing legally adjacent to your band then set your nominal nco to a closer start such as .20 i is index of sample (time/period) and phase then equals that index as part of the gang i*2*pi *inc for the cos/sin values. Time here has no meaning until you apply specific Fs. --- Quote End --- Thank you Mr KAZ. I hope you check that file and see if it can help to model our loop. (Actually it does have different behavior when you change - to + in error signal). - Altera_Forum
Honored Contributor
--- Quote Start --- Thank you Mr KAZ. I hope you check that file and see if it can help to model our loop. (Actually it does have different behavior when you change - to + in error signal). --- Quote End --- I did some read on that file. This guy is probably funny trying to match some absolute phase of two signals. This is meaningless unless he got some specific application. absolute phase is meaningless to control as signal could arrive at any phase and this is immaterial in most radios (possibly all radios). what we want is to control frequency through phase until rf signal is centred on dc. Phase then doesn't matter and you should not compare phase if signals are of different frequencies. don't mix up with PLL that generate clock in phase with ref. - Altera_Forum
Honored Contributor
Hhhhhhhh What do you want Mr Kazem!!! Matlab is meant to prove math through math... not like ModelSim prove math through hardware, even though it's not giving correct results. Problem is either in the idea, or in our predictions. Idea is true since it's not that hard to write mathematical equations in Matlab.
I have a question, how different is a Costas Loop for QPSK than BPSK? I think it should be the same with one difference, the quadrature component in BPSK has no information while it does have in QPSK, and it should not affect Costas Loop in both cases. Is this correct? - Altera_Forum
Honored Contributor
--- Quote Start --- Hhhhhhhh What do you want Mr Kazem!!! Matlab is meant to prove math through math... not like ModelSim prove math through hardware, even though it's not giving correct results. Problem is either in the idea, or in our predictions. Idea is true since it's not that hard to write mathematical equations in Matlab. --- Quote End --- I don't quite understand your thoughts. Unless proved otherwise I believe strongly now that the free simplified documented design for BPSK carrier tracking does not work efficiently because the error of sin*cos is vague except at very start cycle of sine wave. This start is marred with filter delay and vanishes quickly. I suggets you use the costas loop for qpsk/qam which I did. This loop's error is based on slicer output. You will need to see diagrams of that loop which is based on complex multiplication with sliced values of I/Q together with signal I/Q to produce error. In your case you have only two sliced states either -1 or +1. So the concept of I/Q sliced data doesn't apply but may be you can use it but ignore the Q channel at the end. For QPSK it was particulary efficient. So I guess for BPSK as well. Try your skill again with modelling it that way. To slice the symbols you need to have threshold after matched rrc then feedback the results into error detector. - Altera_Forum
Honored Contributor
OMG! Our brains are synchronized without a Costas Loop! :D
I edited my previous post to ask you about QPSK error circuitry! You are amazing Kazem!! I'm gonna model it right away! - Altera_Forum
Honored Contributor
Alright, this code uses a slicer to calculate error:
I didn't feed the phase back to NCO just to observe the error and phase signals. They look acceptable and have some life. Plus, if I add instead of subtract error I get an opposite signals. However, I tried to control NCO through phase and frequency and none got me a good result. But I feel that error signal without feedback is correct. I attached the RRC coeff so that you can try this code if you like.clear clc load RRC.mat rf_signal = cos(2*pi*(1:5000)*0.1); N = length(rf_signal); phi_inc = zeros(1, N); 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); error_f = zeros(1, N); %loop filter coefficients alpha = 0.1; b = alpha; a = ; fs = 1.0E8; fc = 0.1; for i = 1:N % Downconverting to Baseband bb(i) = rf_signal(i).*exp(j*2*pi*fc*i); % 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_f = filter(b, a, error(1:i)); phi_inc(i+1) = phi_inc(i) - error_f(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; plot(phi_inc); title('Phase'); figure; plot(error_f); title('Error'); - Altera_Forum
Honored Contributor
I can notice that I component has a DC offset... how can I get rid of it inside for loop? And do I have to scale to unity as you did?
- Altera_Forum
Honored Contributor
--- Quote Start --- I can notice that I component has a DC offset... how can I get rid of it inside for loop? And do I have to scale to unity as you did? --- Quote End --- You will get dc on both I and Q when it works. So if set rf freq and nco to target dc you get it. Depending on rf phase I or Q could be any pair of constants. you don't have dc in rf signal because it is man made clean tone. In real rf you should remove dc (or else it moves to nco frequency where you can filter it. if you get error changing sense you got it. next how to be gentle with nco: the error is basically mad. you need to filter it through IIR and add it proportional term (error x 8 or x 100...) and even a second accum if it helps. finally you scale the error (division by 2^n i.e. later shift in hardware). The scaling is also critical since in your model your nco expects +/- 0 ~ 0.5 range and very gently. run your model in feedback loop, set addition of error to zero to kill the loop effect. Then observe the error, the filtered error and final error and make sure it is gentle and with above nco range. In hardware the tuning word will have to be scaled and things will need proper scaling.