Control Phase on NCO
MrPitts
Posts: 2
Hi all!
I'm wanting to find more information on controlling the phase of a sinewave using the Propeller NCO.· I have a need to·generate two sinewaves operating at identical·frequencies but·90 degs out of phase from one another.··Can someone provide me a code·snippet that demonstrates doing·this in SPIN, or a good explanation of using the phsa and frqa functions?
Thanks so much!
Ron
I'm wanting to find more information on controlling the phase of a sinewave using the Propeller NCO.· I have a need to·generate two sinewaves operating at identical·frequencies but·90 degs out of phase from one another.··Can someone provide me a code·snippet that demonstrates doing·this in SPIN, or a good explanation of using the phsa and frqa functions?
Thanks so much!
Ron
Comments
·····························Cos(theta)=sqr(1-sin(theta)²)
Edit: the +90 assumes angles in degrees, of course. [noparse]:)[/noparse]
Both functions are trigonometric cofunctions of each other, in that function of the complementary angle, which is the "cofunction," is equal to the other function:
sin(x) = cos(90°-x) and
cos(x) = sin(90°-x).
www.math2.org/math/algebra/functions/sincos/overview.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Take a peek at my entry for the Parallax SX contest to see how to generate 2 same frequency (or different frequency for that matter) sine waves, separated by a phase angle of your chosing.
As one experiment I summed the two (same freq) waves together to simulate varable amplitude...... the sum of two same freq sinewaves distanced by some phase, is itself a sine wave, the amplitude being a function of the phase difference.
I know you asked about a Propeller, but similar concepts to my SX example can be applied.
Hope it is of some interest.
Cheers,
Peter (pjv)
the sum of two identical sinewaves with a different phase between them is not itself a sine wave, is a complex waveform.
Look the definition of fft.
Steve
Look the definition of fft.
If you plot in a piece of paper each sinewave with proper phase and added them up, you will see the result is not a sinewave.
El Paisa, I think your confusing Harmonics and Phase.
csunix1.lvc.edu/~snyder/1ch5.html
Adding harmonics, different frequencies, distortion all will include new frequencies. Adding 2 sine waves of the same frequency - no new frequencies.
Steve
0º····· 0
90º··· 1
180º· 0
270º· -1
360º· 0
it is easy to see that adding two sine wave of same phase and frequency results in a sine wave of the same frequency with double the amplitude (1+1=2, -1+-1=-2). Likewize adding two sine waves of phase difference 180º results in a sine wave of 0 amplitude (1+-1=0). Adding a sine wave of phase difference 90º results in a sine wave of amplitude 1.5 whose peak is at 45º
you can graph it here: http://www.coolmath.com/graphit/index.html
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
...
Post Edited (Paul Baker) : 7/18/2006 4:25:20 PM GMT
I said adding two sinewaves with the same frequency and DIFFERENT phase between them does not produce a sinewave.
It is a distorted sinewave with harmonic content.
>It is a distorted sinewave with harmonic content.
You are wrong.
It is an undistorted sinewave, with no harmonic content.
Please, check your maths, one way or another, before continuing this.
Steve
Here is the graph of 1.5*sin(x + 45º):
Now, compare that with the previous graph, they are identical.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
...
Post Edited (Paul Baker) : 7/18/2006 5:49:41 PM GMT
I proved myself, see data from MCAD.
case closed.
·
This is the MCAD file
Paul, Steve have explaned and proven the issue at hand. I even went as far as to research and derived the same answer as Paul did.
If you have any proof, you should post it here and now, saving any chance of 'grace' within the forums.
................................
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
Err... [noparse]:)[/noparse]
However, even when you do get it to show up, lots of people (including me) can't read MCAD, so you may need to resort to real mathematics, too, or pictures.
Steve
Here's a trig identity that should lay this discussion to rest. It comes from Abramowitz & Stegun's Handbook of Mathematical Functions:
····sin(z1) + sin(z2) = 2 * sin((z1 + z2) / 2) * cos((z1 - z2) / 2)
Substituting x + k for z1 and x for z2, we get:
····sin(x + k) + sin(x) = 2 * sin((2x + k) / 2) * cos(k / 2)
Now, substituting
····a = 2 * cos(k / 2) (a constant), and
····n = k / 2 (another constant),
we get
····sin(x + k) + sin(x) = a * sin(x + n)
which is just another sine function of the same frequency, but with different phase and amplitude from the two original sine functions.
Q.E.D.
-Phil
The sine function is the height of a point on a rotating wheel.
A phase offset is just another point on that same wheel.
The sum of the two (they are vectors from the origin, or center of
the wheel) is yet another point on that same wheel, rotating at the
same speed.
Thus, guaranteed to be a sine wave, no harmonics, no distortion.
(It's ridiculously hot in here in Cambridge, and I've cooled down with beer - wading through propeller documentation isn't really an option...)
Steve
acceptable sine waves from these. (And we won't even mention that the square waves are not nice pretty square
waves with each phase always having the same length.)
That said, you can write to the phase registers; shouldn't this be all that is needed? Just write 0x00000000 to one
phase register, and 0x40000000 to the other, and you should get square waves 90 degrees out of sync.
Steve
I hadn't meant to cause such a furore with my suggestion......, and yes El Paisa, I did build this so I DO know that it generates sine waves.
Two R/C DACs plus a few lines of code is all that is required to generate the two sine waves.
The SX example in the contest shows the code, hence the concept, and that can be readily transported to the propeller. It would be a lot nicer than filtering the signal, especially if frequency variations are required.
Dead simple, really.
Cheers,
Peter (pjv)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
You are write, the waveform is sinewave with no distortion but a different frequency.
The new frequency is function of the phase angle.
Apparently the attachment manager does not like *.bmp files.
This is a screen captured (*.jpg format) of the mcad file.
I meant to say the sinewave sum amplitude (not frequency) changes as function of the phase between the two sinewaves.
As long as BOTH sinewaves have the same frequency, then the product is also going to be the same frequency.
If you have QuickBasic4.5 or QBASIC then you can run the program below to illustrate this. ...Or you can play the
attached WMV file. The "GREEN" wave is fixed Zero phase, while the "RED" wave changes phase from 0 to 360. The
"YELLOW" wave is the sum of both waves.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.