Question 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

% Parameters

N = 1000; % Number of samples


M = 10000; % Number of MC simulations
sigma = 1; % Variance of random process v[k]

% Initialize arrays to store results


real_parts_an = zeros(M, N);
imaginary_parts_bn = zeros(M, N);

% Perform MC simulations
for m = 1:M
% Generate a random sample of v[k] (assumed to be zero-mean)
v = sigma * randn(1, N);

% Compute DFT coefficients


F = fft(v);

% Extract real and imaginary parts of F


real_parts_an(m, :) = real(F);
imaginary_parts_bn(m, :) = imag(F);
end

% Plot histograms of real and imaginary parts of a_n and b_n


figure;
subplot(1, 2, 1);
histogram(real_parts_an(:), 100, 'Normalization', 'pdf');
title('Histogram of Real Parts of a_n');
subplot(1, 2, 2);
histogram(imaginary_parts_bn(:), 100, 'Normalization', 'pdf');
title('Histogram of Imaginary Parts of b_n');

1
% subplot(2, 2, 3);
% qqplot(real_parts_an(:));
% title('QQ Plot of Real Parts of a_n');
% subplot(2, 2, 4);
% qqplot(imaginary_parts_bn(:));
% title('QQ Plot of Imaginary Parts of b_n');

We can see that the DFT coefficients follow Gaussian distributions in MC simuations

% Parameters
M = 10000; % Number of realizations
N_values = [100, 200, 500, 1000, 10000]; % Different values of N

% Initialize arrays to store mean and variance


mean_Pfn = zeros(length(N_values), 1);
variance_Pfn = zeros(length(N_values), 1);

for i = 1:length(N_values)
N = N_values(i);
Pfn_realizations = zeros(M, N); % Store P[f_n] for each realization

for m = 1:M
% Generate a realization of the Gaussian process v[k]
vk = sigma * randn(1, N);

2
% Compute DFT coefficients and estimate PSD
V = fft(vk);
Pfn = abs(V).^2 / N;
Pfn_realizations(m, :) = Pfn;
end

% Compute mean and variance of P[f_n]


mean_Pfn(i) = mean(Pfn_realizations(:));
variance_Pfn(i) = var(Pfn_realizations(:));
end

% Plot mean and variance as functions of N


figure;
subplot(2, 1, 1);
plot(N_values, mean_Pfn);
xlabel('N');
ylabel('Mean of P[f_n]');
title('Mean of Estimated PSD vs. N');
subplot(2, 1, 2);
plot(N_values, variance_Pfn);
xlabel('N');
ylabel('Variance of P[f_n]');
title('Variance of Estimated PSD vs. N');

3
Mean and variance don't go to zero but remains constant after large values of N , thus showing its not a
consistent estimator

You might also like