简体   繁体   English

使用 firwin 应用带通滤波器

[英]Applying a bandpass filter with firwin

I want to apply a bandpass filter with firwin to a three-tone signal.我想将带有 firwin 的带通滤波器应用于三音信号。 The three tones are 7, 11, and 30 hz, respectively.这三种音调分别为 7、11 和 30 赫兹。 Specifically, I need to modify the cutoff so that the first and last tones(7 and 30hz) get filtered out.具体来说,我需要修改截止频率,以便过滤掉第一个和最后一个音调(7 和 30hz)。 To my understanding, f1 and f2 should be the edges of the bandpass filter.据我了解,f1 和 f2 应该是带通滤波器的边缘。 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.如果我将它们设置为 10 和 20 hz,它会给我一个错误,告诉我我不能将截止值设置为高于 fs/2。 I'm not understanding the error because I previously set fs to 100hz.我不理解这个错误,因为我之前将 fs 设置为 100hz。 Is there any way I can set the cutoffs so that only the 11hz gets passed?有什么办法可以设置截止频率,以便只通过 11hz?

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

You should pass Fs to signal.firwin.您应该将 Fs 传递给 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.否则默认值将用于 fs,根据文档,默认值为 2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM