消除这些谐波的最简单方法是简单地使用低通滤波器......它将消除截止频率以上的所有频率内容。这不再是一个陷波滤波器,就像你展示的那样,但它肯定会摆脱那些谐波:
%% lowpass IIR filter example
fs_Hz = 1; %your sample rate appears to be 1 Hz
fund_Hz = 1/40; %this is your fundamental
cutoff_Hz = 1.5*fund_Hz; %choose cutoff
[b,a] = butter(3,fund_Hz/(fs_Hz/2)); %lowpass by default
y = filter(b,a,s13); %apply filter
如果低通滤波器过滤过多,那么听起来您的问题是您不知道如何进行多陷波滤波器。没关系。您可以通过一个接一个地应用一系列陷波滤波器来选择对我们的谐波进行陷波...
%% apply IIR notch filters in series
fs_Hz = 1; %your sample rate
fund_Hz =1/40; %your fundamental frequency
y = x; %initialize your output
for Iharm = 3:2:7 %will do 3rd, 5th, 7th
[b, a] = ellip(6,0.5,20,[(Iharm-0.3) (Iharm+0.3)]*fund_Hz/(fs_hz/2),'stop');
y = filter(b,a,y); %apply the filter onto the previous output
end
最后,如果您想将所有这些作为一个过滤器来完成,您将需要一个更复杂的过滤器。您可以根据极点和零点设计自己的(这可能是预期的,如果这是一个班级项目,听起来就是这样)。或者,您可以使用允许您输入任意响应的过滤器设计命令之一。如果您想使用 IIR 过滤器(与 FIR 过滤器相反),请查找yulewalk
命令。你会像这样使用它(我有一段时间没有使用它了,所以这可能不对......
%% yulewalk example
f_Hz = 1; %your sample rate
f_fund_Hz = 1/40; %your fundamental
%define desired response at different frequencies
w = 0.3; %width of each notch
f_Hz = [3-w 3 3+w 5-w 5 5+w 7-w 7 7+w]*f_fund_Hz; %3rd, 5th, 7th harmonics
resp = [ 1 0 1 1 0 1 1 0 1 ]; %notch each harmonic
f_Hz = [0; f_Hz(:); fs/2]; %must start at 0 Hz and end at Nyquist
resp = [1; resp(:); 1]; %add start and end points
%create and apply the filter
N = 3*3; %filter order...play with this...N=3 per notch?
[b,a]=yulewalk(N,f_Hz/(fs_Hz/2),resp); %create filter
y = filter(b,a,x); %apply filter