Sign in to follow this  
Prads

Wave frequency question

Recommended Posts

So, 1 Hz Frequency wave looks like this: (The middle line is 0 amplitude)

[img]http://www.mirrorimg.net/im1/04m.jpeg[/img]

But what if wave looks something like this:

[img]http://www.mirrorimg.net/im1/l1b.jpeg[/img]

Is it still 1Hz? Sorry if this is a stupid question.

Share this post


Link to post
Share on other sites
It depends.
1Hz means that each second the wave repeats itself once. If that happens, it's still 1Hz.
If, for example, the wave repeated itself 3 times per second, it would be 3Hz.

Share this post


Link to post
Share on other sites
Thank you both for replying.

Consider the waves above is played only once a second. That means the first wave is 1 Hz, what would be the frequency of second wave? Thanks!

Share this post


Link to post
Share on other sites
It would also repeat once every second, so the fundamental frequency would still be 1 Hz. But it also contains overtones, since it's not pure tone, which are multiples of the fundamental frequency. So you would hear not only 1 Hz, but also 2 Hz, and 3 Hz and so on, but with a much lower amplitude.

Share this post


Link to post
Share on other sites
Oh, Thank You! :)

XAudio2 has SetFrequencyRatio function to change frequency of the sound and to find frequency ratio, I need to detect the frequency at which the sound in a buffer plays at.
Consider the buffer is circular and is 64 bytes long, sample rate is 8 kHz and sample depth is 8 bits, I can find the frequency of the sound in buffer by finding the number of oscillations in the buffer and then multiplying 125 with the number of oscillations. And find frequency ratio by dividing the 'new frequency' by the frequency of the sound in buffer.
So, my question is that to find the frequency of the sound in buffer, do I have to consider the overtones too or just fundamental frequency?

Share this post


Link to post
Share on other sites
Either I don't understand what it is you're trying to do, or you're not understanding what the different meaning of frequency in these contexts are, because your question doesn't make much sense to me. You seem to mix the notation of frequency of the tone and the sampling frequency as if they are the same thing, or at least related to each other. I'm afraid you're going to have to make your question much clearer.

Share this post


Link to post
Share on other sites
Sorry, sometimes I can't express myself clearly in English since it's my second language.

As far as I understand, sampling frequency is the number of sample played per second. So, if the sample rate is 8kHz, it means 8000 samples are played per second.
And frequency of sound is number of oscillation of sound waves per second.
So they are not the same thing.

What I am trying to do is this, I have 64 bytes long buffer and the contains of it is played again and again, infinite loop. Now I have to find the frequency at which the sound in that buffer is playing at. Since I know the sample rate is 8 kHz, I can analyze the value in the buffer and find out the number of oscillation in the buffer. And lastly to find out the frequency I can simply do this:

Frequency = (Sample Rate / Size of Buffer) * number of oscillation in buffer
or, Frequency = (8000 / 64) * number of oscillation in buffer
or, Frequency = 125 * number of oscillation in buffer

After I find the frequency of the sound that is being played, I can use that to find the frequency ratio needed for the XAudio2 SetFrequencyRatio function.

Thanks!

Share this post


Link to post
Share on other sites
What is it that you want to do with the sampling frequency adjustment? I really see no connection between what you describe about the number of cycles in the sample buffer, and how you want to adjust the playback sample rate.

But let's just ask a question with specific numbers. Everything else being what you describe in your post; 8 kHz sample rate and 64 samples per buffer, what do you want to do if you know that the buffer contains three osscilations? That is, if the frequency of the tone is 375 Hz.

Share this post


Link to post
Share on other sites
I have a 13 bit frequency in which the sound in the buffer should be played at. To change sound frequency, I need to calculate the frequency ratio (so that I can use it in XAudio2::SetFrequencyRatio function) which is equal to '13 bit frequency / frequency of the tone' ('13 bit frequency / 375' in your above example).

Share this post


Link to post
Share on other sites
So now that I think I understand what you want, I guess we can go back to the original question: determining the frequency of a signal.

In all but the very trivial cases where the signal is basically only a tone, either pure or with little overtones, this problem is not well defined unless you have specific requirements of what [i]the[/i] frequency of a signal really is. A pure tone contains a single frequency, but anything else will contain multiple frequencies, so there is no [i]the[/i] frequency.

Two examples could be the dominant frequency, or the pitch of the signal. The dominant frequency can be determined by the frequency bin from a DFT with the largest magnitude. In this case, you can look for a DFT library, such as [url="http://www.fftw.org"]fftw[/url]. You can also approximate it by the number of zero-crossings (for example, your signals in the pictures, has one zero-crossing; two periods would have three zero-crossings, but you have to be careful with the corner cases at the borders of the buffer). The pitch is the [i]perceived[/i] frequency of a signal. Without going into details, it is extremely simplified as the average of all frequencies weighted by their corresponding magnitude. Again, you would need a DFT library to determine the frequencies and magnitudes.

As I said, the problem is not well defined for arbitrary signals, only for very trivial signals that are mostly tonal.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this