www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/DiscreteFilterExample.m

    %% Modify Amplitude of Data
% This example shows how to modify the amplitude of a vector of data by
% applying a transfer function.

%%
% In digital signal processing, filters are often represented by a
% transfer function. The Z-transform of the difference equation
%
% $$\begin{array}{rcl}
% a(1)y(n) &=& b(1)x(n)+b(2)x(n-1)+...+b(N_{b})x(n-N_{b}+1)\\
% &&{}-a(2)y(n-1)-...-a(N_{a})y(n-N_{a}+1)\end{array}$$
%
% is the following transfer function.
%
% $$Y(z) = H(z^{-1})X(z) =
% \frac{b(1)+b(2)z^{-1}+...+b(N_{b})z^{-N_{b}+1}}{a(1)+a(2)z^{-1}+...+a(N_{a})z^{-N_{a}+1}}X(z)$$

%%
% Use the transfer function
%
% $$H(z^{-1}) = \frac{b(z^{-1})}{a(z^{-1})} =
% \frac{2+3z^{-1}}{1+0.2z^{-1}}$$
% 
% to modify the amplitude of the data in |count.dat|.

%% 
% Load the data and assign the first column to the vector |x|.
load count.dat
x = count(:,1);

%% 
% Create the filter coefficient vectors according to the transfer function $H(z^{-1})$.
a = [1 0.2];
b = [2 3];

%% 
% Compute the filtered data, and plot both the original data and the
% filtered data.  This filter primarily modifies the amplitude of the
% original data.
y = filter(b,a,x);

t = 1:length(x);
plot(t,x,'--',t,y,'-')
legend('Original Data','Filtered Data')