Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- FPGAs and Programmable Solutions
- Nios® II Embedded Design Suite (EDS)
- Costas Loop oscillates in ModelSim while locks in MATLAB!

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-31-2015
09:21 AM

1,367 Views

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?Link Copied

46 Replies

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-31-2015
09:54 AM

155 Views

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 I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-31-2015
10:23 AM

155 Views

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-31-2015
10:39 AM

155 Views

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-31-2015
10:42 AM

155 Views

How to do so?

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-31-2015
10:55 AM

155 Views

Mathworks provide a fixed point tool box as part of simulink.

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-31-2015
06:15 PM

155 Views

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 I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
03:44 PM

155 Views

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
04:11 PM

155 Views

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 I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
06:53 PM

155 Views

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 I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
07:07 PM

155 Views

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?
Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
07:27 PM

155 Views

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
07:32 PM

155 Views

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 I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
07:50 PM

155 Views

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
07:56 PM

155 Views

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 I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
08:11 PM

155 Views

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
08:22 PM

155 Views

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 I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
08:34 PM

155 Views

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 I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
08:46 PM

155 Views

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 I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
08:51 PM

155 Views

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2015
09:13 PM

99 Views

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.- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.