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

EXP 10-Analysis of Power Spectral Density

The lab manual outlines procedures for analyzing Power Spectral Density (PSD) of various signals using MATLAB, including methods like the periodogram and Welch's method. It provides MATLAB code examples for computing PSD for white Gaussian noise, sinusoidal signals, and filtered signals, among others. The manual concludes with results demonstrating successful PSD computation and visualization of different signals.

Uploaded by

230801177
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)
5 views9 pages

EXP 10-Analysis of Power Spectral Density

The lab manual outlines procedures for analyzing Power Spectral Density (PSD) of various signals using MATLAB, including methods like the periodogram and Welch's method. It provides MATLAB code examples for computing PSD for white Gaussian noise, sinusoidal signals, and filtered signals, among others. The manual concludes with results demonstrating successful PSD computation and visualization of different signals.

Uploaded by

230801177
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

LAB MANUAL

Analysis of Power Spectral Density using MATLAB

AIM:
To compute and analyze the Power Spectral Density (PSD) of random and deterministic signals
using MATLAB and visualize the frequency-domain characteristics using the Signal Processing
Toolbox.

APPARATUS / SOFTWARE REQUIRED:


MATLAB with Signal Processing Toolbox

THEORY:
The Power Spectral Density (PSD) shows how the power of a signal or time series is
distributed with frequency. It is useful in analyzing noise, filters, and communication signals.

Common methods:
1
Periodogram: 𝑃(𝑓) = 𝑁 ∣ 𝑋(𝑓) ∣2
Welch’s method: Averaged periodograms with windowing for smoother estimate
MATLAB Tools:
pwelch – Welch's method
periodogram – Basic FFT-based method
psd – (older function)
fft – Manual calculation of PSD

PROCEDURE:
1. Define or generate a time-domain signal (random or deterministic).
2. Use pwelch() or periodogram() to compute PSD.
3. Plot and analyze peak frequencies and bandwidth.
4. Compare different signals or system responses.
LAB MANUAL
PROBLEMS WITH MATLAB CODE

Problem 1: PSD of White Gaussian Noise


clc; clear;
Fs = 1000; % Sampling frequency
t = 0:1/Fs:1-1/Fs;
x = randn(size(t)); % White Gaussian noise

% Compute PSD using Welch's method


figure;
pwelch(x,[],[],[],Fs);
title('PSD of White Gaussian Noise');

Problem 2: PSD of Sinusoidal Signal


clc; clear;
Fs = 1000;
t = 0:1/Fs:1-1/Fs;
f0 = 50;
x = sin(2*pi*f0*t);

% Compute PSD
figure;
pwelch(x,[],[],[],Fs);
title('PSD of Sinusoidal Signal at 50 Hz');

Problem 3: Compare PSD of Sine and Square Waves


clc; clear;
Fs = 1000;
t = 0:1/Fs:1-1/Fs;
f0 = 20;
x1 = sin(2*pi*f0*t);
x2 = square(2*pi*f0*t);

figure;
subplot(2,1,1); pwelch(x1,[],[],[],Fs); title('PSD of Sine Wave');
subplot(2,1,2); pwelch(x2,[],[],[],Fs); title('PSD of Square Wave');
LAB MANUAL
Problem 4: PSD of Filtered White Noise
clc; clear;
Fs = 1000;
t = 0:1/Fs:2;
x = randn(size(t)); % White noise input

[b,a] = butter(4, 0.2); % 4th-order Butterworth low-pass filter


y = filter(b, a, x); % Filtered signal

figure;
pwelch(y,[],[],[],Fs);
title('PSD of Filtered White Noise (Low-pass)');

Problem 5: Manual PSD using FFT


clc; clear;
Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = sin(2*pi*100*t) + 0.5*randn(size(t)); % Sine + noise

N = length(x);
X = fft(x);
Pxx = (1/(Fs*N)) * abs(X).^2; % Power spectrum
f = (0:N-1)*(Fs/N);

figure;
plot(f, 10*log10(Pxx));
xlim([0 Fs/2]);
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
title('Manual PSD using FFT');
grid on;
LAB MANUAL

Power Spectral Density Analysis of Filtered Signals Using FIR Design


s = 1000; % Sampling frequency (Hz)
t = 0:1/Fs:1; % Time vector
x = sin(2*pi*50*t) + 0.5*randn(size(t)); % Signal with noise
[Pxx, f] = pwelch(x, [], [], [], Fs); % Compute PSD
figure;
plot(f, 10*log10(Pxx)); % Plot in dB scale
title('Power Spectral Density');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
fc = 100; % Cutoff frequency (Hz)
Wn = fc/(Fs/2); % Normalized cutoff frequency
filterOrder = 10; % Filter order
b = fir1(filterOrder, Wn, 'low'); % Low-pass FIR filter design
x_filtered = filter(b, 1, x); % Apply filter
[Pxx_filtered, f] = pwelch(x_filtered, [], [], [], Fs); % Compute PSD of filtered
signal
figure;
plot(f, 10*log10(Pxx), 'b', f, 10*log10(Pxx_filtered), 'r');
title('Comparison of Original and Filtered Power Spectral Density');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
legend('Original', 'Filtered');

Out put

RESULT:
The PSD of different signals was successfully computed and interpreted using MATLAB
functions like pwelch, periodogram, and FFT.
LAB MANUAL
Problem 6
A variety of toolbox functions generate waveforms. Most require you to begin
with a vector representing a time base. Consider generating data with a 1000
Hz sample frequency, for example. An appropriate time vector is t = (0:0.001:1)'
Matlab code
t = (0:0.001:1)';
y = sin(2*pi*50*t) + 2*sin(2*pi*120*t);
randn('state',0);
yn =y +0.5*randn(size(t));
plot(t(1:50),yn(1:50))

Output

Problem 7
To generate 1.5 seconds of a 50 Hz sawtooth wave with a sample rate of 10 kHz
and plot 0.2 seconds of the generated waveform, use
Matlab code
fs = 10000;
t = 0:1/fs:1.5;
x = sawtooth(2*pi*50*t);
plot(t,x), axis([0 0.2 -1 1])
LAB MANUAL

Output

Problem 8

Aperiodic Waveforms
To compute 2 seconds of a linear chirp signal with a sample rate of 1 kHz, that starts
at DC and crosses 150 Hz at 1 second, use

t = 0:1/1000:2;
y = chirp(t,0,1,150);
specgram(y,256,1000,256,250)

Output
LAB MANUAL

Problem 9

The pulstran Function

T = 0:1/50E3:10E-3;
D = [0:1/1E3:10E-3;0.8.^(0:10)]';
Y = pulstran(T,D,'gauspuls',10E3,0.5);
plot(T,Y)

Output
LAB MANUAL

Problem 10 Visualization of Dirichlet Functions for Odd and Even Harmonics Using MATLAB

The Dirichlet Function

Matlab code
clc; clear;

% Define time vector


x = linspace(0, 4*pi, 300);
LAB MANUAL
% Dirichlet functions
y7 = diric(x, 7); % N = 7
y8 = diric(x, 8); % N = 8

% Plotting Dirichlet functions


figure;

subplot(2,1,1);
plot(x, y7, 'r', 'LineWidth', 1.5);
title('Dirichlet Function, N = 7');
xlabel('x'); ylabel('diric(x,7)');
grid on;

subplot(2,1,2);
plot(x, y8, 'g', 'LineWidth', 1.5);
title('Dirichlet Function, N = 8');
xlabel('x'); ylabel('diric(x,8)');
grid on;

Output

You might also like