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
--- Quote Start --- There is no indication of lock. You have killed the error by /1e5 then (5*10^-5) , this adds almost nothing to nco tuning word whose range is 0 ~ +/-0.5 for .1 case error should settle zero and filtered signal should be dc (I think you got that because error is forced to nothing) for .09 and .11 case error should settle at .01 (either plus or minus) and filtered signal should be dc (not sine wave) --- Quote End --- correction: can you set RF signal to 0.1, 0.11,0.09 and keep nco at 0.1 also why you have nested your filter function twice? - Altera_Forum
Honored Contributor
I rerun the code without killing the error and bringing it back to life (as Celine Dion says :P )
But nothing changed... exactly same result. So, it's not behaving as Costas Loop. What do you suggest? I surrender! (Also as Celine Dion says :D ) - Altera_Forum
Honored Contributor
--- Quote Start --- correction: can you set RF signal to 0.1, 0.11,0.09 and keep nco at 0.1 --- Quote End --- I will try now. --- Quote Start --- also why you have nested your filter function twice? --- Quote End --- Because you said to filter 200 taps x 2... remember? By the way I tried to filter once... I just got a high frequency component. - Altera_Forum
Honored Contributor
--- Quote Start --- correction: can you set RF signal to 0.1, 0.11,0.09 and keep nco at 0.1 --- Quote End --- Nothing changed also! - Altera_Forum
Honored Contributor
--- Quote Start --- Nothing changed also! --- Quote End --- Now what I said should apply but as follows: phy_inc should settle to 0.1, 0.11 and 0.09 for the three cases. I & Q should be dc only in all three cases especially towards end of vector if lock occurs. error may oscillate initially. Do not kill the error by that scaling, you need a target of .01 be added or subtracted from nco value of 0.1 initially. Once the nco is set to this correct value then the error I think will tend to drop towards zero. 200 x 2 does not mean nesting. I simply meant resource of two flters each 200 taps so it 200 x 2 (one per branch) use y = filter(LPF,1,x(1:i)); if it doesn't cut the high band then check response. - Altera_Forum
Honored Contributor
well I finally tried my muscles. There is some life in it but it requires a lot of tweaks. It lloks it is tending to lock but requires very long stime so I tried 6000 samples.
clear all; close all; clc; N = 6000; h = fir1(100,0.3); rf_signal = cos(2*pi*(0:N-1)*0.1); %.1,.11,.09 bb_sig = zeros(1, N); y_f = zeros(1, N); error_sig = zeros(1, N); error_f = zeros(1, N); %PLL fs = 1; f = .1; phi_inc = f/fs; for i = 1:N %Downconverting to Baseband bb_sig(i) = rf_signal(i)*exp(j*2*pi*i*phi_inc); %Filtering y_f = filter(h,1,bb_sig(1:i)); %Error error(i) = real(y_f(i))*imag(y_f(i))/2^16; phi_inc = phi_inc - error(i); temp(i) = phi_inc; end plot(temp,'.-'); figure; plot(error); figure; plot(real(y_f(end-1000:end)),'.-'); - Altera_Forum
Honored Contributor
1- I ran your code for 12000 samples, output signal got distorted, why?
2- You are changing the frequency rather than shifting phase. Is it what you intend to do? My code controls phase not frequency. 3- Why are you dividing by 2^16? 4- Phase, or more precisely, frequency is settling at 0.1, 0.11, 0.09 as you mentioned, but I don't see I&Q as DC... they are sinusoidal waves. - Altera_Forum
Honored Contributor
--- Quote Start --- 1- I ran your code for 12000 samples, output signal got distorted, why? 2- You are changing the frequency rather than shifting phase. Is it what you intend to do? My code controls phase not frequency. --- Quote End --- when you run nco you control the tuning word (phi_inc). That is what I am doing. phase and frequency are related. In design the nco will keep running nonstop from phase 1 and after some clocks (latency) its tuning word is updated. In the code the index i is the phase and it is incremented steadily. If you can run modelsim it gets much easier to check long sims and do any tweaks. The important thing initial is to watch the phi_in value tending towards the rf centre frequency. once it settles the signal will settle at a constant (dc). /2^16 is the tweek that turned out to control the loop better for our setup. you may require modifying it in final sign off of your radio ! output may look sinusoidal but check dynamic range (is it around zero or just osscilation around a constant level) - Altera_Forum
Honored Contributor
the filter needs to cut off the high sidband.
rf signal has two frequencies at +0.1 and -0.1 when we mix it with 0.1 (or you can choose =-0.1) we get the sum and the difference: 0.1 + 0.1 = 0.2 (high sideband) 0.1 - 0.1 = 0 (our dream dc) 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). bwt this costas loop seems horrible to control compared to my previous work on qpsk/qam which was predictable. in this loop even if reverse the sense of error I get same result. so surely this is not how it should be done. If you make research and find out I will be interested to know. Should we use filter for the error (I tried IIR and IIR + a second accum and lost control). - Altera_Forum
Honored Contributor
Thank you so much for bearing with me Mr Kazem.
I really got tired today, I'll see what I can do tomorrow and let you know.