0% found this document useful (0 votes)
6 views

EXP 9 Linear System with Random Inputs in MATLAB

The document outlines an experiment to simulate and analyze the output of a linear time-invariant (LTI) system using MATLAB when excited by random inputs. It includes the aim, required software, theoretical background, procedure, and MATLAB code for generating random inputs, computing outputs, and analyzing statistical properties such as mean, variance, autocorrelation, and power spectral density. Additionally, it provides practice problems to reinforce the concepts learned.

Uploaded by

230801177
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

EXP 9 Linear System with Random Inputs in MATLAB

The document outlines an experiment to simulate and analyze the output of a linear time-invariant (LTI) system using MATLAB when excited by random inputs. It includes the aim, required software, theoretical background, procedure, and MATLAB code for generating random inputs, computing outputs, and analyzing statistical properties such as mean, variance, autocorrelation, and power spectral density. Additionally, it provides practice problems to reinforce the concepts learned.

Uploaded by

230801177
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

.

Exp. No. 9 Linear Systems with Random Inputs using MATLAB

AIM:
To simulate and analyze the output of a linear time-invariant (LTI) system when excited by a
random input using MATLAB, and compute key statistical properties such as mean, variance,
autocorrelation, and power spectral density.

APPARATUS / SOFTWARE REQUIRED:


 MATLAB (R2016 or later)
 Basic understanding of signals, systems, and probability

THEORY:
In communication systems, input signals are often random (like noise). Understanding how
linear systems respond to these inputs is crucial. If the system is LTI, the output can be analyzed
using:

 Impulse response ℎ(𝑡)


 Input 𝑥(𝑡): Random process (e.g., white noise, Gaussian)
 Output 𝑦(𝑡) = 𝑥(𝑡) ∗ ℎ(𝑡) (convolution)
Key tools:
 Mean and variance of output
 Autocorrelation: 𝑅𝑦 (𝜏)
 Power Spectral Density (PSD): via FFT or pwelch

PROCEDURE:
1. Define an impulse response ℎ(𝑡) (e.g., exponential or rectangular).
2. Generate a random input signal 𝑥(𝑡) (white Gaussian noise).
3. Compute the system output using convolution: y = conv(x, h, 'same')
4. Compute and plot:
o Mean and variance of input and output
o Autocorrelation of input and output
o Power Spectral Density using pwelch()
MATLAB CODE:
clc;
clear;

% 1. Define time axis


t = 0:0.01:10;

% 2. Generate random input signal (zero-mean white Gaussian noise)


x = randn(size(t)); % mean ≈ 0, std dev ≈ 1

% 3. Define LTI system impulse response (e.g., exponential decay)


h = exp(-t); % h(t) = e^{-t}, causal system

% 4. Compute output of system using convolution


y = conv(x, h, 'same') * 0.01; % scale by time step

% 5. Plot input and output


figure;
subplot(2,1,1);
plot(t, x); title('Random Input x(t)');
xlabel('Time'); ylabel('Amplitude'); grid on;

subplot(2,1,2);
plot(t, y); title('System Output y(t)');
xlabel('Time'); ylabel('Amplitude'); grid on;

% 6. Mean and Variance


mean_x = mean(x);
var_x = var(x);
mean_y = mean(y);
var_y = var(y);

fprintf('Input Mean: %.4f, Variance: %.4f\n', mean_x, var_x);


fprintf('Output Mean: %.4f, Variance: %.4f\n', mean_y, var_y);

% 7. Autocorrelation
[Rxx, lags_x] = xcorr(x, 'normalized');
[Ryy, lags_y] = xcorr(y, 'normalized');

figure;
subplot(2,1,1);
plot(lags_x, Rxx); title('Autocorrelation of Input x(t)'); grid on;
subplot(2,1,2);
plot(lags_y, Ryy); title('Autocorrelation of Output y(t)'); grid on;

% 8. Power Spectral Density using Welch's method


figure;
pwelch(x, [], [], [], 100); title('PSD of Input x(t)');
figure;
pwelch(y, [], [], [], 100); title('PSD of Output y(t)');

CONCLUSION:
 Linear systems filter random inputs and alter their spectral and statistical properties.
 MATLAB is effective in simulating and analyzing these changes using convolution,
autocorrelation, and spectral estimation.

To analyze the behavior of a linear time-invariant (LTI) system with random inputs using
MATLAB, and compute the system output, autocorrelation, and cross-correlation between input
and output.

� Theory:
In practical systems, input signals like thermal noise or communication signals are random in
nature. Understanding how LTI systems respond to such inputs is essential in signal processing
and communication engineering.

Key Concepts:
 LTI System: Defined by its impulse response ℎ(𝑡) or transfer function 𝐻(𝜔)
 Output: 𝑦(𝑡) = 𝑥(𝑡) ∗ ℎ(𝑡)
 Autocorrelation:
𝑅𝑥𝑥 (𝜏) = 𝐸[𝑥(𝑡) ⋅ 𝑥(𝑡 + 𝜏)]
𝑅𝑦𝑦 (𝜏) = 𝐸[𝑦(𝑡) ⋅ 𝑦(𝑡 + 𝜏)]
 Cross-correlation:
𝑅𝑥𝑦 (𝜏) = 𝐸[𝑥(𝑡) ⋅ 𝑦(𝑡 + 𝜏)]

⚙️ Procedure:
5. Define an LTI system with a known impulse response.
6. Generate a random input signal (e.g., Gaussian noise).
7. Compute the system output via convolution.
8. Calculate autocorrelation of input and output.
9. Compute cross-correlation between input and output.
10. Plot and analyze the behavior of all signals and correlations.
� MATLAB Code Example (Generalized Lab Code):
clc; clear;

% Time vector
Fs = 1000; % Sampling frequency
t = 0:1/Fs:1; % Time vector
N = length(t);

% Random input: zero-mean white Gaussian noise


x = randn(1, N);

% Impulse response of the system (LTI system)


h = exp(-5*t); % Example: low-pass filter response

% Output of the system


y = conv(x, h, 'same') / Fs;

% Autocorrelation of input and output


[Rxx, lags_x] = xcorr(x, 'biased');
[Ryy, lags_y] = xcorr(y, 'biased');

% Cross-correlation of input and output


[Rxy, lags_xy] = xcorr(x, y, 'biased');

% Plot signals
figure;
subplot(3,1,1); plot(t, x); title('Input Signal x(t)'); grid on;
subplot(3,1,2); plot(t, h); title('Impulse Response h(t)'); grid on;
subplot(3,1,3); plot(t, y); title('Output Signal y(t)'); grid on;

% Plot correlations
figure;
subplot(3,1,1);
plot(lags_x/Fs, Rxx); title('Autocorrelation of x(t)'); xlabel('\tau'); grid
on;

subplot(3,1,2);
plot(lags_y/Fs, Ryy); title('Autocorrelation of y(t)'); xlabel('\tau'); grid
on;

subplot(3,1,3);
plot(lags_xy/Fs, Rxy); title('Cross-correlation R_{xy}(\tau)');
xlabel('\tau'); grid on;
Practice Problems

Problem 1: Exponential System with White Noise Input


Analyze an LTI system with impulse response ℎ(𝑡) = 𝑒 −𝑡 , input 𝑥(𝑡) is white Gaussian noise.

MATLAB Code:
clc; clear;
t = 0:0.01:10;
x = randn(size(t)); % White Gaussian input
h = exp(-t); % Exponential system
y = conv(x, h, 'same') * 0.01;
figure; plot(t, y);
title('Output of System with h(t) = e^{-t} and White Noise Input');
xlabel('Time'); ylabel('Amplitude'); grid on;

Problem 2: Rectangular Pulse Response with Random Input


⚙️ Description:
System has a rectangular impulse response ℎ(𝑡) = 1 for 0 < 𝑡 < 1. Analyze output for uniform
random input.

⚙️ MATLAB Code:
clc; clear;
t = 0:0.01:10;
x = rand(size(t)); % Uniform random input
h = ones(1, 100); % Rectangular impulse response (length = 1 sec)
y = conv(x, h, 'same') * 0.01;
plot(t, y); title('Output with Rectangular Impulse Response');
xlabel('Time'); ylabel('Amplitude'); grid on;

Problem 3: System with Oscillatory Impulse Response


Description:
Use an oscillatory impulse response ℎ(𝑡) = sin(2𝜋𝑡)𝑒 −0.5𝑡 . Input: white Gaussian noise.

MATLAB Code:
clc; clear;
t = 0:0.01:10;
x = randn(size(t));
h = sin(2*pi*t).*exp(-0.5*t); % Damped sinusoidal system
y = conv(x, h, 'same') * 0.01;
plot(t, y); title('Output with Damped Sinusoidal System');
xlabel('Time'); ylabel('Amplitude'); grid on;

Problem 4: Compare the autocorrelation of the input and


output of a system to understand how system dynamics affect
signal properties.
Description:
Show how autocorrelation changes after random signal passes through a low-pass system.

MATLAB Code:
clc; clear;
t = 0:0.01:10;
x = randn(size(t)); % Random input
h = exp(-t); % Exponential impulse response
y = conv(x, h, 'same') * 0.01;

% Compute autocorrelations using xcorr()


[Rx, lags_x] = xcorr(x, 'normalized');
[Ry, lags_y] = xcorr(y, 'normalized');

% Plot input autocorrelation


figure;
subplot(2,1,1);
plot(lags_x, Rx, 'LineWidth', 1.5);
title('Autocorrelation of Input Signal');
xlabel('Lag'); ylabel('R_{xx}(\tau)');
grid on;

% Plot output autocorrelation


subplot(2,1,2);
plot(lags_y, Ry, 'LineWidth', 1.5);
title('Autocorrelation of Output Signal');
xlabel('Lag'); ylabel('R_{yy}(\tau)');
grid on;

Problem 5: Compute and Plot Power Spectral Density


Description:
Find PSD of input/output when white noise is passed through exponential system.

MATLAB Code:
clc; clear;
t = 0:0.01:10;
x = randn(size(t));
h = exp(-t);
y = conv(x, h, 'same') * 0.01;

figure;
subplot(2,1,1);
pwelch(x, [], [], [], 100); title('PSD of Input');

subplot(2,1,2);
pwelch(y, [], [], [], 100); title('PSD of Output');

You might also like