在MATLAB插值中取消采样后进行过滤

在MATLAB插值中取消采样后进行过滤

带滤波的升频得到的是内插信号。升频过程只是在给定的输入信号上增加零值样本。零值样本对于获得内插信号没有实际意义。事实上,这些零值样本应该根据输入信号中存在的先前和未来的样本转换为其近似值。将零值样本转换为近似大小的样本的工作是通过滤波完成的。

因此,过滤是在升频后获得内插信号的一个重要步骤。

在MATLAB插值中取消采样后进行过滤

示例:

% MATLAB code to perform filtering
% and obtaining Interpolated signal:
% filtfilt command provides zero-phase digital
% filtering by processing input data x
% in both forward and reverse directions
Syntax: y=filtfilt(b,a,x);
 
% b,a specifies the filter order
% x is input data
% taking sampling frequency as input and
% storing in fs variable
fs=input('enter sampling frequency'); 
 
% taking frequency of the signal as
% input and storing in f 
f=input('enter frequency of signal'); 
 
% taking interpolation factor I as input
% and storing it in L
L=input('enter interpolation factor'); 
 
%defining time-axis 
t=0:1/fs:1; 
 
% generating a sinusoidal signal with
% a given frequency and time-axis tf
x=sin(2*pi*f*t); 
 
% storing length of axis x in N
N=length(x); 
 
% taking another axis ranging from 0 to N-1
n=0:N-1; 
 
% taking another axis ranging from 0 to N*L-1
m=0:(N*L)-1; 
 
% creating zeros in axis of length L*N and storing it in x1
x1=zeros(1,L*N); 
 
% taking another axis with a interpolation
% factor L from 0 to increasing with a factor L and upto N*L
j=1:L:N*L; 
 
% taking j values into x1 from x
x1(j)=x; 
 
% creating a window-based finite inpulse response filter design
% Syntax: b = fir1(n,Wn,'ftype')
% n is number of samples ranging from 0 to N-1,
% Wn is normalized frequency ranging from 0 to 1,
% 'ftype' specifies a filter type
f1=fir1(34,0.48,'low'); 
 
% filtfilt command provides zero-phase digital filtering
% by processing input data x in both forward and reverse directions
% Syntax: y=filtfilt(b,a,x);
% b,a specifies the filter order
% x is input data
output=2*filtfilt(f1,1,x1); 
 
% Syntax: y=interp(x,r);
% the above command specifies increasing the sampling
% rate of signal x by a factor of r.
y=interp(x,L); 
 
% subplot command in MATLAB allows you to insert
% multiple plots in a grid where all plots are specified in same grid
subplot(2,1,1); 
 
% stem command is to plot discrete signal
stem(n,x); 
 
% xlabel shows name of x axis in a plot
xlabel('samples'); 
 
% ylabel shows name of y axis in a plot
ylabel('amplitude'); 
 
% title is shown at the top of figure 
% title is usually used to specify the name  of your figure
title('Input signal'); 
subplot(2,1,2); 
stem(m,output); 
 
% axis command specifies the limit of current axis
axis ([0 200 -1 1]); 
xlabel('samples'); 
ylabel('amplitude'); 
  
%Interpolated signal or Filtered signal
title('Interpolated signal');

输出:

在MATLAB插值中取消采样后进行过滤

在MATLAB插值中取消采样后进行过滤

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程