How to test Digital Filter design in Matlab | applied electronics engineering

### Latest

By Applied Electronics - Monday, January 2, 2017 No Comments
In this matlab tutorial we show how to apply simple input signal to a digital filter designed in matlab and view the filter response.

Let us consider first the design of a simple digital filter. A digital filter is described by coefficients a and b. These are as follows,

b = 1
a = 1, -1, 0.9


We generated in earlier post different types of signals. These will be applied to the digital filter. The signals are again provided here,

n0 = 0;
n1 = -20;
n2 = 120;
n = [n1:n2];
M= 60;
N = [n1:n2];

% generate impulse sequence
imp = [(N-n0) == 0];

%generate unit impulse
u = [(N-n0) >= 0];

% generate real valued signal
xr = (0.75).^n;

% complex valued exponential signal
xexp = exp((4+1*j)*n);

% sinusoid signal
x = 7*cos(0.4*pi*n+pi/3)+3*sin(0.5*pi*n);

% uniformly distributed random signal
runi = rand(1,M);

% Gaussian distributed random signal
rgau = randn(1,M);



Now these signals are applied to the digital filter. The code is shown below.

% Apply Filter

b = [1];
a = [1 -1 0.9];

y1 = filter(b,a,imp);
y2 = filter(b,a,u);
y3 = filter(b,a,x);
y4 = filter(b,a,xr);
y5 = filter(b,a,xexp);
y6 = filter(b,a,rgau);

figure(4)

subplot(3,2,1)
stem(N,y1)
title('Response due to Impulse Input')
xlabel('n')
ylabel('Impulse Response')

subplot(3,2,2)
stem(N,y2)
title('Response due Unit Input')
xlabel('n')
ylabel('Unit Step Response')

subplot(3,2,3)
stem(N,y3)
title('Response due x input')
xlabel('n')
ylabel('Impulse x Response')

subplot(3,2,4)
stem(y4)
title('Response due sinusoid x Input')
xlabel('n')
ylabel('xexp Response')

subplot(3,2,5)
stem(N,y3)
title('Response due x real input')
xlabel('n')
ylabel('Real x Response')

subplot(3,2,6)
stem(y4)
title('Response due to complex x Input')
xlabel('n')
ylabel('Complex x Response')

The response of the filter to the different input signal is as follows,