Dsap Lab 3
Dsap Lab 3
y[n] = ∑ x [ k ] h[n−k ]
k=−∞
Infinite Impulse Response (IIR) filters are a type of recursive filter commonly used in
signal processing. They compute the output based on current and previous inputs and
outputs. IIR filters are designed by identifying the pulse transfer function H(z) that meets
the specified filter requirements. Their implementation often results in reduced memory
and processing demands when used in software.
The magnitude response of an IIR filter refers to its behavior concerning amplitude at
different frequencies. It describes how the filter affects the amplitude of various
frequency components in the input signal. The magnitude response is typically
represented by a frequency response curve, usually displayed on a logarithmic scale in
decibels (dB).
The phase response of an IIR filter describes the relationship between the input and
output signals in terms of phase or time delay at different frequencies. It is represented by
a phase response curve, which illustrates the phase shift introduced by the filter as a
function of frequency. The phase shift is commonly expressed in degrees or radians.
M
Y ( z)
∑ b k z−k
k=0
H(z) = X (z )
= N
1+ ∑ ak z
−k
k=1
By modifying the writing style, I aimed to provide a clearer and more concise
explanation of the concepts associated with LTI systems, linearity, time invariance,
impulse response, convolution, IIR filters, magnitude response, and phase response.
SOURCE CODE:
clc;
clear all;
close all;
n = -2:2;
a = length(n);
x = 1;
while(x<=a)
if(n(x)>= 0)
ud(x)= 1;
h(x)=2^n(x);
else
ud(x)=0;
h(x)=0;
end
x = x+1;
end
grid on;
y = conv (ud, h);
subplot (3,1,1);
stem(n,ud);
title('x[n]=u(n)-76015')
subplot (3,1,2);
stem(n,h);
title('h[n]=2^n*u (n)-76015')
subplot (3,1,3);
stem(y);
title('Y[n]-76015');
OUTPUT:
DISCUSSION:
In the given lab session, the goal was to process an input signal x[n] and an impulse
response h[n] using a linear time-invariant (LTI) system. The following steps were
undertaken to achieve this:
The input signal x[n] and impulse response h[n] were generated by limiting their ranges
from -2 to +2. This range limitation was necessary as the original signals were infinite
series. The length of the range was stored in the variable a.
To generate the signals, a loop was implemented with a length of 5, based on the value
stored in a. Within the loop, conditions were applied to determine the values of x[n] and
h[n] at each index. The specific conditions for generating the signals were not mentioned
in the description, but they were implemented within the loop.
Once the values of x[n] and h[n] were calculated, the next step involved finding the
output of the LTI system. This was achieved by performing convolution between x[n] and
h[n] using the conv function. Convolution combines the two signals to produce the output
signal y[n].
Finally, the stem function was utilized to plot the input signal x[n], impulse response
h[n], and the output of the LTI system y[n]. However, in the description, it is mentioned
that only stem(y) was used to plot the output. This indicates that only the output signal
y[n] was plotted to observe its behavior over time, while the input signal and impulse
response were not explicitly visualized.
In summary, the lab session involved generating the input signal x[n] and impulse
response h[n], convolving them to obtain the output of the LTI system y[n], and plotting
the output signal. The specific conditions for generating x[n] and h[n] were not provided,
but the main focus was on analyzing the behavior of the output signal y[n] over time
using the stem function.
−1 −2 −3
0 .56 z +0 . 638 z + 0 . 08 z
2. H(z) = −1 −2 −3
1+ 0. 6 z +0 . 34 z −0 . 4 z
clc;
clear all;
close all;
b =[0 0.56 0.638 0.08];
a = [1 0.6 0.34 -0.4];
[H, w] = freqz (b, a, 1024, 'whole');
mag = abs(H);
phase=angle(H);
W = w/pi;
subplot(2,1,1);
plot (w, mag);
xlabel('Normalized frequency (\times\Pi)');
ylabel('Magnitude');
title('Magnitude response-76015');
subplot(2,1,2);
plot (w, phase);
xlabel('Normalized frequency (\times\Pi)');
ylabel('Phase');
title('Phase response-76015');
OUTPUT:
DISCUSSION:
During this lab, our objective was to analyze and visualize the magnitude and phase
response of an Infinite Impulse Response (IIR) filter. We were provided with the transfer
function equation, H(z), and our task was to plot the frequency response.
To begin, we examined the given transfer function equation and compared it with the
equation representing a causal IIR system. By making this comparison, we determined
the coefficients 'b' and 'a' specific to the transfer function. These coefficients were then
stored in the variables 'b' and 'a', respectively.
To calculate the frequency response of the IIR filter, we utilized the 'freqz' function. By
using the statement '[H, w] = freqz(b, a, 1024, 'whole')', we obtained the frequency
response vector 'H'. The '1024' parameter determines the number of points used to sample
the frequency range.
To derive the magnitude response, we computed the absolute values of 'H' using the 'abs'
function. Similarly, to determine the phase response, we applied the 'angle' function to
'H'.
Finally, we utilized the 'plot' function to create visual representations of the magnitude
and phase responses. These plots allow us to gain insights into how the IIR filter affects
the amplitude and phase of different frequency components.
CONCLUSION:
The lab session was a valuable learning experience in the field of signal processing. We
delved into two key concepts: convolution and Infinite Impulse Response (IIR) filters.
Convolution, the fundamental operation in linear systems, was explored in the context of
an LTI system. We grasped the significance of convolving the input signal with the
impulse response to obtain the output signal, enabling us to comprehend how the system
modifies the input over time. Employing MATLAB's conv function, we executed the
convolution process seamlessly. An important observation was made regarding the
plotting of the LTI system's output. By visualizing the complete output signal, without
restricting the range, we gained a holistic understanding of its behavior and dynamics.
Furthermore, we dived into the realm of IIR filters, recursive filters commonly used in
signal processing. The transfer function equation of an IIR filter was provided, and we
derived the numerator and denominator coefficients. We explored how to compute and
analyze the magnitude and phase response of the IIR filter using the freqz function,
allowing us to understand its frequency-dependent characteristics. This lab session
equipped us with practical knowledge and tools to investigate linear systems, design
filters, and analyze their responses in MATLAB.