EXP 9 Linear System with Random Inputs in MATLAB
EXP 9 Linear System with Random Inputs in 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.
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:
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;
subplot(2,1,2);
plot(t, y); title('System Output y(t)');
xlabel('Time'); ylabel('Amplitude'); grid on;
% 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;
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);
% 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
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;
⚙️ 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;
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;
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;
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');