Thread: Processing a sine wave file

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367

    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.
    Be a leader and not a follower.

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    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. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Ok, thank you for your reply. The information you have given me is excellent. Thanks for your time.

    Dene
    Be a leader and not a follower.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  3. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. Help open wave file in Borland C++ plz
    By toa2k in forum C++ Programming
    Replies: 1
    Last Post: 01-22-2004, 07:55 AM