# Apply FIR filters to Extract Stego from WAV data

I appreciate anyone that takes a moment to help me with this problem. I've been banging my head against the keyboard for a while, searching forums and DSP tutorials and I can't figure this problem out.

Here's a couple links I found very helpful from this forum on the subject: http://www.dspguide.com/ http://wiki.scipy.org/Cookbook/ApplyFIRFilter

So I have a WAV file with a 28 sec song/sound that I am trying to convert to frequency range, apply an FIR filter to isolate the 14.5 - 16kHz range. The WAV has a sampling rate of 32 kHz and contains an intermittent buzz that becomes clearer when I drop out all other frequencies besides the 14.5 -16kHz bands.

I have written this sample of python code, and believe I am close to isolating the signal. Its hard to tell.

# read data from file name fn, using low/high for bandpass
# low and high frequency cutoffs, and a
def filter_frequencies(fn,low=0,high=0):
data = wave.open(fn,'rb'); rate = data.getframerate()
ntap = (rate / 4) + 1; nyq = rate / 2
low,high = low/nyq,high/nyq
chunks = int(data.getnframes()/(rate*4))
ns = b''
if low and high == 0: # lowpass
bp = low; pz = True
elif high and low == 0: # highpass
bp = high; pz = False
else: # bandpass
bp = [low,high]; pz = False

b = firwin(ntap, bp, pass_zero=pz, window='blackman', nyq=nyq)
y = b''
for num in range(chunks):
# read 4 secs of frames from wav file
# convert frame amplitudes to their frequency values
freq = np.fft.rfft(seg)
# perform lowpass, highpass or bandpass filter
cr = fftconvolve(freq,b,mode='valid')
# converts frequencies to binary string
y += cr.tostring()
data.close()
return y


I am a noob to DSP, so again I would really appreciate your help on if I am doing the FFT to inverse FFT correctly.

Below is the code I am using to transform the output from the above function back into WAV bytes format.

def frequency_to_bytes(freq):
# invert the Fast Fourier Transform
nf = np.fft.irfft(freq)
# convert frequencies back to integer values
bs = np.ravel(nf).astype(np.int8)
return bs.tostring()



P.s. if you have seen this problem before, or know what challenge I am trying to solve, please no spoilers. I have been working on this for a week solid.