【问题标题】:How to filter out harmonics (DSP) using MATLAB?如何使用 MATLAB 滤除谐波(DSP)?
【发布时间】:2023-03-18 23:42:01
【问题描述】:

我有这段代码,它将 3 次谐波添加到基波信号中,然后使用滤波器取回基波。我必须修改此代码以添加 3 次、5 次和 7 次谐波,然后将它们过滤掉,但我不知道如何使过滤器做到这一点。

t = [0:199];
A1 = 100;
s1 = A1*sin(2*pi*(1/40)*t); % fundamental
A3 = A1/3;
s3 = A3*sin(2*pi*(1/40)*3*t); %3rd harmonic
s13 = s1 + s3; 
% A5 = A1/5;  
% s5 = A5*sin(2*pi*(1/40)*5*t); 5th
% A7 = A1/7;
% s7 = A7*sin(2*pi*(1/40)*7*t); 7th

% filter
[b13, a13] = ellip(6,0.5,20,[5.7/40 6.3/40],'stop') %elliptic filter
h13 = impz(b13,a13,length(s13)); %impulse
y13 = filter(b13,a13,s13); 

【问题讨论】:

    标签: matlab signals processing signal-processing digital


    【解决方案1】:

    消除这些谐波的最简单方法是简单地使用低通滤波器......它将消除截止频率以上的所有频率内容。这不再是一个陷波滤波器,就像你展示的那样,但它肯定会摆脱那些谐波:

    %% 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
    

    【讨论】:

    • 非常感谢您的努力,您以最好的方式解决了我的问题。最好的问候
    猜你喜欢
    • 1970-01-01
    • 2012-11-01
    • 2011-03-04
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多