In this post about The Fast Fourier Transform, I described how simple it was to create a filter to remove unwanted sound from a WAV file. In order to do that, I needed some code to read and write a WAV file. Then I used the FFT to convert to the frequency domain, do a simple convolution (which in this case was trivial: multiply by 1 or 0 if the frequency was outside/inside the desired range), then do an inverse FFT.


The format of a WAV file is fairly simple. There is a header with some waveform information and then the raw data, typically in Pulse Code Modulated form. PCM is just a digitized representation of the waveform, like an amplitude vs time graph. The number of bits per sample indicates the number of discrete levels of amplitude, also known as the dynamic range


I remembered that Sound Recorder allows you to do primitive editing of WAV files, and it also has a feature to mix WAV files together. I used these features to record my voice and mix it with a 2048 hz sine wave to make a “noisy” sample input wave form. The goal was to write code to filter out the “noise”. Creating a sine wave WAV file is easy: just modify the code that writes the WAV file to output a sine wave.


Making your voice sound like the chipmunks is simple: just change the sampling frequency

You can do tricks like

  • remove every other sample and halve the sample frequency to compress the data. Windows Media Player can speed up the video playback without making the audio sound like the chipmunks.
  • Change 16 bit sampling to 8 bit sampling for compression
  • Convolve the data with a filter (such as low pass, high pass, or notch filter).
    • The convolution can be done as a simple multiply: do a Fourier Transform on the data, multiply by a filter, then do an inverse Fourier Transform
    • A low-pass filter allows only frequencies below a particular frequency. Conversely for a high-pass filter. A bandpass filter allows only frequencies within a particular band. A notch filter is the inverse of a bandpass, and is what my sample does to eliminate the sine wave.
    • A digital Treble or Bass control can use exactly the same technique, except that the filter shape might have a gentle attenuation or amplification of higher or lower frequencies.


(I was trying to find the built in microphone on my Toshiba Portege M200, but couldn’t find it in the documentation or the interactive tour. So I started trusty old Windows Sound Recorder (sndrec32.exe) and blew on some of the candidate holes I could find. Sure enough, there are a couple tiny holes at the bottom (when in non-tablet mode) of the screen )


Experiment with changing the filter parameters: frequency (nMid) and range (nRange).


Also, experiment with changing the FFT code itself: change a “+” to a “-“ to hear the result!


Here is a link to the source code


Here is a link to the sample FoxRocks.Wav file (It will open in whatever app is associated with the WAV file extension on your machine: Windows Media Player, for example. Just choose “File->Save As” to save it locally. Or you can right click on the link and choose File->Save Target as)