DSPRelated.com
Forums

sine wave generation

Started by decorr April 11, 2006
"john" <johns@xetron.com> wrote in message 
news:1144843640.294320.17020@i39g2000cwa.googlegroups.com...
> > > Yes, I knew about those higher rates. I think a dog would even have a > hard time hearing Fs/4 on some of those.
Hello All, I don't know about dogs, but I recall some research back during the 80s that showed kittens being able to hear 200kHz and even as adults they can hear 60 kHz. Apparently moles and other rodents emit very high frequency sounds and the cats were very quickly able to localize their prey. Clay
i am a newbie when it comes to programming more over i am using TurboC
v3.0 as my compiler on windows platform.i have to create a physical
sine wave and play it in a .wav file.I DON'T have to produce a sound
that sounds like a sine wave.if anybody can please help me out i would
be grateful.
Thanks a kot for your replies :)

Jerry Avins wrote:

>>> for(k = 0;k < N/4;k++) { >>> sound[4*k] = 0x7FFF; >>> sound[4*k+1] = 0; >>> sound[4*k+2] = 0x8000; >>> sound[4*k+3] = 0; >>> } >> >> Dear god, that's going to hurt like hell! ;-) >> > > I wouldn't hear it.
What? The same one that identified the Baldwin piano in that recording that time? (or are you now going to tell me that "emphasis on the *that time*"? :-( )
> How about we drop the frequency and raise the > amplitude a bit? > > for(k = 0;k < N/6;k++) { > sound[4*k] = 0x7FFF; > sound[4*k+1] = 0x7FFF; > sound[4*k+2] = 0; > sound[4*k+3] = -0x7FFF; > sound[4*k+4] = -0x7FFF; > sound[4*k+5] = 0;
Oh, I'm disappointed, Jerry ... What kind of joke are those zeros in the middle of it!! Make it two +7FFF followed by two -7FFF !!! ;-) Carlos --
john wrote:

>>>>>for(k = 0;k < N/4;k++) { >>>>> sound[4*k] = 0x7FFF; >>>>> sound[4*k+1] = 0; >>>>> sound[4*k+2] = 0x8000; >>>>> sound[4*k+3] = 0; >>>>>} >>>> >>>>1. Not a sine. Try 0x8001 instead of 0x8000. ;) >>> >>>I'll bet you would not be able to tell me which is which in a listening >>>test. >> >>Yeah, but what about my dog...
Your dog?? Your dog is far (faaaaaaaar) less capable than you to *distinguish* the two versions. Probably wouldn't even distinguish two things with frequencies 10% apart -- which is a much much much more severe difference than the tiny 1-bit of noise that Randy caught (on the screen -- no way he would have caught it coming from a speaker or headphones! ;-)) Carlos --
Carlos Moreno wrote:
> Jerry Avins wrote: > >>>> for(k = 0;k < N/4;k++) { >>>> sound[4*k] = 0x7FFF; >>>> sound[4*k+1] = 0; >>>> sound[4*k+2] = 0x8000; >>>> sound[4*k+3] = 0; >>>> } >>> >>> >>> Dear god, that's going to hurt like hell! ;-) >>> >> >> I wouldn't hear it. > > > What? The same one that identified the Baldwin piano in > that recording that time? (or are you now going to tell > me that "emphasis on the *that time*"? :-( )
That was in 1952, when my hearing extended at least to 16 KHz. Now I can't hear the highest two notes on a piano, but the next one down is quite audible. No harmonic content, though. :-)
>> How about we drop the frequency and raise the amplitude a bit? >> >> for(k = 0;k < N/6;k++) { >> sound[4*k] = 0x7FFF; >> sound[4*k+1] = 0x7FFF; >> sound[4*k+2] = 0; >> sound[4*k+3] = -0x7FFF; >> sound[4*k+4] = -0x7FFF; >> sound[4*k+5] = 0; > > > Oh, I'm disappointed, Jerry ... What kind of joke are those > zeros in the middle of it!! Make it two +7FFF followed by > two -7FFF !!! ;-)
That would be four samples per cycle. I outlined six. Suppose we write it so: for(k = 0;k < N/6;k++) { sound[4*k] = 0x7FFF; */ 0x7FFF/sin(pi/3)*sin(1*pi/3) /* sound[4*k+1] = 0x7FFF; */ 0x7FFF/sin(pi/3)*sin(2*pi/3) /* sound[4*k+2] = 0; */ 0x7FFF/sin(pi/3)*sin(3*pi/3) /* sound[4*k+3] = -0x7FFF; */ 0x7FFF/sin(pi/3)*sin(4*pi/3) /* sound[4*k+4] = -0x7FFF; */ 0x7FFF/sin(pi/3)*sin(5*pi/3) /* sound[4*k+5] = 0; */ 0x7FFF/sin(pi/3)*sin(6*pi/3) /* } Is that easier to see? The peak amplitude will then be 0x7FFF*2/sqrt(3). In decimal, that's 1.1547 times the DAC's full scale. (The reconstruction filter sees to that.) Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Carlos Moreno <moreno_at_mochima_dot_com@mailinator.com> wrote in news:v4i%
f.94323$g23.964869@wagner.videotron.net:

> john wrote: > >>>>>>for(k = 0;k < N/4;k++) { >>>>>> sound[4*k] = 0x7FFF; >>>>>> sound[4*k+1] = 0; >>>>>> sound[4*k+2] = 0x8000; >>>>>> sound[4*k+3] = 0; >>>>>>} >>>>> >>>>>1. Not a sine. Try 0x8001 instead of 0x8000. ;) >>>> >>>>I'll bet you would not be able to tell me which is which in a listening >>>>test. >>> >>>Yeah, but what about my dog... > > Your dog?? Your dog is far (faaaaaaaar) less capable than you > to *distinguish* the two versions. Probably wouldn't even > distinguish two things with frequencies 10% apart -- which is > a much much much more severe difference than the tiny 1-bit of > noise that Randy caught (on the screen -- no way he would have > caught it coming from a speaker or headphones! ;-)) > > Carlos > -- >
The 0x8000 is going to cause even order harmonic distortion. Its not going to impact the frequency (fs/4). -- Al Clark Danville Signal Processing, Inc. -------------------------------------------------------------------- Purveyors of Fine DSP Hardware and other Cool Stuff Available at http://www.danvillesignal.com
>i am a newbie when it comes to programming more over i am using TurboC >v3.0 as my compiler on windows platform.i have to create a physical >sine wave and play it in a .wav file.I DON'T have to produce a sound >that sounds like a sine wave.if anybody can please help me out i would >be grateful. >Thanks a kot for your replies :) > >
What do you mean by "physical sine wave"? If you mean sine wave approximation - i.e. particles of sine wave in a sequence/array (sorry for this rough interpretation), as I already told please go through "The Art of Computer Programming - Volume 2 - Seminumerical algorithm" by Donald Knuth. A Taylor series based approximation of sine wave is given in this book. It is in pseudocode and you can convert it into C. But I don't know whether you can play it as a .wav file. I don't know the format in which .wav file is stored. - Krishna
Al Clark wrote:

>>>>Yeah, but what about my dog... >> >>Your dog?? Your dog is far (faaaaaaaar) less capable than you >>to *distinguish* the two versions. Probably wouldn't even >>distinguish two things with frequencies 10% apart -- which is >>a much much much more severe difference than the tiny 1-bit of >>noise that Randy caught (on the screen -- no way he would have >>caught it coming from a speaker or headphones! ;-)) > > The 0x8000 is going to cause even order harmonic distortion. Its not going > to impact the frequency (fs/4).
This is exactly what I was saying. My point was precisely, a dog would be utterly incapable of distinguishing both versions -- from what I've read, the dog's ear is actually far less capable than the human in terms of *distinguishing* sounds with slightly different characteristics (even if it was a frequency change that for us, humans, was extremely obvious) Carlos --
Carlos Moreno wrote:
> Al Clark wrote: > >>>>> Yeah, but what about my dog... >>> >>> >>> Your dog?? Your dog is far (faaaaaaaar) less capable than you >>> to *distinguish* the two versions. Probably wouldn't even >>> distinguish two things with frequencies 10% apart -- which is >>> a much much much more severe difference than the tiny 1-bit of >>> noise that Randy caught (on the screen -- no way he would have >>> caught it coming from a speaker or headphones! ;-)) >> >> >> The 0x8000 is going to cause even order harmonic distortion. Its not >> going to impact the frequency (fs/4). > > > This is exactly what I was saying. > > My point was precisely, a dog would be utterly incapable of > distinguishing both versions -- from what I've read, the dog's > ear is actually far less capable than the human in terms of > *distinguishing* sounds with slightly different characteristics > (even if it was a frequency change that for us, humans, was > extremely obvious)
There's no need to get into that. The generated second harmonic will be 96 dB down from the fundamental. Masking will surely make it inaudible even in the absence of a reconstruction filter (which should remove it). Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry Avins <jya@ieee.org> wrote in news:5fGdndU-
GtXu6aPZnZ2dneKdnZydnZ2d@rcn.net:

> Carlos Moreno wrote: >> Al Clark wrote: >> >>>>>> Yeah, but what about my dog... >>>> >>>> >>>> Your dog?? Your dog is far (faaaaaaaar) less capable than you >>>> to *distinguish* the two versions. Probably wouldn't even >>>> distinguish two things with frequencies 10% apart -- which is >>>> a much much much more severe difference than the tiny 1-bit of >>>> noise that Randy caught (on the screen -- no way he would have >>>> caught it coming from a speaker or headphones! ;-)) >>> >>> >>> The 0x8000 is going to cause even order harmonic distortion. Its not >>> going to impact the frequency (fs/4). >> >> >> This is exactly what I was saying. >> >> My point was precisely, a dog would be utterly incapable of >> distinguishing both versions -- from what I've read, the dog's >> ear is actually far less capable than the human in terms of >> *distinguishing* sounds with slightly different characteristics >> (even if it was a frequency change that for us, humans, was >> extremely obvious) > > There's no need to get into that. The generated second harmonic will be > 96 dB down from the fundamental. Masking will surely make it inaudible > even in the absence of a reconstruction filter (which should remove
it).
> > Jerry
Yeh, and it will be at DC and PI (fs/2). -- Al Clark Danville Signal Processing, Inc. -------------------------------------------------------------------- Purveyors of Fine DSP Hardware and other Cool Stuff Available at http://www.danvillesignal.com