White noise periodogram coming out lower than I expected

13 views (last 30 days)
I am comparing MATLAB's periodogram.m with my own code for periodogram PSD estimation. I've created 50 realizations of a purely white noise signal with a length of N=512. I take the periodogram of each (rectangular window), average the periodograms together, then plot the average. The results are nearly identical, except with my own code I get a flat line right around 0, but when I use periodogram.m, I get a flat line at -5. Shouldn't it be at 0? What am I missing here?
The following is the code I use:
% Calculate PSD of 50 Realizations and plot the average PSD Estimate.
% Signal Length 512
% MY CODE
clear
rng default % Default random numbers
n_len = 512; % Size of the signal
T = 1/(2*n_len-1);
df = 0:2*T:1; % Normalized Frequency Vector
% Generate 50 realizations of the signal
nt = randn(50,n_len);
for zz = 1:50
% Perform Autocorrelation
for kk = 1:n_len
for nn = 1:n_len
if nn+kk-1 > n_len
yy(nn) = 0;
else
yy(nn) = nt(zz,nn+kk-1)*conj(nt(zz,nn));
end
end
r(kk) = (1/(n_len))*sum(yy);
end
% Flip r and combine with original
r = [flipdim(r,2) r(2:end)];
% FFT of autocorrelation
R(zz,:) = fftshift(abs(fft(r)));
clear r yy kk zz
end
% Calculate Ensemble Average
for zz = n_len:size(R,2)
avR(zz) = mean(R(:,zz));
end
% MATLAB'S periodogram.m
for zz = 1:50
X = nt(zz,:);
[pxx(zz,:)] = periodogram(X,[],1024);
end
% Ensemble Average
for zz = 1:size(pxx,2)
avpxx(zz) = mean(pxx(:,zz));
end
% Plot for Comparison
figure(1);
plot(df,10*log10(avR(n_len:end)), df, 10*log10(avpxx(1:end-1)))
axis([0 1 -20, 10])

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!