ad space

impz() matlab function usage in digital filters

 The impz() function in MATLAB is used to generate the impulse response of a given filter. Consider for example, 4th order Butterworth low pass filter. The IIR digital filter is given below.

  \( H(z) = \frac{\sum_{k=0}^{M}b_k z^{-k}}{\sum_{k=0}^{N}a_k z^{-k}} = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2} + ... + b_n z^{-n}}{a_0 + a_1 z^{-1} + a_2 z^{-2} + ... + a_n z^{-n}}\) ---->(1)

The impulse response h(n) of this filter can be calculated using the impz() matlab function utilizing the coefficients a and b.

impz(b, a);

An example matlab program that calculates the impulse response of 4th order IIR digital filter is below.

 % Designing a low-pass filter
fc = 1000; % Cutoff frequency in Hz
fs = 8000; % Sampling frequency in Hz
order = 4; % Filter order

% Compute filter coefficients using the Butterworth filter design
[b, a] = butter(order, fc/(fs/2), 'low');

% Plot impulse response
impz(b, a);
title('Impulse Response of a Low-Pass IIR Filter');

% Generate input signal
t = 0:1/fs:100/fs; % Time vector
f1 = 500; % Frequency of first sinusoid
f2 = 5000; % Frequency of second sinusoid
x = sin(2*pi*f1*t) + sin(2*pi*f2*t); % Input signal

% Apply filter using the filter function
y = filter(b, a, x); % Apply filter to input signal

% Plot input and output signals
figure;
subplot(2,1,1);
plot(t,x);
title('Input Signal');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(2,1,2);
plot(t,y);
title('Output Signal');
xlabel('Time (s)');
ylabel('Amplitude');


 

In the above code, we first use the impz() function to plot the impulse response of the IIR filter, using the b and a coefficients as input. The resulting plot shows the filter's response to an impulse input.

impulse response IIR filter

 We then generate the input signal x as a sum of two sinusoids, apply the filter to the input signal using the filter() function, and plot the input and output signals using the plot() function. Note that we use the filter() function instead of the conv() function to apply the IIR filter, since the filter() function takes into account the feedback terms of the difference equation that defines the filter, while the conv() function does not.

The resulting plot shows the input and output signals, with the output signal showing the effect of the low-pass filter on the input signal.

IIR  digital filter

Reference

[1] IIR filter without Matlab inbuilt function

[2] Derivation of Z-transform Equation

[3] How to calculate IIR filter coefficients in Matlab

[4] Matlab conv() function for filter design and analysis



Post a Comment

Previous Post Next Post