应用低通滤波器 [英] Applying low pass filter

查看:284
本文介绍了应用低通滤波器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MATLAB中使用上采样和低通滤波器来模拟插值器。首先,我通过引入0来提升我的信号。



现在我想应用一个低通滤波器来插入。我设计了以下滤镜:



过滤器正好是标准化频率的1/8,因为之后我需要下采样。 (这是一个具体的excersise上采样插值和下采样在这个特定的顺序。)

然而,当我使用函数过滤器应用此过滤器(myfilter,data)生成以下信号:



我真的不知道我的信号发生了什么,因为理论上我知道应该出现一个内插信号。这是我第一次使用滤波器在MATLAB中工作,因为直到现在我们只有理论,并且必须假设理想的滤波器和分析解决方案。

有人可以指出什么可能是错的吗?我使用下面的代码:

 清除所有;关闭所有; 

%设置参数
fs = 10e6;
N = 10;
c = 3 / fs;
k = 3;
M = 8;

%设置时间和信号
t = 0:fs ^ -1:N * fs ^ -1;
x = exp( - (t。^ 2)./(2. * c。^ 2)); %高斯信号

%上采样
tu = 0:(fs * M)^ - 1:N * fs ^ -1;
xu = zeros(1,size(tu,2));
sample_range = 1:M:size(xu,2);
for i = 1:size(x,2);
xu(sample_range(i))= x(i);
end;

%%直接方法

xf = filter(lpf5mhz,xu);


解决方案



给出一个更平滑的过渡信号,例如高斯脉冲,它已经有足够的时间延迟:

  delay = 10 / fs; 
x = exp( - ((t-delay)。^ 2)./(2. * c。^ 2)); %高斯信号

过滤器可以更好地上升到信号值:



接下来您可能会注意到,过滤的输出有 1 / M 将振幅作为未经滤波的信号。为了得到一个与未滤波信号幅度相似的内插信号,你必须用下面的方法来缩放滤波器的输出:

$ p $ xf = M *过滤器(lpf5mhz,1,XU);



最后,信号被滤波操作延迟。所以为了比较的目的,你可能需要绘制一个时间转换的版本:

$ $ $ $ $ $ $ $ $> filter_delay =(1 /(M * fs))* (长度(lpf5mhz)-1)/ 2;
plot(tu-(1 /(M * fs))*(length(b)-1)/ 2,xf);


I want to simulate an interpolator in MATLAB using upsampling followed by a low pass filter. First I have up-sampled my signal by introducing 0's.

Now I want to apply a low pass filter in order to interpolate. I have designed the following filter:

The filter is exactly 1/8 of the normalized frequency because I need to downsample afterward. (it's a specific excersise to upsample interpolate and downsample in this particular order.)

However when I apply this filter to my data using the function filter(myfilter, data) the following signal is generated:

I really don't know what is happening to my signal because in theory I know an interpolated signal should appear. This is the first time I'm working in MATLAB with filters because till now we only had the theory and had to assume ideal filters and analytical solutions.

Can someone give me an indication what might be wrong? I use the following code:

clear all; close all;

% Settings parameters
fs=10e6; 
N=10;
c=3/fs;
k=3;
M=8;

% Settings time and signal 
t=0:fs^-1:N*fs^-1;
x=exp(-(t.^2)./(2.*c.^2)); % Gaussian signal

% Upsampling
tu=0:(fs*M)^-1:N*fs^-1;
xu=zeros(1,size(tu,2));
sample_range=1:M:size(xu,2);
for i=1:size(x,2);
    xu(sample_range(i))=x(i);
end;

%% Direct Method

xf=filter(lpf5mhz,xu); 

解决方案

As suggested by hotpaw2's answer, the low-pass filter needs some time to ramp up to the input signal values. This is particularly obvious with signal with sharp steps such as yours (the signal implicitly includes a large step at the first sample since past samples are assumed to be zeros by the filter call). Also, with your design parameters the delay of the filter is greater than the maximum time range shown on your output plot (1e-6), and correspondingly the output remains very small for the time range shown.

To illustrate the point, we can take a look at the filtered output with smaller filter lengths (and correspondingly smaller delays), using filters generated with fir1(length,0.125):

Given a signal with a smoother transition such as a Gaussian pulse which has been sufficiently time delayed:

delay = 10/fs;
x=exp(-((t-delay).^2)./(2.*c.^2)); % Gaussian signal

the filter can better ramp up to the signal value:

The next thing you may noticed, is that the filtered output has 1/Mth the amplitude as the unfiltered signal. To get an interpolated signal with similar amplitude as the unfiltered signal you would have to scale the filter output with:

xf=M*filter(lpf5mhz,1,xu);

Finally, the signal is delayed by the filtering operation. So for comparison purposes you may want plot a time shifted version with:

filter_delay = (1/(M*fs))*(length(lpf5mhz)-1)/2;
plot(tu-(1/(M*fs))*(length(b)-1)/2, xf);

这篇关于应用低通滤波器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆