Applying a bandpass filter with firwin

1.1k Views Asked by At

I want to apply a bandpass filter with firwin to a three-tone signal. The three tones are 7, 11, and 30 hz, respectively. Specifically, I need to modify the cutoff so that the first and last tones(7 and 30hz) get filtered out. To my understanding, f1 and f2 should be the edges of the bandpass filter. If I set them to 10 and 20 hz, it gives me an error telling me I can't set the cutoff higher than fs/2. I'm not understanding the error because I previously set fs to 100hz. Is there any way I can set the cutoffs so that only the 11hz gets passed?

f1, f2 = 0.5, 0.8 
# f1, f2 = 10.0, 20.0

bandpass_coeff = signal.firwin(N_taps, [f1, f2], pass_zero=False) 

freqzPlot(bandpass_coeff, 'bandpass filter with firwin ' + str(N_taps) + ' taps')

filterHighest(Fs, Fc, bandpass_coeff)


def generateThreeTones(Fs, interval, freq1 = 7.0, amp1 = 5.0, phase1 = 0.0, freq2 = 11.0, amp2 = 3.0, phase2 = 5.0, freq3 = 30.0, amp3 = 4.0, phase3 = 11.0):

dt = 1.0/Fs                          # sampling period (increment in time)
time = np.arange(0, interval, dt)    # time vector over interval



# generate the sin signal
x = amp1*np.sin(2*math.pi*freq1*time+phase1)+amp2*np.sin(2*math.pi*freq2*time+phase2)+amp3*np.sin(2*math.pi*freq3*time+phase3)
return time, x
1

There are 1 best solutions below

0
On

You should pass Fs to signal.firwin. Something like:

bandpass_coeff = signal.firwin(N_taps, [f1, f2], pass_zero=False,fs=Fs)

Otherwise the default value will be used for fs, which is 2 according to the documentation.