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
Is the filter in floating point in matlab? Or fixed point?
The VHDL will be fixed point - are there any rounding errors or parts where the bit width isnt wide enough? - Altera_Forum
Honored Contributor
--- Quote Start --- Is the filter in floating point in matlab? Or fixed point? The VHDL will be fixed point - are there any rounding errors or parts where the bit width isnt wide enough? --- Quote End --- I tried to use multiples of 2 as far as possible in matlab. This is the block diagram of the loop filter where C1 = 4 and C2 = 1/2^8 https://www.alteraforum.com/forum/attachment.php?attachmentid=10459 In VHDL, I tried every thing regarding rounding errors and bit widths... this is the best result I got or the closest result to matlab results. I widened vectors in almost every where in loop filter. - Altera_Forum
Honored Contributor
I highly suggest you convert your matlab model to fixed point, so you can compare the two models directly. Matlab natively uses floating point, so there are bound to be differences.
- Altera_Forum
Honored Contributor
How to do so?
- Altera_Forum
Honored Contributor
Mathworks provide a fixed point tool box as part of simulink.
- Altera_Forum
Honored Contributor
oscillation is good sign as convergence of feedback loops takes time (convergence time) before it settles with some jitter in the steady state. It then may lose lock and re-acquire if upset. All these parameters are well known in control design.
Your matlab model may not be that good I assume. Moreover to match delays and latency and bit precision/truncation is no easy job. I suggest you stick with modelsim for now. - Altera_Forum
Honored Contributor
--- Quote Start --- oscillation is good sign as convergence of feedback loops takes time (convergence time) before it settles with some jitter in the steady state. It then may lose lock and re-acquire if upset. All these parameters are well known in control design. Your matlab model may not be that good I assume. Moreover to match delays and latency and bit precision/truncation is no easy job. I suggest you stick with modelsim for now. --- Quote End --- Please don't bring me back to Matlab LOL! Don't you think that it is taking too much time to settle? or a 300+ microseconds is normal for convergence time? I was thinking of group delays that you once warned me of... is this the time to discuss it? - Altera_Forum
Honored Contributor
Hi Kazem, I had a doubt about the NCO to be the reason.... I changed it into a DDS I wrote. Take a look at the result:
http://www.alteraforum.com/forum/attachment.php?attachmentid=10465&stc=1 It does converge! and phase error is 0! But data is diminished also... Why do think is this? I remember I faced something like that in Matlab but I don't remember how and why. - Altera_Forum
Honored Contributor
what is your input? is it clean tone or bpsk signal.
Where is your model that works in matlab? a single tone should end up as dc i.e. two constants for I and Q if nco frequency is correctly matched to push input signal to zero freq.(baseband). but for bpsk signal I expect to see constellations of +/- on each I and Q or one circle if nco is not locked (still rotating symbols). The main difference between model and sim is that of resolution, truncations and loop delay (in unit samples) between nco updates. Groupdelay of filters doesn't make difference but it affects initial convergence time in both cases and equally. - Altera_Forum
Honored Contributor
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?