DSPRelated.com
Forums

Quadrature Oscillator Question

Started by murthy_nssr August 20, 2007
Hi Friends,

I am working in DSP since last 4 years but new to implementation of
communication related algorithms. Now I am trying to implement QPSK
demodulator on DSP and for that I picked up "Coupled Quadrature
Oscillator" method to generate I/Q references. 

Basic equations of the implementation are,

Yi[n] = Yi[n-1]*cos(x)-Yq[n-1]*sin(x)
Yq[n] = Yi[n-1]*sin(x)+Yq[n-1]*cos(x)

where x = 2*pi*ft/fs, ft being oscillator tuning frequency and fs is
sampling frequency.

I understand the strategy of this oscillator from the paper by Turner, C.
"Recursive Discrete-Time Sinusoidal Oscillators," IEEE Signal Processing
Magazine, Vol. 20. 

I can see beautiful I/Q outputs from this oscillator up to the Nyquist
rate but I could not figure out "how many points the oscillator takes to
complete one period"?. For example, with fs=8000 and ft=2000, the
oscillator is completing one period for n=226,  This is important for me
for my implementation of circular addressing.

Can any body guide me to figure out how many points i have to calculate to
complete once cycle?


Hello,

>Yi[n] = Yi[n-1]*cos(x)-Yq[n-1]*sin(x) >Yq[n] = Yi[n-1]*sin(x)+Yq[n-1]*cos(x)
> x = 2*pi*ft/fs, fs=8000 and ft=2000 >oscillator is completing one period for n=226
Isn't that a simple rotating phasor? With the given numbers, x = 2*pi*2000/8000=pi/2 Therefore I would expect a full cycle every four samples. If so, the cycle length is simply fs/ft. If ft is an irrational number, it will "never" complete a whole cycle. I haven't simulated or read the reference. But I've got a feeling that machine precision could have an impact, since sin/cos(x) appear to the nth power after n samples. Cheers Markus
mnentwig wrote:
> Hello, > >> Yi[n] = Yi[n-1]*cos(x)-Yq[n-1]*sin(x) >> Yq[n] = Yi[n-1]*sin(x)+Yq[n-1]*cos(x) > >> x = 2*pi*ft/fs, fs=8000 and ft=2000 >> oscillator is completing one period for n=226 > > Isn't that a simple rotating phasor? With the given numbers, > x = 2*pi*2000/8000=pi/2 > > Therefore I would expect a full cycle every four samples.
I would too -- and this may not be the best way to implement a quadrature oscillator if _all_ you want is output at fs/2.
> > If so, the cycle length is simply fs/ft. If ft is an irrational number, it > will "never" complete a whole cycle. > > I haven't simulated or read the reference. But I've got a feeling that > machine precision could have an impact, since sin/cos(x) appear to the nth > power after n samples. >
Where machine precision comes in is that if the _effective_ fs/ft isn't a rational number _after_ you've taken rounding into account, then your oscillator won't repeat on exact cycle boundaries. Worse, depending on your rounding the oscillations could either build, remain steady, or die off -- you really want them to remain steady, or you want them to have a slight tendency to build that you counteract with a nonlinearity to keep the amplitude constant without much harmonic generation. There must be literature on how to make this happen; I just know that you need to watch out for it. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com 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
>Hello, > >>Yi[n] = Yi[n-1]*cos(x)-Yq[n-1]*sin(x) >>Yq[n] = Yi[n-1]*sin(x)+Yq[n-1]*cos(x) > >> x = 2*pi*ft/fs, fs=8000 and ft=2000 >>oscillator is completing one period for n=226 > >Isn't that a simple rotating phasor? With the given numbers, >x = 2*pi*2000/8000=pi/2 > >Therefore I would expect a full cycle every four samples. > >If so, the cycle length is simply fs/ft. If ft is an irrational number,
it
>will "never" complete a whole cycle. > >I haven't simulated or read the reference. But I've got a feeling that >machine precision could have an impact, since sin/cos(x) appear to the
nth
>power after n samples. > >Cheers > >Markus > >Yes Markus,
It is a rotating phasor. With the given numbers x = 1.57080, where pi=3.1415926, Hence sin(x)=0.0274121 cos(x)=0.999624 But I don't think this pi/2 is not only the factor which is governing the period of this oscillator. sin(x) and cos(x) when multiplied with previous Y values are incrementing the phase by much smaller factions than pi/2. So, the oscillator should take more points to complete one cycle. My implementation platform is 32-bit floating point DSP. What you said about completing a cycle is perfectly true in case of fixed point implementations, where it is really hard to make this oscillator stable. By setting Yi[n-1]=1 and Yq[n-1]=0, and writing a loop for the given equations like, for(i=0;i<256;i++) { yI[n]=yI[n_1]*cosQ-yQ[n_1]*sinQ; yQ[n]=yI[n_1]*sinQ+yQ[n_1]*cosQ; yI[n_1]=yI[n];iOut[i]=yI[n]; yQ[n_1]=yQ[n];qOut[i]=yQ[n]; } and plotting the outputs tapped, i could see that the oscillator is finishing the it's first cycle when i=226. So, is it still not possible to figure out a formula to find oscillator period in terms of "i"?
> > >
On Aug 21, 3:23 am, "murthy_nssr" <murthyn...@gmail.com> wrote:
> > It is a rotating phasor. With the given numbers > > x = 1.57080, where pi=3.1415926, > Hence sin(x)=0.0274121 > cos(x)=0.999624 > >
I would check your calculations. sin(pi/2) should be 1 (or very close to it, depending upon your precision), and cos(pi/2) should be very close to zero. An oscillator with frequency pi/2 is a special case that can be handled easily anyway; assuming an initial phase of zero, the in-phase channel is just [1 0 -1 0 1 0 -1 0 1 0 -1 0 ...], and the quadrature channel is offset by one sample (pi/2). Jason
> > Where machine precision comes in is that if the _effective_ fs/ft isn't > a rational number _after_ you've taken rounding into account, then your > oscillator won't repeat on exact cycle boundaries. Worse, depending on > your rounding the oscillations could either build, remain steady, or die > off -- you really want them to remain steady, or you want them to have a > slight tendency to build that you counteract with a nonlinearity to keep > the amplitude constant without much harmonic generation. > > There must be literature on how to make this happen; I just know that > you need to watch out for it. >
Hello Tim, My paper actually presents a scheme for controlling the amplitude. It is effectively a type of AGC. The following is a link to my paper: http://www.claysturner.com/dsp/2nd_OSC_paper.pdf
On Aug 21, 3:23 am, "murthy_nssr" <murthyn...@gmail.com> wrote:
> >Hello, > > >>Yi[n] = Yi[n-1]*cos(x)-Yq[n-1]*sin(x) > >>Yq[n] = Yi[n-1]*sin(x)+Yq[n-1]*cos(x) > > >> x = 2*pi*ft/fs, fs=8000 and ft=2000 > >>oscillator is completing one period for n=226 > > >Isn't that a simple rotating phasor? With the given numbers, > >x = 2*pi*2000/8000=pi/2 > > >Therefore I would expect a full cycle every four samples. > > >If so, the cycle length is simply fs/ft. If ft is an irrational number, > it > >will "never" complete a whole cycle. > > >I haven't simulated or read the reference. But I've got a feeling that > >machine precision could have an impact, since sin/cos(x) appear to the > nth > >power after n samples. > > >Cheers > > >Markus > > >Yes Markus, > > It is a rotating phasor. With the given numbers > > x = 1.57080, where pi=3.1415926, > Hence sin(x)=0.0274121 > cos(x)=0.999624 > > But I don't think this pi/2 is not only the factor which is governing the > period of this oscillator. sin(x) and cos(x) when multiplied with previous > Y values are incrementing the phase by much smaller factions than pi/2. So, > the oscillator should take more points to complete one cycle. > > My implementation platform is 32-bit floating point DSP. What you said > about completing a cycle is perfectly true in case of fixed point > implementations, where it is really hard to make this oscillator stable. > > By setting Yi[n-1]=1 and Yq[n-1]=0, and writing a loop for the given > equations like, > > for(i=0;i<256;i++) > { > yI[n]=yI[n_1]*cosQ-yQ[n_1]*sinQ; > yQ[n]=yI[n_1]*sinQ+yQ[n_1]*cosQ; > yI[n_1]=yI[n];iOut[i]=yI[n]; > yQ[n_1]=yQ[n];qOut[i]=yQ[n]; > } > and plotting the outputs tapped, i could see that the oscillator is > finishing the it's first cycle when i=226. > > So, is it still not possible to figure out a formula to find oscillator > period in terms of "i"? >
Hello Murthy, I'm not sure I understand your question. I have formulas in the paper that allow you to find exactly the period. Clay Turner
On Tue, 21 Aug 2007 02:23:06 -0500, murthy_nssr wrote:

>>Hello, >> >>>Yi[n] = Yi[n-1]*cos(x)-Yq[n-1]*sin(x) >>>Yq[n] = Yi[n-1]*sin(x)+Yq[n-1]*cos(x) >> >>> x = 2*pi*ft/fs, fs=8000 and ft=2000 >>>oscillator is completing one period for n=226 >> >>Isn't that a simple rotating phasor? With the given numbers, >>x = 2*pi*2000/8000=pi/2 >> >>Therefore I would expect a full cycle every four samples. >> >>If so, the cycle length is simply fs/ft. If ft is an irrational number, > > it >>will "never" complete a whole cycle. >> >>I haven't simulated or read the reference. But I've got a feeling that >>machine precision could have an impact, since sin/cos(x) appear to the > > nth >>power after n samples. >> >>Cheers >> >>Markus >> >>Yes Markus, > > It is a rotating phasor. With the given numbers > > x = 1.57080, where pi=3.1415926, > Hence sin(x)=0.0274121 > cos(x)=0.999624 > > But I don't think this pi/2 is not only the factor which is governing the > > period of this oscillator. sin(x) and cos(x) when multiplied with previous > > Y values are incrementing the phase by much smaller factions than pi/2. So, > > the oscillator should take more points to complete one cycle.
You are miscalculating your values of sine and cosine. In the context of DSP math the arguments to sine and cosine are universally in radians, not degrees. sin(pi/2) = 1, and cos(pi/2) = 0. So your matrix is [ 0 -1 ] A = [ ] [ 1 0 ] this has eigenvalues of 1, -1, so the amplitude will never grow or shrink. It also rotates the vector through 90 degrees, so it does what you want.
> > My implementation platform is 32-bit floating point DSP. What you said > > about completing a cycle is perfectly true in case of fixed point > > implementations, where it is really hard to make this oscillator stable. > > By setting Yi[n-1]=1 and Yq[n-1]=0, and writing a loop for the given > > equations like, > > for(i=0;i<256;i++) > { > yI[n]=yI[n_1]*cosQ-yQ[n_1]*sinQ; > yQ[n]=yI[n_1]*sinQ+yQ[n_1]*cosQ; > yI[n_1]=yI[n];iOut[i]=yI[n]; > yQ[n_1]=yQ[n];qOut[i]=yQ[n]; > } > and plotting the outputs tapped, i could see that the oscillator is > > finishing the it's first cycle when i=226. > > So, is it still not possible to figure out a formula to find oscillator > > period in terms of "i"?
It is possible, if you get your angular scaling right. Floating point still doesn't have infinite precision, so if you want to use just about any frequency other than fs/4 or fs/2 you will find that the values of your coefficients aren't right, by as much as 7.5e-9. This amount is small; it would take over 12 million iterations to change the amplitude of your oscillator by 10%. However, if you are going to run the thing indefinitely it will eventually suffer from the effect -- if you were sampling at 44kHz it could take less than five minutes for this to happen. Were I doing this task, I'd control the amplitude of my oscillator output. I'd probably read Clay's paper, then either shamelessly copy what he's done, or use his thoughts as a springboard for my own implementation -- but I'd do it. -- Tim Wescott Control systems and communications consulting http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
Tim Wescott wrote:
...
> So your matrix is > > [ 0 -1 ] > A = [ ] > [ 1 0 ] > > this has eigenvalues of 1, -1, ...
Almost. Rotating those values by pi/2 gives the true eigenvalues :-). Regards, Andor
>mnentwig wrote: >> Hello, >> >>> Yi[n] = Yi[n-1]*cos(x)-Yq[n-1]*sin(x) >>> Yq[n] = Yi[n-1]*sin(x)+Yq[n-1]*cos(x) >> >>> x = 2*pi*ft/fs, fs=8000 and ft=2000 >>> oscillator is completing one period for n=226 >> >> Isn't that a simple rotating phasor? With the given numbers, >> x = 2*pi*2000/8000=pi/2 >> >> Therefore I would expect a full cycle every four samples. > >I would too -- and this may not be the best way to implement a >quadrature oscillator if _all_ you want is output at fs/2. >> >> If so, the cycle length is simply fs/ft. If ft is an irrational number,
it
>> will "never" complete a whole cycle. >> >> I haven't simulated or read the reference. But I've got a feeling that >> machine precision could have an impact, since sin/cos(x) appear to the
nth
>> power after n samples. >> >Where machine precision comes in is that if the _effective_ fs/ft isn't >a rational number _after_ you've taken rounding into account, then your >oscillator won't repeat on exact cycle boundaries. Worse, depending on >your rounding the oscillations could either build, remain steady, or die
>off -- you really want them to remain steady, or you want them to have a
>slight tendency to build that you counteract with a nonlinearity to keep
>the amplitude constant without much harmonic generation. > >There must be literature on how to make this happen; I just know that >you need to watch out for it. > >-- > >Tim Wescott >Wescott Design Services >http://www.wescottdesign.com > >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
Information is available on the amplitude variations of this oscillator in the same reference I mentioned. I am using the AGC method suggested the paper by Turner. So, isn't there a way i can use this oscillator and capture a cycle of it for my I/Q reference? If this is not a good way to implement a quadrature oscillator till fs/2, can you please suggest something else which stands for my problem. Thanks in advance. Murthy.