Project02
Project02
ELEC 6601
Question 1.
Introduction
This project analyzes a causal Linear Time-Invariant (LTI) system with a given transfer
function, H(z) By examining various characteristics of H(z), such as the impulse response,
frequency response, pole-zero plot, and filter type, we aim to understand the system's
behavior and classify the type of filter it represents.
For an LTI system characterized by a transfer function H(z), key properties such as the
impulse response and frequency response can reveal the system's behaviour in both the
time and frequency domains. The impulse response indicates how the system responds to
a unit impulse input, while the frequency response describes how the system processes
different frequency components of the input signal.
The amplitude and phase of the frequency response give insight into which frequencies are
passed or attenuated by the system, helping to classify it as a low-pass, high-pass, band-
pass, or band-stop filter. The pole-zero plot also provides valuable information, as the
location of poles and zeros determines the stability and frequency characteristics of the
system.
Matlab code
% Define the coefficients of the transfer function H(z)
num = [1, 2, 1]; % Numerator coefficients
den = [1, -1.2, 0.5]; % Denominator coefficients
figure;
subplot(3,1,1);
impz(num, den);
title('Impulse Response of H(z)');
xlabel('n');
ylabel('h[n]');
subplot(3,1,3);
plot(w/pi, angle(H));
title('Phase Response ∠H(e^{j\omega})');
xlabel('\omega / \pi');
ylabel('Phase (radians)');
1. Impulse Response: We compute the impulse response using impz(num, den, 30),
which calculates the response of the system to a unit impulse input over 30
samples. The response is plotted to observe the time-domain behavior of the
system.
3. Pole-Zero Plot: The zplane(num, den) function plots the poles and zeros of
H(z)H(z)H(z). The positions of poles and zeros help to understand the stability and
frequency characteristics of the filter.
4. Difference Equation: From the transfer function H(z), we derive the difference
equation for the system. The equation governing the system is:
5. Filter Type : Based on the amplitude response plot, this system attenuates
frequencies around ω=0.6π, while allowing other frequencies to pass. This
characteristic is indicative of a band-stop filter. The band-stop filter selectively
removes a specific frequency range, making it useful in applications where certain
frequencies need to be suppressed. The pole-zero plot configuration also supports
this classification, as it aligns with the frequency characteristics observed in the
amplitude response.
Results
The results from the MATLAB code are shown in the figures:
1. Impulse Response: The impulse response indicates the time-domain behavior, with
a rapidly decaying response.
2. Amplitude and Phase Response: The amplitude response shows attenuation around
ω=0.6π\omega = 0.6\piω=0.6π, confirming the band-stop filter behavior. The phase
response provides information about the phase shift across frequencies.
3. Pole-Zero Plot: The poles lie within the unit circle, confirming that the system is
stable. The configuration of poles and zeros contributes to the band-stop behavior
observed in the amplitude response.
5
Conclusion
The analysis of this system confirms that it functions as a stable band-stop filter,
selectively attenuating frequencies around ω=6π. The MATLAB code provided an effective
approach to visualize and confirm the system's behavior in both the time and frequency
domains, and the results align well with theoretical expectations for a band-stop filter.
7
Question 2.
Introduction
Background
An LTI system’s behavior can be fully described by its difference equation, which relates the
current and past input and output values. For this system, the difference equation is given
by:
This equation characterizes a second-order system with feedback, making it suitable for
analysis using Discrete-Time Fourier Transform (DTFT) techniques. By taking the Z-
transform of this equation, we derive the transfer function H(z) = Y(z) / X(z). The transfer
function helps us understand the system’s frequency response and stability, as we can plot
its amplitude and phase responses and observe the pole-zero distribution.
• The impulse response is derived to observe how the system responds to an initial
impulse.
• The frequency response (amplitude and phase) is plotted to analyze the system’s
filtering characteristics.
MATLAB Codes
Part 1: Define the System and Find the Transfer Function
We define the coefficients of the system’s transfer function based on the difference equation.
The numerator num and denominator den represent the coefficients of x[n] and y[n], respectively.
The system’s behavior can be characterized by its transfer function H(z) = Y(z)/ X(z)
Given,
The impulse response, h[n], is obtained using MATLAB's impz function, which calculates the
system’s response to a unit impulse. The impulse response provides insight into the system’s
behavior in the time domain.
9
figure;
impz(num, den);
xlabel('n');
ylabel('h[n]');
The freqz function is used to calculate the system’s frequency response, including amplitude and
phase responses. This allows us to determine the type of filter represented by the system by
observing the frequency ranges with the highest gains.
figure;
subplot(2,1,1);
plot(w/pi, abs(H));
xlabel('\omega / \pi');
ylabel('Magnitude');
subplot(2,1,2);
plot(w/pi, angle(H));
xlabel('\omega / \pi');
ylabel('Phase (radians)');
The pole-zero diagram, created using zplane, reveals the system’s stability. A stable system has
all its poles within the unit circle in the Z-plane.
figure;
zplane(num, den);
The filter function is used to calculate the output responses for each input.
x1 = sin(pi/8 * n);
x2 = sin(3*pi/4 * n);
figure;
subplot(3,1,1);
plot(n, y1);
xlabel('n');
ylabel('y_1[n]');
subplot(3,1,2);
plot(n, y2);
xlabel('n');
ylabel('y_2[n]');
subplot(3,1,3);
plot(n, y3);
xlabel('n');
ylabel('y_3[n]');
12
MATLAB Code
subplot(3,1,3);
plot(w/pi, angle(H));
title('Phase Response ∠H(e^{j\omega})');
xlabel('\omega / \pi');
ylabel('Phase (radians)');
figure;
subplot(3,1,1);
plot(n, y1);
title('Output Response to x_1[n] = sin(\pi/8 \cdot n)');
xlabel('n');
ylabel('y_1[n]');
subplot(3,1,2);
plot(n, y2);
title('Output Response to x_2[n] = sin(3\pi/4 \cdot n)');
xlabel('n');
ylabel('y_2[n]');
subplot(3,1,3);
plot(n, y3);
title('Output Response to x_3[n] = u[n]');
xlabel('n');
ylabel('y_3[n]');
Results
Impulse Response: The impulse response plot shows a decaying oscillatory behavior, indicating
that the system is stable. This decay confirms that the system has poles within the unit circle.
Frequency Response: The amplitude response reveals a peak near ω/π = 1, suggesting that the
system acts as a band-pass filter, allowing frequencies near this value to pass while attenuating
others. The phase response is continuous and smooth, which is characteristic of an LTI system.
14
Figure 01 : The impulse response and amplitude and phase frequency responses
Pole-Zero Diagram: The pole-zero plot (not shown in this report but generated) confirms that
the system’s poles are within the unit circle, further supporting the system’s stability.
15
Output Responses
• For x1[n] = sin(π/8⋅n): The output response shows a damped oscillation, indicating that
the system attenuates lower frequencies.
• For x2[n] = sin(3π/4⋅n) = sin(3π/4⋅n): The output response exhibits sustained
oscillations, as the frequency 3π/4 lies within the system’s passband.
• For x3[n] = u[n]: The response to the step input decays to zero, indicating that the
system does not resonate with a step input and is stable.
16
Discussion of Results
The system’s responses to the three different inputs reveal its selective frequency passing
characteristics:
3. Response to x3[n]=u[n]:The step input initially excites the system, but the response
quickly decays to zero, indicating that the system is stable and does not resonate with
broad-spectrum inputs.
The frequency response of the system, with its peak near ω/π=1, confirms that it functions as a
band-pass filter, allowing mid-range frequencies while attenuating lower and higher frequencies.
Conclusion
The analysis confirms that the system behaves as a band-pass filter, primarily allowing
frequencies around π (or half the Nyquist frequency) to pass while attenuating both lower and
higher frequencies. The impulse and frequency responses indicate a stable system, verified by
the pole-zero plot and the responses to various inputs. This band-pass characteristic is evident
from the amplitude response plot, and the system’s response to sinusoidal inputs aligns with this
behavior. The stability and filter type make this system suitable for applications where mid-range
frequency components are required, while low and high frequencies are undesired.
18
Question 3
Introduction
This report analyzes a discrete-time signal x[n] = sin(3nπ/5) + cos(7nπ/5) to estimate its
frequency spectrum using the Discrete Fourier Transform (DFT). The analysis explores how
segment lengths impact the clarity and accuracy of the frequency spectrum. By examining the
spectrum across varying segment lengths, we gain insight into spectral leakage and resolution
effects in DFT-based signal processing.
Background
In the range f ∈ [0,0.5], frequencies above 0.5 reflect back due to the DFT symmetry, causing f =
0.7 to alias to f = 0.3. Therefore, the DFT-based spectrum should show a single peak at f=0.3.
The DFT provides an estimate of the frequency content based on finite-length signal segments.
Longer segments improve frequency resolution, reducing spectral leakage and creating a sharper,
more distinct peak. This project examines the spectrum for segments of length 1000, 500, 100,
and 20 to study the effects of segment length on spectral accuracy.
Aliasing:
• In a DFT for real signals, frequencies above f=0.5 reflect back (alias) into the range
f∈[0,0.5]. Thus, the component at f=0.7 aliases to f = 1−0.7 = 0.3.
• As a result, both terms contribute to a single peak at f=0.3.
Expected Spectrum:
• Based on this theoretical analysis, we expect a single peak at f=0.3 in the magnitude
spectrum ∣X(f)∣ within the range f∈[0,0.5].
Figure: 01
20
For Parts II and III, we generate finite signal segments of varying lengths, compute the DFT of
each segment, and plot the magnitude spectrum. This allows us to observe the impact of segment
length on frequency resolution and spectral leakage.
Figure: 02
21
Figure: 03
22
Figure: 04
23
Figure: 05
N_DFT: We set the DFT length to 1024 for all segments. Using a fixed DFT length (higher than
the segment length) helps improve frequency resolution by zero-padding shorter segments up to
1024 points. This provides a consistent frequency axis for comparing spectra across different
segment lengths.
24
f = (0:N_DFT/2) / N_DFT;
figure;
ylabel('|X(f)|');
grid on;
Segment Length: We use N=200 as a moderate segment length for theoretical approximation.
DFT with Zero-Padding: By computing the DFT with a length of 1024, we improve frequency
resolution and get a smoother plot.
25
Plotting: This plot displays the magnitude spectrum ∣X(f)∣ and should show a peak around f=0.3.
N_segment = 1000;
X = fft(x, N_DFT);
f = (0:N_DFT/2) / N_DFT;
figure;
plot(f, abs(X(1:N_DFT/2+1)));
ylabel('|X(f)|');
grid on;
DFT Calculation: X = fft(x, N_DFT) computes the DFT of the signal segment with a length of
1024. Since Nsegment=1000 is less than NDFT=1024, MATLAB automatically zero-pads the
signal to length 1024. Zero-padding improves the frequency resolution, allowing finer frequency
bins.
Frequency Axis:
o f = (0: N_DFT/2) / N_DFT defines the frequency axis for the plot. By dividing by
NDFT, we normalize the frequency axis from 0 to 1.
o We then restrict the range to f∈ [0,0.5] , since the DFT is symmetric for real-
valued signals.
o plot (f, abs(X(1:N_DFT/2+1))) plots the magnitude of the DFT in the range f∈
[0,0.5].
o The title, x-axis, and y-axis labels provide context, and grid on improves
readability.
This segment length (1000) provides high resolution, resulting in a sharp, distinct peak around
f=0.3, closely matching the theoretical expectation.
% Part III: Different Segment Lengths for Comparison (500, 100, and 20)
for i = 1:length(segment_lengths)
figure;
plot(f, abs(X(1:N_DFT/2+1)));
ylabel('|X(f)|');
grid on;
end
Segment Lengths (500, 100, 20): Segment lengths = [500, 100, 20] creates an array of the
different segment lengths to be tested in Part III. For i = 1: length(segment_lengths) iterates
through each segment length to compute and plot the DFT.
Looping Over Segment Lengths: Inside the loop, N = segment_lengths (i) sets the current
segment length (500, 100, or 20) and n = 0:N-1 defines the time index for the current segment.
DFT Calculation with Zero-Padding: X = fft(x, N_DFT) computes the DFT of length 1024 for
each segment. For segment lengths less than 1024, MATLAB zero-pads the signal, ensuring that
the DFT length is consistently 1024 for all cases.
Plotting the Spectrum for Each Segment Length: Inside the loop, a new plot is generated for
each segment length using plot(f, abs(X(1:N_DFT/2+1))). The title dynamically changes to show
the current segment length (e.g., "Segment Length N = 500"). The x-axis and y-axis labels, along
with grid on, ensure clarity for each plot.
28
Matlab code
%% Part III: Different Segment Lengths for Comparison (500, 100, and 20)
29
for i = 1:length(segment_lengths)
N = segment_lengths(i); % Current segment length
n = 0:N-1; % Time index for the segment
x = sin(3 * pi * n / 5) + cos(7 * pi * n / 5); % Generate the signal segment
Results
o This segment length is too short to capture the frequency content accurately, as
spectral leakage dominates and obscures the main frequency component.
Conclusion
This analysis demonstrates the importance of segment length in DFT-based spectral estimation.
The theoretical approximation in Part I, using a segment length of 200, provides a reasonably
accurate view of the main frequency content, showing a peak at f=0.3, but with slightly reduced
sharpness due to its shorter length. Longer segments, such as 1000 and 500, more closely
approximate an ideal spectrum by providing a sharper, well-defined peak with minimal spectral
leakage. In contrast, shorter segments, like 100 and 20, significantly reduce spectral resolution,
broadening the peak and introducing leakage that distorts the spectrum.