# Thread: Processing a sine wave file

1. ## Processing a sine wave file

Hi, I am just wondering if anyone could point me in the right direction with this. I have a sound recording off a phone line, which is taken at the very beginning of a call. It is in the windows standard wave format. Now, I need to be able to determine when I have a new cycle, and the duration of this cycle in ss:mm. Additionally, from this data I also need to be able to determine the frequency of the wave file. I think the formula for calculating the frequency is 1/t (the time of the cycle?) This will be a sine wave.

I have never processed a wave file before, and I was going to use memory mapping to do this instead of working on several different buffers. However, I am uncertain as to how to calculate the cycles and the frequency. Could anyone give me any advise on this? Another thing, when you are reading in the data from the data section of the wave file, how does it represent negative voltages, does it use signed ints (so I would need an array of signed ints)?

Thanks, Dene.

2. You can find the wave (.wav) spec at wotsit.org. You'll have to know the bit-resolution and sampling frequency (i.e. 16 bit / 44 khz).

The wave format is just a series of numbers (samples) that represent the instantanious level at a point in time. ...Connect the dots (or steps), and you have an approximation of the sound wave.

If you really have a single-frequency sine wave, you can count the number of samples between zero-crossings (i.e. where it changes from positive to negative), Multiply that times the sample rate, and you'll get the peroid for one half-cycle. Double that and you'll have the period. Then you're right: F = 1/T.

Your question about signed ints is a good one. For 16 bit resolution, signed integers are used (-32768 to 32767). This means that a 0dB signal (which is the maximum) will have a positive peak level of 32767, and a negative peak of -32768). 8-bit uses unsigned numbers (0 to 255)... You'll have to subtract 127 to find the actual zero-crossing.

Now, if you don't have a single frequency things get complicated. You'll have to use a FFT (Fast Fouier Transform) algorithm to find the "component frequencies". If you are trying to simply find the dominate frequency, you might be able to use the time between peaks.

3. Ok, thank you for your reply. The information you have given me is excellent. Thanks for your time.

Dene