You are on page 1of 21

NATIONAL INSTITUTE OF TECHNOLOGY CALICUT

Department of Electronics and Communication Engineering

Monsoon 2024

EC6405E Statistical Signal Processing

Assignment - 3

SUBMITTED BY
SYAMANTAK SARKAR (M230922EC)
M.Tech – Signal Processing
a) Periodogram
Code:
%%%%%%%%%%% Periodogram Estimate %%%%%%%%%%%%%

% Define parameters
N = 1000; % Number of samples
fs = 1000; % Sampling frequency
t = (0:N-1) / fs; % Time axis
% Frequencies
f1 = 50; % Frequency of the first sinusoid
f2 = 75; % Frequency of the second sinusoid
v1 = 0.5;
v2 = 0.5;
% Generate random phases uniformly distributed between 0 and 2*pi
phi1 = rand() * 2 * pi;
phi2 = rand() * 2 * pi;
x = v1*sin(2 * pi * f1 * t + phi1) + v2*sin(2 * pi * f2 * t + phi2);
% Add Gaussian white noise with variance 0.25
variance = 0.5;
noise = sqrt(variance) * randn(1, N);
x_noisy = x + noise;
% Apply a Bartlett window
window = hamming(N);
x_windowed = x_noisy .* window';
% Compute the DTFT of the windowed signal
dtft_freq = linspace(0, fs, N); % Frequency axis for DTFT
X_dtft = zeros(size(dtft_freq));
for i = 1:length(dtft_freq)
X_dtft(i) = sum(x_windowed .* exp(-1j * 2 * pi * dtft_freq(i) * t));
end
% Compute the magnitude of the DTFT
PSD1 = abs(X_dtft).^2 / N;
% Plot the periodogram estimate
plot(dtft_freq, PSD1);
xlabel('Frequency [Hz]');
ylabel('Power/Frequency');
title('Periodogram Estimate of PSD with Noise and Random Phases');
grid on;

Results:

b) Bartlett Estimate
Code:
%%%%%%%%% Bartlett PSD Estimate %%%%%%%%%%
% Define parameters
N = 1000; % Number of samples
fs = 1000; % Sampling frequency
t = (0:N-1) / fs; % Time axis
% Frequencies
f1 = 50; % Frequency of the first sinusoid
f2 = 75; % Frequency of the second sinusoid
v1 = 0.5;
v2 = 0.5;
% Generate random phases uniformly distributed between 0 and 2*pi
phi1 = rand() * 2 * pi;
phi2 = rand() * 2 * pi;
x = v1*sin(2 * pi * f1 * t + phi1) + v2*sin(2 * pi * f2 * t + phi2);
% Add Gaussian white noise with variance 0.25
variance = 0.5;
noise = sqrt(variance) * randn(1, N);
x_noisy = x + noise;
% Define window size
window_size = 100;
% Calculate number of segments
num_segments = floor(N / (window_size / 2)) - 1;
% Initialize array to store periodograms
periodograms = zeros(num_segments, window_size);
% Compute Bartlett PSD for each segment
for i = 1:num_segments
start_idx = (i - 1) * (window_size / 2) + 1;
end_idx = start_idx + window_size - 1;
segment = x_noisy(start_idx:end_idx);
window = bartlett(window_size);
segment_windowed = segment .* window';
X = fft(segment_windowed);
periodogram = (1 / window_size) * abs(X).^2;
periodograms(i, :) = periodogram;
end
% Average the periodograms
average_periodogram = mean(periodograms, 1);
% Compute the frequency axis
freq_axis = linspace(0, fs, window_size);
% Plot the Bartlett PSD estimate
plot(freq_axis, average_periodogram);
xlabel('Frequency [Hz]');
ylabel('Power/Frequency');
title('Bartlett PSD Estimate with Window Size 100 Samples');
grid on;

Results:
c) Weltch Estimate
Code:
%%%%%%%% Weltch PSD Estimate with 50% overlap %%%%%%%%%%%%%%
% Define parameters
N = 1000; % Number of samples
fs = 1000; % Sampling frequency
t = (0:N-1) / fs; % Time axis
% Frequencies
f1 = 50; % Frequency of the first sinusoid
f2 = 75; % Frequency of the second sinusoid
v1 = 0.5;
v2 = 0.5;
% Generate random phases uniformly distributed between 0 and 2*pi
phi1 = rand() * 2 * pi;
phi2 = rand() * 2 * pi;
x = v1*sin(2 * pi * f1 * t + phi1) + v2*sin(2 * pi * f2 * t + phi2);
% Add Gaussian white noise with variance 0.25
variance = 0.5;
noise = sqrt(variance) * randn(1, N);
x_noisy = x + noise;
% Define segment size and overlap
segment_size = 100;
overlap = segment_size / 2;
% Calculate number of segments
num_segments = floor((N - overlap) / (segment_size - overlap));
% Initialize array to store periodograms
periodograms = zeros(num_segments, segment_size);
% Compute Welch PSD for each segment
for i = 1:num_segments
start_idx = (i - 1) * (segment_size - overlap) + 1;
end_idx = start_idx + segment_size - 1;
segment = x_noisy(start_idx:end_idx);
window = hamming(segment_size);
segment_windowed = segment .* window';
X = fft(segment_windowed);
periodogram = (1 / segment_size) * abs(X).^2;
periodograms(i, :) = periodogram;
end
% Average the periodograms
average_periodogram = mean(periodograms, 1);
% Compute the frequency axis
freq_axis = linspace(0, fs, segment_size);
% Plot the Welch PSD estimate
plot(freq_axis, average_periodogram);
xlabel('Frequency [Hz]');
ylabel('Power/Frequency');
title('Welch PSD Estimate with 50% Overlap');
grid on;
Results:

d) BT Estimate
Code:
%%%%% BT PSD Estimate %%%%%%%%%%
% Define parameters
N = 1000; % Number of samples
fs = 1000; % Sampling frequency
t = (0:N-1) / fs; % Time axis
% Frequencies
f1 = 50; % Frequency of the first sinusoid
f2 = 75; % Frequency of the second sinusoid
v1 = 0.5;
v2 = 0.5;
% Generate random phases uniformly distributed between 0 and 2*pi
phi1 = rand() * 2 * pi;
phi2 = rand() * 2 * pi;
x = v1*sin(2 * pi * f1 * t + phi1) + v2*sin(2 * pi * f2 * t + phi2);
% Add Gaussian white noise with variance 0.25
variance = 0.5;
noise = sqrt(variance) * randn(1, N);
x_noisy = x + noise;
L = 100;
% Compute biased autocorrelation function
autocorr = zeros(1, N);
for k = 1:N
for n = 1:N - k
autocorr(k) = autocorr(k) + x_noisy(n) * x_noisy(n + k);
end
% Normalize the biased autocorrelation function
autocorr(k) = autocorr(k) / N;
end
% Construct the autocorrelation matrix
Rx = toeplitz(autocorr);
Rx = Rx(1:L, 1:L);
w = linspace(0, 2*pi, N);
Px = zeros(size(w));
% Compute eigenvalues and eigenvectors
[eigen_vectors, eigen_values] = eig(Rx);
eigen_values = diag(eigen_values);
% Compute PSD using BT
for i = 1:L
eigenvector_i = eigen_vectors(:, i);
DFT_eigenvector_i = fft(eigenvector_i, N);
Px = Px + eigen_values(i) * abs(DFT_eigenvector_i).^2;
end
% Plot PSD
plot(w*fs/(2*pi), abs(Px), 'b');
xlabel('Frequency [rad/sample]');
ylabel('Power/Frequency');
title('PSD by Blackman-Tukey');
grid on;

Results:
e) MVM Estimate
Code:
%%%%%%%%%%% MVM PSD Estimate %%%%%%%%%%%

% Define parameters
N = 1000; % Number of samples
fs = 1000; % Sampling frequency
t = (0:N-1) / fs; % Time axis
% Frequencies
f1 = 50; % Frequency of the first sinusoid
f2 = 75; % Frequency of the second sinusoid
v1 = 0.5;
v2 = 0.5;
% Generate random phases uniformly distributed between 0 and 2*pi
phi1 = rand() * 2 * pi;
phi2 = rand() * 2 * pi;
x = v1*sin(2 * pi * f1 * t + phi1) + v2*sin(2 * pi * f2 * t + phi2);
% Add Gaussian white noise with variance 0.25
variance = 0.5;
noise = sqrt(variance) * randn(1, N);
x_noisy = x + noise;
L = 100;
% Compute biased autocorrelation function
autocorr = zeros(1, N);
for k = 1:N
for n = 1:N - k
autocorr(k) = autocorr(k) + x_noisy(n) * x_noisy(n + k);
end
% Normalize the biased autocorrelation function
autocorr(k) = autocorr(k) / N;
end
% Construct the autocorrelation matrix
Rx = toeplitz(autocorr);
Rx = Rx(1:L, 1:L);
% Compute eigenvalues and eigenvectors
[eigen_vectors, eigen_values] = eig(Rx);
eigen_values = diag(eigen_values);
% Arrange eigenvalues in ascending order
[~, sorted_indices] = sort(eigen_values);
sorted_eigen_values = eigen_values(sorted_indices);
sorted_eigen_vectors = eigen_vectors(:, sorted_indices);
% Compute vector e
w = linspace(0, 2*pi, N);
e = exp(1j * (0:L-1)' * w);
% Compute PSD using MVM
Px = zeros(size(w));
for i = 1:4
eigenvector_i = sorted_eigen_vectors(:, i);
DFT_eigenvector_i = fft(eigenvector_i, N);
Px = Px + (1 / sorted_eigen_values(i)) * abs(DFT_eigenvector_i).^2;
end
% Plot PSD
plot(w*fs/(2*pi), L*abs(Px), 'b');
xlabel('Frequency [Hz]');
ylabel('Power/Frequency');
title('PSD by MVM');
grid on;

Results:

Inference:

• The periodogram estimate has the highest resolution, but also the highest variance. It shows the
peaks of the two sinusoids clearly, but also has a lot of fluctuations due to noise.

• The Bartlett estimate has lower resolution, but also lower variance. It smooths out some of the
noise, but also reduces the peak heights and widens the peak widths of the sinusoids.

• The Welch estimate has the lowest resolution, but also the lowest variance. It further smooths
out the noise, but also further reduces and broadens the peaks of the sinusoids.

• The resolution and variance of the estimates depend on the choice of the window width and the
overlap. A larger window width or a smaller overlap will increase the resolution, but also
increase the variance. A smaller window width or a larger overlap will decrease the resolution,
but also decrease the variance.

• Resolution for these estimates are much higher.

• Among these two estimates MVM estimate is the best estimation of PSD.
b) Varying relative strength of frequency components (V1 and V2)

i) V1 = 10 , V2 = 5
Periodgram

Bartlett
Weltch

BT Estimate
MVM Estimate

ii) V1 = 1 , V2 = 2

Periodgram
Bartlett

Weltch
BT Estimate

MVM Estimate
Inference:
• As difference between the signal strength is much higher we can observe that the signal with
higher strength can suppress the signal with lower strength.
• This observation is seviour in case of Perideogram, Bertlet and Weltch estimates as they are
parameric in nature.
• MVM and BT estimates this is not that much evident.
• MVM is the best estimate among the others. It has lowest varience and highest resolution.

c) Varying Strength of noise

i) Varience = 0.25

Periodgram
Bartlett

Weltch
BT estimate

MVM estimate
ii) Varience = 0.7

Periodgram

Bartlett
Weltch

BT estimate
MVM estimate

Inference:
• As noise power is increased we can see that MVM estimate is better that other estimates. The
reason is it is a estimator of noise subspace.
• The resolution is maximum for Periodogram.
• The resolution decreses in case of Bertlet and Weltch Estimates. The Varience also decreases
respectively.
• MVM and Bertlet estimates have higher resolution than Bertlet and Weltch estimate.
• Resulution of MVM is better than BT estimate .
• Varience is minimum in case of MVM estimate.

You might also like