DSPRelated.com
Forums

harmonics when generating sine and cos signal

Started by dtsao April 1, 2007
Hi,

I'm building a recursive quadrature oscillator to generate sin and cos
using in verilog. The sin and cos are 5 Mhz, using a clock of 108 Mhz.
Without going into too much detail of the implementation, the FFT is
showing a very sharp tone at the w = 5 Mhz (offset +/- 3khz is around
-90dB). However I am seeing harmonics 85 khz away which reach around -50
dB.
The system functions are:

H1 = (1 - cos(wT)z^(-1))/(1 - 2cos(wT)z^(-1) + z^(-2))
H2 = sin(wT)z^(-1)/(1 - 2cos(wT)z^(-1) + z^(-2))

Does anyone have suggestion on how I can search for where these harmonics
are coming from? 

      

_____________________________________
Do you know a company who employs DSP engineers?  
Is it already listed at http://dsprelated.com/employers.php ?
dtsao wrote:
> Hi, > > I'm building a recursive quadrature oscillator to generate sin and cos > using in verilog. The sin and cos are 5 Mhz, using a clock of 108 Mhz. > Without going into too much detail of the implementation, the FFT is > showing a very sharp tone at the w = 5 Mhz (offset +/- 3khz is around > -90dB). However I am seeing harmonics 85 khz away which reach around -50 > dB. > The system functions are: > > H1 = (1 - cos(wT)z^(-1))/(1 - 2cos(wT)z^(-1) + z^(-2)) > H2 = sin(wT)z^(-1)/(1 - 2cos(wT)z^(-1) + z^(-2)) > > Does anyone have suggestion on how I can search for where these harmonics > are coming from? >
Harmonics of 5MHz that are 85kHz away? Nope. A harmonic of 5MHz would happen at 10MHz, 15MHz, etc -- not less than 5MHz away. You're seeing something, but it's not a harmonic. Where are you taking your data for the FFT? Are you converting to analog, filtering, then converting back to digital and FFT-ing, or are you taking the digital data out of the oscillator and FFT-ing? If you're not analyzing the purely digital data I would suggest that you do, to see if the tone is created before or after your conversion. How are you controlling the amplitude of your oscillator, and what is your word depth? Have you analyzed it for the effect of quantization noise? If your oscillator is what I think it is it will have a slight bit of damping, either negative or positive. The combination of quantization and (possibly) saturation could make the amplitude of the NCO oscillate, which would cause tones in an FFT. Finally, have you checked to make sure that your FFT is accurate down that far? It may be a good idea to feed it a known pure tone and see if it comes up with the same results. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html

dtsao wrote:

> Hi, > > I'm building a recursive quadrature oscillator to generate sin and cos > using in verilog. The sin and cos are 5 Mhz, using a clock of 108 Mhz. > Without going into too much detail of the implementation, the FFT is > showing a very sharp tone at the w = 5 Mhz (offset +/- 3khz is around > -90dB). However I am seeing harmonics 85 khz away which reach around -50 > dB.
That could be either the artifact of FFT or the artifact of your oscillator. Are you doing the FFT numerically or you are processing the actual output of the DAC? Make sure the tone is exactly on the corresponding FFT bin. 108MHz/85kHz = 127*10, which makes me think that something has to do with the quantization and the accumulation of some error over 128 samples. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Tim Wescott wrote:
> dtsao wrote: > > I'm building a recursive quadrature oscillator to generate sin and > > cos using in verilog. The sin and cos are 5 Mhz, using a clock of > > 108 Mhz. Without going into too much detail of the implementation, > > the FFT is showing a very sharp tone at the w = 5 Mhz (offset +/-3khz > > is around -90dB). However I am seeing harmonics 85 khz away which > > reach around -50 dB. > > How are you controlling the amplitude of your oscillator, and what is > your word depth?
This is key. If you are relying on peak limiting to control the oscillator amplitude, the 5 MHz signal will "beat" with the nearest sub-multiple of the sampling rate, which in this case is 108 MHz/22 = 4.909091 Mhz. This is a difference frequency of 90.91 kHz. The problem with peak limiting is that the arithmetic errors accumulate between moments when the signal peaks line up with the sample points. I once did an audio quadrature oscillator on a 16-bit DSP. It took me a while to understand this and implement good sample-by-sample amplitude control in order to get the total distortion down to -76 dB or so (measured by Audio Precision at an analog output), which was sufficient for my needs. Looking at the distortion residual on the scope gave me a big clue about what was going on. -- Dave Tweed
David Tweed wrote:
> Tim Wescott wrote: >> dtsao wrote: >>> I'm building a recursive quadrature oscillator to generate sin and >>> cos using in verilog. The sin and cos are 5 Mhz, using a clock of >>> 108 Mhz. Without going into too much detail of the implementation, >>> the FFT is showing a very sharp tone at the w = 5 Mhz (offset +/-3khz >>> is around -90dB). However I am seeing harmonics 85 khz away which >>> reach around -50 dB. >> How are you controlling the amplitude of your oscillator, and what is >> your word depth? > > This is key. If you are relying on peak limiting to control the > oscillator amplitude, the 5 MHz signal will "beat" with the nearest > sub-multiple of the sampling rate, which in this case is 108 MHz/22 > = 4.909091 Mhz. This is a difference frequency of 90.91 kHz. > > The problem with peak limiting is that the arithmetic errors > accumulate between moments when the signal peaks line up with > the sample points. > > I once did an audio quadrature oscillator on a 16-bit DSP. It took > me a while to understand this and implement good sample-by-sample > amplitude control in order to get the total distortion down to -76 dB > or so (measured by Audio Precision at an analog output), which was > sufficient for my needs. > > Looking at the distortion residual on the scope gave me a big clue > about what was going on.
Normalize the amplitude to make sqrt(sin^2 + cos^2) = 1 for every iteration. It can be cone with about three instructions. Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
David Tweed <dtweed@acm.org> writes:

> I once did an audio quadrature oscillator on a 16-bit DSP. It took > me a while to understand this and implement good sample-by-sample > amplitude control in order to get the total distortion down to -76 dB > or so (measured by Audio Precision at an analog output), which was > sufficient for my needs.
David, How did you implement your sample-by-sample amplitude control? I recently considered a recursive quadrature oscillator in fixed-point and also had problems with the amplitude control. Since my goal was to implement a combination quadrature downconverter / decimator, I ended implementing instead what I term "quadrature bandpass decimation" and therefore avoided the entire problem, and simultaneously improved my numerical accuracy and signal integrity. I'm curious if others utilize this approach as well. -- % Randy Yates % "And all that I can do %% Fuquay-Varina, NC % is say I'm sorry, %%% 919-577-9882 % that's the way it goes..." %%%% <yates@ieee.org> % Getting To The Point', *Balance of Power*, ELO http://home.earthlink.net/~yatescr
Jerry Avins <jya@ieee.org> writes:

> David Tweed wrote: >> Tim Wescott wrote: >>> dtsao wrote: >>>> I'm building a recursive quadrature oscillator to generate sin and >>>> cos using in verilog. The sin and cos are 5 Mhz, using a clock of >>>> 108 Mhz. Without going into too much detail of the implementation, >>>> the FFT is showing a very sharp tone at the w = 5 Mhz (offset +/-3khz >>>> is around -90dB). However I am seeing harmonics 85 khz away which >>>> reach around -50 dB. >>> How are you controlling the amplitude of your oscillator, and what is >>> your word depth? >> This is key. If you are relying on peak limiting to control the >> oscillator amplitude, the 5 MHz signal will "beat" with the nearest >> sub-multiple of the sampling rate, which in this case is 108 MHz/22 >> = 4.909091 Mhz. This is a difference frequency of 90.91 kHz. >> The problem with peak limiting is that the arithmetic errors >> accumulate between moments when the signal peaks line up with >> the sample points. >> I once did an audio quadrature oscillator on a 16-bit DSP. It took >> me a while to understand this and implement good sample-by-sample >> amplitude control in order to get the total distortion down to -76 dB >> or so (measured by Audio Precision at an analog output), which was >> sufficient for my needs. >> Looking at the distortion residual on the scope gave me a big clue >> about what was going on. > > Normalize the amplitude to make sqrt(sin^2 + cos^2) = 1 for every > iteration. It can be cone with about three instructions.
How? Just computing x^2 + y^2 is three instructions already. -- % Randy Yates % "Bird, on the wing, %% Fuquay-Varina, NC % goes floating by %%% 919-577-9882 % but there's a teardrop in his eye..." %%%% <yates@ieee.org> % 'One Summer Dream', *Face The Music*, ELO http://home.earthlink.net/~yatescr
Randy Yates wrote:
> Jerry Avins <jya@ieee.org> writes:
...
>> Normalize the amplitude to make sqrt(sin^2 + cos^2) = 1 for every >> iteration. It can be cone with about three instructions. > > How? Just computing x^2 + y^2 is three instructions already.
The recursion formula for 1/sqrt(x^2 + y^2) when x^2 + y^2 is very nearly 1 is 2 - x^2 - y^2 if I remember correctly and if I remember incorrectly, something very similar to that. If x^2 + y^2 is accurate to n bits, after one iteration it will be accurate to 2n +/- 1 bits. Multiplying x and y by 2 - x^2 - y^2 makes them as accurate as the bit width allows. So sue me about the instruction count! :-) Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
Jerry Avins wrote:
> David Tweed wrote: >> Tim Wescott wrote: >>> dtsao wrote: >>>> I'm building a recursive quadrature oscillator to generate sin and >>>> cos using in verilog. The sin and cos are 5 Mhz, using a clock of >>>> 108 Mhz. Without going into too much detail of the implementation, >>>> the FFT is showing a very sharp tone at the w = 5 Mhz (offset +/-3khz >>>> is around -90dB). However I am seeing harmonics 85 khz away which >>>> reach around -50 dB. >>> How are you controlling the amplitude of your oscillator, and what is >>> your word depth? >> >> This is key. If you are relying on peak limiting to control the >> oscillator amplitude, the 5 MHz signal will "beat" with the nearest >> sub-multiple of the sampling rate, which in this case is 108 MHz/22 >> = 4.909091 Mhz. This is a difference frequency of 90.91 kHz. >> >> The problem with peak limiting is that the arithmetic errors >> accumulate between moments when the signal peaks line up with >> the sample points. >> >> I once did an audio quadrature oscillator on a 16-bit DSP. It took >> me a while to understand this and implement good sample-by-sample >> amplitude control in order to get the total distortion down to -76 dB >> or so (measured by Audio Precision at an analog output), which was >> sufficient for my needs. >> >> Looking at the distortion residual on the scope gave me a big clue >> about what was going on. > > Normalize the amplitude to make sqrt(sin^2 + cos^2) = 1 for every > iteration. It can be cone with about three instructions. > > Jerry
Or make sin^2 + cos^2 = 1 for every iteration -- it'll be linear enough, and you don't have to take sqrt, or even a pretend sqrt. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
>Tim Wescott wrote: >> dtsao wrote: >> > I'm building a recursive quadrature oscillator to generate sin and >> > cos using in verilog. The sin and cos are 5 Mhz, using a clock of >> > 108 Mhz. Without going into too much detail of the implementation, >> > the FFT is showing a very sharp tone at the w = 5 Mhz (offset
+/-3khz
>> > is around -90dB). However I am seeing harmonics 85 khz away which >> > reach around -50 dB. >> >> How are you controlling the amplitude of your oscillator, and what is >> your word depth? > >This is key. If you are relying on peak limiting to control the >oscillator amplitude, the 5 MHz signal will "beat" with the nearest >sub-multiple of the sampling rate, which in this case is 108 MHz/22 >= 4.909091 Mhz. This is a difference frequency of 90.91 kHz. > >The problem with peak limiting is that the arithmetic errors >accumulate between moments when the signal peaks line up with >the sample points. > >I once did an audio quadrature oscillator on a 16-bit DSP. It took >me a while to understand this and implement good sample-by-sample >amplitude control in order to get the total distortion down to -76 dB >or so (measured by Audio Precision at an analog output), which was >sufficient for my needs. > >Looking at the distortion residual on the scope gave me a big clue >about what was going on. > >-- Dave Tweed >
I am using the digital data out of the oscillator to calculate the FFT. Also, since the amplitude will increase, I gave me head room for bits, alowing it to increase slightly over time, then reset to initial conditions after a while. I'm not sure how quantization will have anything to do with creating an extra tone at every 127 samples. Can someone explain or give an example how this works? Also, what is "peak limiting control" mean exactly? As I said, I made the bus a bit larger so the sine wave could have room to increase slightly, then just reset it before it overflows to whatever I set. I am resetting at the 216000 cycle: my reasoning for this is 5/108 = 21.6, so after 10000 periods, I know the sine will be 0 and the cos will be at my initial "1". My bus width is actually 31 bits. My cos(wT) and sin(wT) are quantized to 18 bits. And I start with an initial "1" being represented by 2^28 (=268435456). When you refer to 90.91 kHz... if this is what is causing the problem, is this avoidable? _____________________________________ Do you know a company who employs DSP engineers? Is it already listed at http://dsprelated.com/employers.php ?