You can not get a frequency value out of one sample !

To get the frequency response of the audio you should do a DFT or FFT.

In this FIR analyzer example i just showed that you can do a band-pass filter for let's say 1000 Hz and 2000 Hz.

It removes the frequency content below 1000 Hz and removes the frequency content above 2000 Hz

Now we have only the frequencies between 1000 Hz and 2000 Hz.

You could save this as a wav-file and the only sound you will hear is the frequency range of 1000 Hz to 2000 Hz, all other frequencies are filtered out.

But as in this example i use the filtered frequencies to show them on screen to see which frequencies are played.

I showed 3 ways to present those filtered frequencies per frequency band.

1) Peak = find the highest sample value.

2) RMS = multiply each sample with it self, add all multiplied samples and then divide by the number of samples, then get the sqrt.

3) Average = add all samples and then divide by the number of samples.

Why use zero padding at the beginning and the end of the audio data ?

If you have 3 FIR coefficients, you need 1 zero before the audio-data and 1 zero after the audio-data.

Because you start filtering with the first audio sample, you need the sample numbers "-1,0,1" to do the filter calculations.

The same fore the last audio sample you need an extra sample, so there has to be an extra zero ad the end of the audio-data.

So if you have 8191 FIR coefficients you need 4095 zeros before and 4095 zeros after the audio-data.

Now the whole sequence:

1) Create a FIR window:

; example 2th order band-pass

invoke CalculateFIRcoefficients,2,44100,1000,2000,FIR_BandPass,addr FIRcoefficients ; get the frequencies between 1000 and 2000 Hz

2) Load your wav-file to memory ( reserve extra memory for the zero padding )

It looks like this:

0,L,R,L,R,L,R,L,R,0 ( add zeros for the FIR window size == number of FIR coeffs )

3) Now convert this to 2 seperate 32 bit floating point audio channels.

It looks like this:

0,L,L,L,L,L,L,L,L,.....,0 ( Left channel )

0,R,R,R,R,R,R,R,R,.....,0 ( Rigth channel )

And reserve also memory for the 2 output channels if you like to save it as a wav-file.

4) Do the FIR calculations for both seperate audio channels:

s = audio samples

f = fir coeffs

example with a 2th order filter (3 FIR coeffs):

ouput(s0) = f0*input(s-1) + f1*input(s0) + f2*input(s1)

ouput(s1) = f0*input(s0) + f1*input(s1) + f2*input(s2)

etc....

Note: a 2th order FIR filter has 3 coeffs, a 4th order FIR filter has 5 coeffs etc....

5) Your output has now the fitered audio data.

To save as Wav-file, convert the two output 32 bit floats audio channels back as interleaved (L,R,L,R,L,R,L,R,...) 16 bit signed ints.

6) Your done.....

There are 4 types of band filtering:

invoke CalculateFIRcoefficients,OrderNumber,Samplerate,1000,NULL,FIR_LowPass,addr FIRcoefficients ; remove the frequencies above 1000 Hz

invoke CalculateFIRcoefficients,OrderNumber,Samplerate,1000,NULL,FIR_HighPass,addr FIRcoefficients ; remove the frequencies below 1000 Hz

invoke CalculateFIRcoefficients,OrderNumber,Samplerate,1000,2000,FIR_BandPass,addr FIRcoefficients ; remove the frequencies below 1000 and above 2000 Hz

invoke CalculateFIRcoefficients,OrderNumber,Samplerate,1000,2000,FIR_BandReject,addr FIRcoefficients ; remove the frequencies between 1000 and 2000 Hz

Marinus