Forum Discussion
Costas Loop oscillates in ModelSim while locks in MATLAB!
Hello again,
I have designed a Costas Loop in MATLAB and it simulates very well... locking and recovering the carrier. Here are the results: http://www.alteraforum.com/forum/attachment.php?attachmentid=10456&stc=1 I ported the design to FPGA in VHDL, and simulated in ModelSim... however, the loop has a kinda oscillating behaviour... take a look: http://www.alteraforum.com/forum/attachment.php?attachmentid=10457&stc=1 This is the Loop Filter output: http://www.alteraforum.com/forum/attachment.php?attachmentid=10458&stc=1 Why is it oscillating? Is it the loop filter?46 Replies
- Altera_Forum
Honored Contributor
--- Quote Start --- My input is a bpsk signal. I didn't get the second question. What do you mean by "but for bpsk signal I expect to see constellations of +/- on each I and Q"? I was trying several things before I post this thread... and each one yields to different result... however when I open the loop they all give the same falling slope that I get in matlab if I open the loop. Let's try to eliminate options... 1- Do you recommend using Altera's NCO (First post in the thread) or go on with my DDS (previous post)? 2- I tried to use RRC after mixers instead of CIC... but CIC gave more closer results... what do you think about it? would it be a major cause to the problem? 3- I am scaling down the loop filter output that is used to subtract or add with NCO phi_inc. Am I right? --- Quote End --- Altera nco is ok. "my dds" is an nco if it works! there is no difference but possibly altera's one will have higher resolution (for phase). To answer other questions follow this test: ignore carrier tracking. Send bpsk signal from tx through rx with nco phase in both tx and rx at zero offset and see (after final RRC) that you get constellations by plotting: plot(I_signal,'.'); you can do that in your model or sim by deactivationg the loop i.e. setting eror to zero at addition to nco word. (I don't use close/open as they can be confusing). you should see +/- constellations on I axis. if it fails don't leave it to carrier tracking. - Altera_Forum
Honored Contributor
when doing above test in modelsim make sure the phase of tx nco is same as that of rx nco. If not adjust rx nco to match when they get together. Both sine and cosine waves mustmatch in phase at rx mixer(sine will be inverted for negative frequency)
Regarding rrc/cic I don't know about your chain but normally RRC is first in tx, last in Rx. - Altera_Forum
Honored Contributor
--- Quote Start --- Regarding rrc/cic I don't know about your chain but normally RRC is first in tx, last in Rx. --- Quote End --- Brilliant! One confusion vanished. I am not sure how to plot constellations in Modelsim but this is the output of I_RRC with no phase offset in both tx and rx, both synchronized and loop is deactivated. http://www.alteraforum.com/forum/attachment.php?attachmentid=10466&stc=1 - Altera_Forum
Honored Contributor
In fact you should get same patterns as your input stream. A high mean +1 and low means -1 (if nco are in phase). So don't worry about constellation diagrams.
In matlab if y is complex then plot(y,'.') will do. for bpsk plot(I,Q*0,'.'); - Altera_Forum
Honored Contributor
--- Quote Start --- In fact you should get same patterns as your input stream. A high mean +1 and low means -1 (if nco are in phase). So don't worry about constellation diagrams. In matlab if y is complex then plot(y,'.') will do. for bpsk plot(I,Q*0,'.'); --- Quote End --- I know how to plot them in matlab... in modelsim, as you mentioned I should see same patterns as in tx... and this is what I sent in tx. What do we conclude now? Problem in loop? - Altera_Forum
Honored Contributor
If tx pattern is same as rx pattern (after slicing) and for every sample then it means the chain is working in principle.
If you plot constellations before slicing it will show how much scatter you have (due to filters) which could degrade the loop. Next activate the loop and do some prayer. Remember this simple principle: nco step at start is correct for frequency as frequency is locked. With phase loop active the nco step must become same as its initial value otherwise you lose frequency lock as well. All the phase lock should do is in effect give it a push (a nodge if my spelling is right) to create offset towards correct phase and revert back to initial increment value. So the error adding to nco word must be really scaled gently. I know some people increment the nco word at slow rate and revert back to initial step after cange of phase accumulator value (offset). - Altera_Forum
Honored Contributor
If you want a tricky solution then avoid loop altogether and do the following:
apply a known tx symbol pattern at start. Try detect it at Rx. Keep moving phase offset until you get it. That is all. In practice this trick wouldn't work or I will have patented it since frequency needs lock as well. - Altera_Forum
Honored Contributor
This is greatly useful to know although it's simple... I believe you've just vanished another confusion I had regarding Costas Loop in general!
I have had the question of why does it change the nco word, based on your note the nco word should change for a little of time and come back... that means it should oscillate because I don't expect it to come back instantly! So my design might be correct! From another point of view... this is different from matlab simulation... because the loop output in matlab keeps steady after lock on a constant and doesn't come back to the initial value. And this is correct I think because in matlab I am controlling PHASE of the cosine function which happens to be separate from frequency in a way or another, and this is not the case in Modelsim and NCO where there is only one thing (NCO word) that determines freq and phase. I don't know if you got my point regarding the comparison between matlab and modelsim... but am I right? - Altera_Forum
Honored Contributor
--- Quote Start --- If you want a tricky solution then avoid loop altogether and do the following: apply a known tx symbol pattern at start. Try detect it at Rx. Keep moving phase offset until you get it. That is all. In practice this trick wouldn't work or I will have patented it since frequency needs lock as well. --- Quote End --- Eventually I am going to attach RF Front-End and receive the signal... plus, this is a graduation project as you know and I can't trick professors :D Although they might not know anything but I really want to do it for the sake of self satisfaction :) - Altera_Forum
Honored Contributor
Data aided lock is common practice and you can add slicer result to the loop to check that +/-1 are at equal distance from zero indicating good phase. I believe you focus on modelsim as it has proper loop and delays. If you want to revert to Matlab you better model nco as per rtl exactly so you have control over phase.
I have posted example nco model on DSPrelated.com long time ago but I now know it got bug in negative frequency when phase accum goes backwards. This cn be repaired or use it for positive freq only and if you need to negate it do that after nco e.g. by inverting sine.