0% found this document useful (0 votes)
46 views9 pages

DSP Lab Report 04

Uploaded by

Ahmer Farooqi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views9 pages

DSP Lab Report 04

Uploaded by

Ahmer Farooqi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1 Abstract

This lab focuses on studying impulse and step responses of a system using MATLAB, along with
analyzing correlation properties of discrete-time sequences.In this experiment,we utilized MATLAB to
explore essential concepts in signal processing and correlation analysis. Practical tasks involve studying
impulse response of systems, analyzing cross-correlation and convolution of discrete-time sequences,
and examining autocorrelation properties of noisy signals. This experiment serves as a valuable tool
for reinforcing theoretical concepts and fostering practical skills in signal processing and correlation
analysis within an educational setting.

2 Introduction
Impulse response characterizes the behavior of a system when subjected to an impulse input, providing
insights into its dynamics and stability. By utilizing MATLAB, a powerful computational tool, we can
efficiently compute and analyze the impulse response of various systems.Moreover, cross-correlation
and convolution are fundamental operations in signal processing, essential for comparing and com-
bining signals. Cross-correlation measures the similarity between two signals at different time lags,
while convolution represents the output of a system when subjected to an input signal. These op-
erations find wide applications in fields such as communication, image processing, and audio analy-
sis.Autocorrelation, on the other hand, quantifies the similarity of a signal with itself at different time in-
stants, providing valuable information about its periodicity and randomness. By employing MATLAB
functions, we can compute autocorrelation efficiently and explore the characteristics of discrete-time
sequences.

3 Objectives
The objectives of lab are:

• Study the impulse and step response of a system using MATLAB.

• Find cross-correlation and convolution of two discrete time sequences.

• Determine autocorrelation of a discrete time noise-corrupted sequence.

4 Lab Tasks
4.1 Task 01
Find Impulse response of a system using MATLAB.

1 − 5ejw
H(ejw ) =
1 − 0.3ejw + 4e2jw

1
4.1.1 Using impz function
4.1.2 Code
num = [1, -5];
den = [1, -0.3, 4];
impulse_response = impz(num, den);
stem(impulse_response);
xlabel(’Time (samples)’);
ylabel(’Amplitude’);
title(’Impulse Response’);

4.1.3 Result

Figure 1: Using impz function

4.1.4 Using impulse function


4.1.5 Code
num = [1, -5];
den = [1, -0.3, 4];
impulse_response = impulse(num, den);
% Plot the impulse response
stem(impulse_response);
xlabel(’Time (samples)’);
ylabel(’Amplitude’);
title(’Impulse Response’);

2
4.1.6 Result

Figure 2: Using Impulse function

4.1.7 Analysis
The impz function is specifically designed to compute the impulse response of a discrete-time system
given its transfer function. It takes the numerator and denominator coefficients of the transfer function
as input arguments. It directly computes the impulse response sequence using the Z-transform method.
This function is suitable for systems represented in the discrete-time domain.The impulse function is a
more generalized tool that can compute the impulse response of both continuous-time and discrete-time
systems. It does not require the transfer function coefficients as input. Instead, it accepts system models
(e.g., state-space models, transfer functions) or discrete-time impulse response directly. This function
can handle a broader range of system representations and provides more flexibility in specifying the
system.

4.2 Task 02
2. Find cross-correlation and convolution of two discrete time sequences

x(n) = ne−0.2n

y(n) = ne0.5n
Finally, analyze the output.

4.2.1 Code
% Define the sequences x[n] and y[n]
n = 0:20; % Assuming a range of n
x = n .* exp(-0.2 * n);

3
y = n .* exp(0.5 * n);

% Compute the cross-correlation using xcorr function


r_xy = xcorr(x, y);

% Compute the convolution using conv function


convolution = conv(x, y);

% Plot the sequences and the outputs using subplot


figure;

% Plot Sequence x[n]


subplot(4, 1, 1);
stem(n, x);
title(’Sequence x[n]’);
xlabel(’n’);
ylabel(’x[n]’);

% Plot Sequence y[n]


subplot(4, 1, 2);
stem(n, y);
title(’Sequence y[n]’);
xlabel(’n’);
ylabel(’y[n]’);

% Plot Cross-correlation r_{xy}[m]


m = -length(n)+1:length(n)-1;
subplot(4, 1, 3);
stem(m, r_xy);
title(’Cross-correlation r_{xy}[m]’);
xlabel(’m’);
ylabel(’r_{xy}[m]’);

% Plot Convolution (x * y)[n]


subplot(4, 1, 4); % Changed index from 3 to 4
stem(convolution);
title(’Convolution (x * y)[n]’);
xlabel(’n’);
ylabel(’(x * y)[n]’);

4
4.2.2 Result

Figure 3: Convoltion and cross correlation

4.2.3 Analysis
Cross-correlation and convolution are both operations used in signal processing to analyze the relation-
ship between two signals.The output of cross-correlation is a new signal that indicates the similarity
between the two input signals at different time lags. It helps identify shifts or delays between the sig-
nals.The output of convolution is a new signal that represents the effect of convolving one signal with
another. It describes how the input signal is modified as it passes through the system.

4.3 Task 03
Find autocorrelation using xcorr command and autocorr command separately of the discrete-
time sequence: x(n) = [1, 2, 5, 9, 2, 1, 5]. Finally, analyze the output.

4.3.1 Code
x = [1, 2, 5, 9, 2, 1, 5];
autocorr_xcorr = xcorr(x, ’coeff’);
autocorr_xcorr = autocorr_xcorr(length(x):end);
[autocorr_autocorr, lags] = autocorr(x);
subplot(2, 1, 1);
stem(lags, autocorr_xcorr);
xlabel(’Lag’);

5
ylabel(’Autocorrelation’);
title(’Autocorrelation using xcorr’);
subplot(2, 1, 2);
stem(lags, autocorr_autocorr);
xlabel(’Lag’);
ylabel(’Autocorrelation’);
title(’Autocorrelation using autocorr’);

4.3.2 Result

Figure 4: Autocorrelation

4.3.3 Analysis
The xcorr command calculates the cross-correlation of a sequence with itself, which effectively yields
the autocorrelation. It computes the cross-correlation of the sequence with its shifted versions.By de-
fault, xcorr returns both positive and negative lags of the autocorrelation function, providing a complete
view of the correlation between the sequence and its shifted versions.The output of xcorr is typically
a symmetric sequence centered around zero lag, where the center value represents the maximum cor-
relation (at zero lag), and the surrounding values indicate correlations at different time lags.The auto-
corr command is specifically designed for calculating autocorrelation. It computes the autocorrelation
function of a sequence without the need for specifying the lag range.Unlike xcorr, which returns both
positive and negative lags, autocorr typically returns only the positive lags of the autocorrelation func-
tion, focusing on the non-negative time shifts.The output of autocorr is a single-sided autocorrelation
function, representing correlations only for positive time lags.

6
4.3.4 Task 04
Generate a discrete sequence s(n) = u[n + 2] and discrete random noise d(n) and then add noise
to s(n), i.e., y(n) = s(n) + d(n). Plot the s(n), d(n), y(n), and autocorrelation of y(n).

4.3.5 Code
% Define the discrete sequence s(n) = u[n+2]
n = -10:20;
s = double(n >= -2);

% Generate discrete random noise d(n)


d = randn(size(n));

% Add noise to s(n) to obtain y(n)


y = s + d;

% Plot s(n), d(n), y(n), and autocorrelation of y(n) using subplot


figure;

subplot(4, 1, 1);
stem(n, s);
title(’s(n)’);
xlabel(’n’);
ylabel(’Amplitude’);

subplot(4, 1, 2);
stem(n, d);
title(’d(n)’);
xlabel(’n’);
ylabel(’Amplitude’);

subplot(4, 1, 3);
stem(n, y);
title(’y(n) = s(n) + d(n)’);
xlabel(’n’);
ylabel(’Amplitude’);

% Compute the autocorrelation of y(n) manually


autocorr_y = xcorr(y, ’coeff’);
lags = -(length(y)-1):(length(y)-1);

% Plot the autocorrelation of y(n)


subplot(4, 1, 4);
stem(lags, autocorr_y);
title(’Autocorrelation of y(n)’);
xlabel(’Lag (n)’);

7
ylabel(’Autocorrelation’);

4.3.6 Result

Figure 5: Output Sequence

4.3.7 Analysis
s(n) represents a unit step function delayed by 2 units. It starts with zeros until n = 1 and becomes
ones from n = 3 onwards. This sequence denotes the desired signal without any noise.d(n) represents
discrete random noise generated from a normal distribution. It introduces randomness to the signal.y(n)
is obtained by adding the random noise d(n) to the signal s(n). This operation simulates the effect of
noise on the original signal.The generated plots provide insights into the characteristics and behavior
of the signal y(n), which is a combination of an underlying deterministic component represented by
s(n) and a stochastic component represented by d(n).The presence of noise introduces variability and
fluctuations in the signal, affecting its overall structure and periodicity. The autocorrelation analysis
helps in understanding the temporal dependencies and repeating patterns within the signal, aiding in
signal processing tasks such as pattern recognition, filtering, and system identification.

8
5 Conclusion
In conclusion, this laboratory experiment provided valuable insights into fundamental concepts of sig-
nal processing and correlation analysis using MATLAB.Through practical tasks, we explored the gen-
eration of discrete sequences and the addition of noise to simulate real-world scenarios. We studied
the behavior of the signals, analyzed their properties, and examined the effects of noise on the original
signals.

You might also like