我想在MATLAB中使用上采样然后是低通滤波器来模拟插值器。首先,我通过引入0对信号进行了上采样。
现在,我想应用低通滤波器以进行插值。我设计了以下过滤器:
滤波器恰好是归一化频率的1/8,因为我需要在之后进行下采样。(按此特定顺序对插值和采样进行上采样是一种特殊的技巧。)
但是,当我使用函数将此过滤器应用于数据时,filter(myfilter, data)
会生成以下信号:
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
滤波器可以更好地提高到信号值:
你可能注意到了,接下来的事情,就是滤波输出有1/M
个幅度为未经过滤的信号。要获得与未滤波信号幅度相似的内插信号,您必须使用以下方法缩放滤波器输出:
xf=M*filter(lpf5mhz,1,xu);
最终,信号被滤波操作延迟。因此,出于比较目的,您可能希望绘制带有以下内容的时移版本:
filter_delay = (1/(M*fs))*(length(lpf5mhz)-1)/2;
plot(tu-(1/(M*fs))*(length(b)-1)/2, xf);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句