将滤波器应用于给定信号

时间:2014-02-28 18:20:40

标签: matlab filter filtering signal-processing

假设我们有以下信号

function [ x ] = generate1(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))'; %'
wn = randn(length(t),1); %zero mean variance 1
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*wn;
%[pks,locs] = findpeaks(x);
 %plot(x)
end

代码

y=generate1(3,500,1);

现在假设我想要频率低于150的所有组件,所以我需要低通滤波器,但是在这种情况下如何应用?请告诉我,我是滤波器设计问题的新手,我可以构建滤波器吗? ?提前谢谢

1 个答案:

答案 0 :(得分:1)

这样的事情应该有效:

function [ x ] = generate1(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))'; %'
fs = m/(T*N);
cutoff = 150;


wn = randn(length(t),1); %zero mean variance 1
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*wn;

[b,a] = butter(4, cutoff/(fs/2));

x_filt = filtfilt(b,a,x);
figure; plot(t,x)
hold on
plot(t,x_filt)
%[pks,locs] = findpeaks(x);
%plot(x)
end

对黄油功能的调用构造了一个4阶段的butterworth低通滤波器,其截止频率由上面的截止参数指定(在我们的例子中它是150Hz)。 “a”和“b”值是滤波器系数,它们使用filtfilt()命令应用于x向量。结果“x_filt”是x的滤波版本,其中包含小于150Hz的频率分量。