akash 1
akash 1
Lab Report 03
Course Title: Digital Signal Processing Sessional
Part – A
Code:
fprintf('Coefficients of X2(z):\n');
disp(coeff_X2);
Output:
Coefficients of x1(z):
1 2 3
Coefficients of X2(z):
2 3 4 5
Coefficients of X3(z) = X1(z) * X2(z):
2 7 16 22 22 15
Discussion:
X3(z) = X1(z) * X2(z) is calculated using the conv() function. The convolution operation
on the coefficient arrays corresponds to multiplying the polynomials in the z-domain.
The conv() function efficiently handles this process by applying the distributive property
of multiplication and summing up coefficients of terms with the same power of z^(-k).
3.Displaying Results:
The code displays the coefficients of X1(z), X2(z), and X3(z). This allows for
verification of intermediate and final results of the computation.
4.Theoretical Verification:
The code suggests a manual verification step, encouraging users to expand the
polynomial multiplication: (2 + 3z^(-1) + 4z^(-2)) * (3 + 4z^(-1) + 5z^(-2) + 6z^(-3)).
By comparing this manual expansion with the output of the conv() function, users can
confirm the correctness of the convolution operation.
Output:
1,1.6, −0.52,0.4,−0.2224,0.13696,−0.081472,0.049024,−0.02938624,0.017637376
Discussion:
1. System Definition:
The transfer function H(z) is expressed using its numerator and denominator coefficients:
H(z) = (1 + 2z^(-1)) / (1 + 0.4z^(-1) - 0.12z^(-2))
The numerator [1, 2] corresponds to 1 + 2z^(-1), while the denominator [1, 0.4, -0.12]
represents 1 + 0.4z^(-1) - 0.12z^(-2).
2. Impulse Input:
The impulse response is obtained by applying an impulse input x(k), where:
x(1) = 1 (impulse input at k = 0)
x(k) = 0 for k > 1.
3. Difference Equation:
The impulse response is iteratively computed using the following difference equation
derived from the transfer function:
y(k) = b1 * x(k) + b2 * x(k-1) - a2 * y(k-1) - a3 * y(k-2)
Here:
- b1 and b2 are the numerator coefficients.
- a2 and a3 are the non-leading denominator coefficients (with a1 normalized to 1).
Conditional evaluations (e.g., k > 1 and k > 2) ensure valid indexing for terms like x(k-1),
y(k-1), and y(k-2).
4. Implementation:
A loop iterates over n = 10 samples to calculate the impulse response. For each sample:
- The current output y(k) (or impulse response at k) is computed based on the present
and past inputs and outputs.
MATLAB's conditional indexing ensures that computations only include valid terms for k
= 1 or k = 2.
5. Results:
The code calculates and displays the first 10 coefficients of the impulse response. These
coefficients characterize the system's time-domain behavior when subjected to an impulse
input:
- If the coefficients decay to zero, the system is stable.
- If the coefficients grow indefinitely, the system is unstable.
Part – B
Code:
% Define system poles
r = 0.95; % Adjusted radius of the poles (slightly less than 1 for stability)
theta = pi / 6; % Modified angle of the poles to change frequency
Output:
Transfer Function H(z):
1
----------------------
z^2 - 1.386 z + 0.9604
Discussion:
1. System Poles:
The system’s behavior is governed by its poles:
The radius r=0.95 determines the magnitude of the poles, which is slightly less than 1. This
ensures the system is stable with damped oscillations, as the poles lie inside the unit circle in
the z-plane.
The angle θ=π/6 specifies the frequency of oscillation. θ corresponds to π/6 radians/sample,
which translates to a normalized frequency of oscillation.
Two complex-conjugate poles are defined:
p1=r.e^iθ, p2=r.e^(-iθ)
These poles describe the system's oscillatory behavior in the time domain.
5. Pole-Zero Diagram:
The pole-zero diagram is a graphical representation of the system's dynamics:
The poles (p1 and p2) are plotted as red "x" marks in the complex plane.
The unit circle is displayed as a dashed line, serving as a reference for stability and frequency
analysis.
Since both poles are inside the unit circle, the system is stable.
B.2 Design a simple low pass and a high pass filter. [Hint: If you
don’t know the exact locations of poles and zeros, try to calibrate
it using SPTOOL]
Code:
% Sampling frequency
fs = 1000; % Hz
% Frequency points for visualization
n_points = 512; % Number of frequency points
Output:
Discussion:
1. Sampling Frequency:
• The sampling frequency fs=1000 Hz is used to scale the normalized frequencies (in the
range 0 to π) to actual frequency values in Hz.
2. Low-Pass Filter:
(a) Design:
• The cutoff frequency ωc is specified as 0.4π radians/sample, which corresponds to
fc=200 Hz in actual frequency (since ωc=2πfc/fs).
• A simple first-order filter is implemented:
o Numerator: [1], representing a gain of 1 for low frequencies.
o Denominator: [1, -e^(-ωc)] controlling the roll-off behavior beyond the cutoff
frequency.
(b) Frequency Response:
• The magnitude response |H(e^jω)| is computed using freqz(), which calculates the
frequency response of the filter.
• The plot shows:
o A flat passband for frequencies below fc.
o A gradual roll-off beyond the cutoff frequency, as expected for a first-order low-pass
filter.
(c) Impulse Response:
• The impulse response is calculated manually, simulating the system’s output to an
impulse input.
• The response shows an exponentially decaying sequence, characteristic of a first-order
low-pass filter. This response highlights how the filter smooths high-frequency
components.
3. High-Pass Filter:
(a) Design:
• The cutoff frequency ωc=0.6π radians/sample corresponds to fc=300 Hz in actual
frequency.
• A first-order high-pass filter is implemented:
o Numerator: [1, -1], ensuring high-frequency components are passed and low-
frequency components are attenuated.
o Denominator: [1, -e^(-ωc)] controlling the attenuation behavior in the stopband.
(b) Frequency Response:
• The frequency response plot shows:
o Significant attenuation of frequencies below fc=300 Hz.
o A flat passband for higher frequencies, consistent with high-pass filter behavior.
(c) Impulse Response:
• The impulse response exhibits an alternating pattern, indicating the emphasis on rapid
changes in the input signal. This is characteristic of high-pass filters, which enhance high-
frequency components.
4. Comparison of Filters:
(a) Frequency Selectivity:
• The low-pass filter allows frequencies below 200 Hz to pass while attenuating higher
frequencies.
• The high-pass filter passes frequencies above 300 Hz, attenuating lower frequencies.
(b) Impulse Responses:
• The low-pass filter’s impulse response is smooth and decays exponentially, reflecting its
smoothing effect on signals.
• The high-pass filter’s impulse response alternates in sign, emphasizing sharp transitions
and high-frequency details.
Part – C
C.1 Determine the system function and the response for a) unit
step b) unit impulse input described by the difference equation-
(assume a causal LTI system)
y(n) = y(n - 1) + x(n)
Code:
Output:
Discussion:
1. Transfer Function:
The transfer function describes a system that has a single pole at z=1 and a zero at the
origin (z=0). These characteristics are evident from the numerator and denominator
coefficients:
The numerator defines a zero at the origin.
The denominator defines a pole at z=1, indicating an unstable system because the pole
lies on the boundary of the unit circle.
2. Pole-Zero Plot:
The pole-zero plot provides a graphical representation of the system's dynamics in the
z-domain. The pole at z=1suggests that the system exhibits unbounded growth in
response to certain inputs, reflecting instability. The zero at the origin influences how
the system attenuates or amplifies signals at various frequencies.
3. Impulse Response:
The response to a unit impulse input (δ(n)) is calculated using the filter function.
Since the transfer function is unstable, the impulse response grows without bound.
This behavior aligns with the pole's location at z=1, where the system repeatedly
accumulates the input value instead of settling to a steady state. The plotted impulse
response illustrates this unbounded growth, highlighting the instability of the system.
4. Step Response:
The response to a unit step input (u(n)) is also computed using the filter function. The
step response, like the impulse response, exhibits unbounded growth due to the
system's pole at z=1. The plotted step response shows a steadily increasing output,
consistent with the theoretical behavior of an unstable system.
5. System Behavior:
The primary characteristic of this system is its instability. A pole at z=1 causes
unbounded growth in both the impulse and step responses. This behavior indicates
that the system cannot be used in practical applications unless the instability is
addressed through modifications, such as pole shifting or stabilization techniques.
C.2 Determine the system function and the unit sample response
for a stable LTI system described by the difference equation
y(n)=0.5y(n-1)+x(n)+0.3x(n-1)
Comment on ROC.
Code:
Output:
Discussion:
2. Pole-Zero Plot:
The pole-zero plot provides a graphical representation of the system's dynamics in the z-
domain:
The pole at z=1/2 indicates that the impulse response will decay exponentially with a
factor of (1/2)n.
The zero at z=−1/3 modifies the system's gain and introduces a specific spectral shaping.
This visualization is a key tool for understanding the system's stability and its influence
on different frequency components.
3. Impulse Response:
The impulse response h(n) is computed analytically as h(n)=(4/3)(1/2)n for n≥0n. This
response:
Reflects the system's reaction to a unit impulse input.
Exhibits exponential decay due to the pole at z=1/2, with the rate of decay governed by
the pole's magnitude.
Demonstrates stability, as the response diminishes over time instead of growing
unbounded.
The impulse response is plotted for n=0 to n=10, clearly illustrating the decay pattern.
4. System Verification:
The code includes theoretical verification by displaying the system's transfer function and
the formula for its impulse response. This ensures consistency between the analytical
derivation and the MATLAB implementation.
5. System Behavior:
This system acts as a simple low-pass filter, where the pole location determines the
smoothing effect. The zero at z=−1/3 slightly modifies the spectral characteristics,
enhancing certain frequency components while attenuating others.
Specify the ROC of H(z) and determine h(n) for the following
conditions:
(a) The system is causal, (b) The system is anticausal, & (c) The
system is noncausal.
Code:
% Stability check
is_stable = all(abs(poles) < 1); % System is stable if all poles are inside the unit
circle
if is_stable
disp('The system is stable.');
else
disp('The system is unstable.');
end
Output:
Poles of H(z):
3.0000
0.5000
Discussion:
1. System Representation:
The transfer function H(z) is defined by its numerator and denominator coefficients.
The denominator describes the system's poles, while the numerator describes the
zeros. These poles and zeros determine the system's dynamic and frequency-selective
behavior.
2. Pole-Zero Analysis:
The roots of the denominator polynomial correspond to the poles of H(z), which are
critical for analyzing system stability and causality. The code uses roots to compute
the pole locations and zplane to visualize the pole-zero plot.
The pole-zero plot reveals the system's behavior in the zzz-domain.
Poles closer to the unit circle indicate signals that decay slowly, while poles outside the
unit circle represent instability.
4. System Stability:
Stability is determined by the pole locations:
If all poles lie strictly within the unit circle (∣z∣<1), the system is stable and its impulse
response converges.
If any pole lies on or outside the unit circle, the system is unstable.
In this case, the poles at z=3 and z=0.5 indicate that the system is unstable, as the pole
at z=3 is outside the unit circle.
2
z
C.4 An LTI system is given by 2
z −2.5 z +1
Make the system stable assuming the system (a) causal and (b)
anticausal.
Code:
% Define the coefficients for the numerator and denominator for causal and
anticausal systems
% Causal System: H(z) = z^2 / (z^2 - 0.5z + 1)
numerator_causal = [1 0 0]; % z^2
denominator_causal = [1 -0.5 1]; % z^2 - 0.5z + 1
% Plot the frequency response (magnitude and phase) for both systems
figure;
subplot(2, 1, 1);
bode(H_causal); % Plot Bode plot for causal system
title('Causal System Frequency Response');
subplot(2, 1, 2);
bode(H_anticausal); % Plot Bode plot for anticausal system
title('Anticausal System Frequency Response');
Discussion:
1. System Definitions:
The two systems analyzed are:
Causal System: The transfer function H(z)has a denominator with poles placed such that
the system can operate in a causal manner. Causality implies that the system's output at
any time depends only on the current and past input values.
Anticausal System: The transfer function H(z) has a denominator with poles configured
to emphasize future input values. Anticausality is less common in practical applications
but is relevant in theoretical studies and specific control scenarios.
2. Transfer Function Representation:
Both systems are defined in terms of their numerator and denominator coefficients.
These coefficients describe the behavior of the system in the z-domain. For the causal
system, the poles are closer to the unit circle and allow for a stable causal response.
For the anticausal system, the poles are placed further away, influencing the response
differently.
Output:
C.5 Write a generalized program in MATLAB which takes the
coefficients of the denominator of a system transfer function as
input and tests the system stability by Schür Cohn stability test
method.
Code:
% Step 3: Check the stability criterion (All values in last row should be positive)
if all(S(end, :) >= 0)
disp('The system is stable.');
isStable = 1; % Stable system
else
disp('The system is unstable.');
isStable = 0; % Unstable system
end
end
% Example usage
% Define the denominator coefficients of the system transfer function
denominator = [1 -1.5 0.7]; % Example: z^2 - 1.5z + 0.7
isStable = schurCohnStabilityTest(denominator);
Output:
Schur-Cohn Array:
1.0000 -1.5000 0.7000
0 -3.7500 1.0267
0 0 1.3077
5
y ( n )=
2
y(n-1)-y(n-2)+x(n)
From the pole-zero plot determine the ROC of H(z) for all the
possible cases –
✓ Determine and plot the impulse response of the system if h(n)
is absolutely summable.
✓ Cascade another system with the previous one to get both a
causal and a stable system. Determine the new ROC from the
pole-zero plot of the cascaded system and plot the impulse
response.
Code:
Output:
Discussion:
1. Impulse Response:
The exponential growth or decay of the impulse response highlights the stability of the
original system based on the pole magnitudes.
The choice of coefficients A and B influences the amplitude but not the stability of the
response.
2. Effect of Cascading:
The pole z3 from the second system introduces additional dynamics to the system. If z3
lies inside the unit circle, the cascaded system is more likely to remain stable.
3. Visualization:
The pole-zero plot is a critical tool for understanding system behavior. It provides a
graphical interpretation of the system’s stability and potential resonance points.
Code:
% Parameters
Fs = 1000; % Sampling frequency (Hz)
T = 1/Fs; % Sampling period
t = 0:T:1-T; % Time vector (1 second duration)
f = 10; % Frequency of sine wave (Hz)
A = 1; % Amplitude of sine wave
noise_power = 0.01; % AWGN power
% Plot results
figure;
subplot(5, 1, 1);
plot(t, input_signal);
title('Input Signal (Sine wave + AWGN)');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(5, 1, 2);
plot(t, LPF_output);
title('LPF Output');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(5, 1, 3);
plot(t, ZCD_output);
title('Zero-Crossing Detector Output');
xlabel('Time (s)');
ylabel('Binary Output');
subplot(5, 1, 4);
plot(t, edge_detector_output);
title('Edge Detector Output');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(5, 1, 5);
plot(t, triangular_wave);
title('Triangular Wave Generator Output');
xlabel('Time (s)');
ylabel('Amplitude');
Output:
Discussion:
Input Signal:
1. Sine Wave with Noise:
o The input signal combines a sine wave with additive white Gaussian noise
(AWGN). This simulates real-world signals where noise is present alongside the
desired signal.
Edge Detector:
6. Operation:
o The edge detector identifies transitions in the ZCD output, marking key points of
change in the signal.
7. Output:
o This process emphasizes points where the signal significantly changes, such as
peaks and troughs.
Visualization:
10. Results Analysis:
o Each stage provides insight into different aspects of the signal, from smoothing
out noise to identifying key events. The final triangular wave combines these
events into a continuous form.
11. Implications:
o This process highlights how digital signal processing techniques can effectively
handle noisy signals and transform them into useful data for analysis or control
applications.
Code:
% Display results
disp('Poles of the system:');
disp(poles);
if is_stable
disp('The system is stable: All poles are inside the unit circle.');
else
disp('The system is unstable: Some poles are outside the unit circle.');
end
The system is unstable: Some poles are outside the unit circle.
Discussion:
Analysis:
3. Poles:
o The roots of D(z) represent the system's poles.
o These poles determine the system's response and stability.
4. Stability:
o By checking the magnitudes of the poles, it is determined whether the system is
stable or not.
o If all poles are within the unit circle, the system is stable; otherwise, it is unstable.
Visualization:
5. Z-Plane Plot:
o The z-plane plot graphically displays the poles of the system.
o The plot shows their real and imaginary components, providing a clear view of
their locations relative to the unit circle.