Hello folks, Suppose Im sampling at 8khz. To generate a 4khz tone, its easy, just generate alternating 1,-1,1,-1, etc... To generate a 2khz tone, its also easy. How can one generate a rational fraction of the nyquist freq? I want to able to generate 3.333khz while sampling at 8khz. Any ideas? This method needs to be very computationally cheap, or else its useless in this context. Thanks, --Shafik
Arbitrary Digital Tone generation?
Started by ●February 21, 2005
Reply by ●February 21, 20052005-02-21
Does it have to be a sine wave? If so, Clay Turner has a good paper. It used to be here: http://personal.atl.bellsouth.net/p/h/physics/oscpaper.pdf, but it appears to have moved. Clay often posts here, so perhaps he can give us the new link. You can also use a look-up table. The more memory you have, the better the quality (lower distortion for a sinewave). You can improve the quality by using interpolation, but at the cost of extra computations. "Shafik" <shafik@u.arizona.edu> wrote in message news:1109017983.530895.240980@z14g2000cwz.googlegroups.com...> Hello folks, > > Suppose Im sampling at 8khz. To generate a 4khz tone, its easy, just > generate alternating 1,-1,1,-1, etc... To generate a 2khz tone, its > also easy. > > How can one generate a rational fraction of the nyquist freq? I want to > able to generate 3.333khz while sampling at 8khz. > > Any ideas? This method needs to be very computationally cheap, or else > its useless in this context. > > Thanks, > --Shafik
Reply by ●February 21, 20052005-02-21
Shafik wrote:> Hello folks, > > Suppose Im sampling at 8khz. To generate a 4khz tone, its easy, just > generate alternating 1,-1,1,-1, etc... To generate a 2khz tone, its > also easy. > > How can one generate a rational fraction of the nyquist freq? I want to > able to generate 3.333khz while sampling at 8khz. > > Any ideas? This method needs to be very computationally cheap, or else > its useless in this context. > > Thanks, > --ShafikThere are many software sine-wave oscillators. Computational complexity can often be traded for processor speed or memory size. More detail is needed for a good recommendation. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●February 21, 20052005-02-21
"Jerry Avins" <jya@ieee.org> wrote in message news:dZWdncVXj4bAz4ffRVn-jg@rcn.net...> Shafik wrote: >> Hello folks, >> >> Suppose Im sampling at 8khz. To generate a 4khz tone, its easy, just >> generate alternating 1,-1,1,-1, etc... To generate a 2khz tone, its >> also easy. >> >> How can one generate a rational fraction of the nyquist freq? I want to >> able to generate 3.333khz while sampling at 8khz. >> >> Any ideas? This method needs to be very computationally cheap, or else >> its useless in this context. >> >> Thanks, >> --Shafik > > There are many software sine-wave oscillators. Computational complexity > can often be traded for processor speed or memory size. More detail is > needed for a good recommendation. > > Jerry > -- > Engineering is the art of making what you want from things you can get. >Hi Shafik , you can always just put 5 cycles out for eight in if you're not much worried about how clean your tone is - e.g. put out 1 1 -1 1 -1 1 -1 -1 1 -1 1 -1 -1 every 8 cycles of your nyquist freq.(this is really dirty but incredibly cheap). There are a number of much nbetter NCO techniques to just swallow 3 sample intervals on average for every five you put out that will give you better DC level and not give such massive harmonic components so you could select how you want to swallow them based on how bad your 3.333kHz tone can be (looks as though it could be really rotten if you think that +1 -1 repeating is a tone). Best of Luck - Mike
Reply by ●February 21, 20052005-02-21
Hello Jon and Shafik, It has moved slightly: http://personal.atl.bellsouth.net/p/h/physics/2nd_OSC_paper.pdf Thanks for the reference, Jon. Clay "Jon Harris" <goldentully@hotmail.com> wrote in message news:37uvn4F5gpah4U1@individual.net...> Does it have to be a sine wave? If so, Clay Turner has a good paper. It > used > to be here: > http://personal.atl.bellsouth.net/p/h/physics/oscpaper.pdf, but it appears > to > have moved. Clay often posts here, so perhaps he can give us the new > link. > > You can also use a look-up table. The more memory you have, the better > the > quality (lower distortion for a sinewave). You can improve the quality by > using > interpolation, but at the cost of extra computations. > > "Shafik" <shafik@u.arizona.edu> wrote in message > news:1109017983.530895.240980@z14g2000cwz.googlegroups.com... >> Hello folks, >> >> Suppose Im sampling at 8khz. To generate a 4khz tone, its easy, just >> generate alternating 1,-1,1,-1, etc... To generate a 2khz tone, its >> also easy. >> >> How can one generate a rational fraction of the nyquist freq? I want to >> able to generate 3.333khz while sampling at 8khz. >> >> Any ideas? This method needs to be very computationally cheap, or else >> its useless in this context. >> >> Thanks, >> --Shafik > >
Reply by ●February 22, 20052005-02-22
"Shafik" <shafik@u.arizona.edu> wrote in news:1109017983.530895.240980 @z14g2000cwz.googlegroups.com:> Hello folks, > > Suppose Im sampling at 8khz. To generate a 4khz tone, its easy, just > generate alternating 1,-1,1,-1, etc... To generate a 2khz tone, its > also easy. > > How can one generate a rational fraction of the nyquist freq? I want to > able to generate 3.333khz while sampling at 8khz. > > Any ideas? This method needs to be very computationally cheap, or else > its useless in this context. > > Thanks, > --Shafik >Generate a cosine table with 2Pi/12 spacing (every 30 degrees). Step thru the table by 5. This will give you 3333Hz since (8000/12)*5 = 3333.33 I have an article on our web site: http://www.danvillesignal.com/files/article_signal_generation.pdf -- Al Clark Danville Signal Processing, Inc. -------------------------------------------------------------------- Purveyors of Fine DSP Hardware and other Cool Stuff Available at http://www.danvillesignal.com
Reply by ●February 22, 20052005-02-22
Al Clark wrote:> "Shafik" <shafik@u.arizona.edu> wrote in news:1109017983.530895.240980 > @z14g2000cwz.googlegroups.com: > > >>Hello folks, >> >> Suppose Im sampling at 8khz. To generate a 4khz tone, its easy, just >>generate alternating 1,-1,1,-1, etc... To generate a 2khz tone, its >>also easy. >> >>How can one generate a rational fraction of the nyquist freq? I want to >>able to generate 3.333khz while sampling at 8khz. >> >>Any ideas? This method needs to be very computationally cheap, or else >>its useless in this context. >> >>Thanks, >>--Shafik >> > > > Generate a cosine table with 2Pi/12 spacing (every 30 degrees). > Step thru the table by 5. This will give you 3333Hz since (8000/12)*5 = > 3333.33 > > I have an article on our web site: > > http://www.danvillesignal.com/files/article_signal_generation.pdfThe OP hasn't yet given us his time and memory constraints. When he does, I'll try to suggest specific solutions to fit them. When I shoot in the dark, I more often than not miss the target. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●February 22, 20052005-02-22
Sorry for the wait Jerry,
I want to be able to, in real time, generate an arbitrary tone
between 3000Hz and 4000Hz, accurate to within 50 Hz. "Real-time" in
this case is 1/8000th of a second (sampling rate is 8Khz). Im running
this on a 60MIP chip.
The tone itself has to be clean, and that's why running through a table
of cosines won't cut it.
--Shafik
Reply by ●February 22, 20052005-02-22
Hi Shafik, What does "clean" mean? -150dB spurious free? -5dB spurious free? On its own "clean" is meaningless. Direct digital synthesis (DDS) is the usual term for properly implemented cosine table method of generating arbitrary tones. Even a modest sized table will give a pretty low noise floor and close in phase noise. Purity constraints in RF applications are demanding, and they usually use DDS. Generating tones by pure calculation can also work, and doesn't require a lot of computation. However, you have to take great care that your oscillator is unconditionally stable. They have a nasty tendancy to drift in amplitude over time, due to limited precision in the calculations. Adding a little more computation can AGC the level, but careful testing is recommended. It seems like you don't need an arbitrary tone generator. You said 50Hz steps are good enough. That means you only need to generate 21 different tones. Regards, Steve Shafik wrote:>Sorry for the wait Jerry, > > I want to be able to, in real time, generate an arbitrary tone >between 3000Hz and 4000Hz, accurate to within 50 Hz. "Real-time" in >this case is 1/8000th of a second (sampling rate is 8Khz). Im running >this on a 60MIP chip. > >The tone itself has to be clean, and that's why running through a table >of cosines won't cut it. > >
Reply by ●February 22, 20052005-02-22
Shafik wrote:> Sorry for the wait Jerry, > > I want to be able to, in real time, generate an arbitrary tone > between 3000Hz and 4000Hz, accurate to within 50 Hz. "Real-time" in > this case is 1/8000th of a second (sampling rate is 8Khz). Im running > this on a 60MIP chip. > > The tone itself has to be clean, and that's why running through atable> of cosines won't cut it. > > --ShafikA standard way to do it is to maintain a phase accumulator (non saturating counter) that increments by 2^n * Fosc/8000 on every sample, where n is the number of bits in the phase accumulator (16 might be fine for your situation). On each sample period, calculate sin and cos of the phase accumulator using one of a couple of methods: 1. Direct calculation of sin and cos using a power series. Free routines are available from DSP vendors. 2. Table lookup, with table size 2^b. If the table holds a full cycle, the top b bits of the accumulator give the index into the table. Offset by 2^b/2 to for sine, 3*2^b/2 for cos. A 256 word table might suffice. It all depends on how the required SFDR and SNR of the tones. John






