% signal fs = 1000; t = 0:1/fs:1-1/fs; x = cos(2*pi*100*t) + randn(size(t)); %PSD calculation N = length(x); xdft = fft(x); xdft = xdft(1:N/2+1); psdx = (1/(fs*N)) * abs(xdft).^2; %deviding power spectrum by frequency resolution psdx(2:end-1) = 2*psdx(2:end-1); %to preserve total power in plot (from neg freq) so multiply by 2 %Zero frequency (DC) and the Nyquist frequency do not occur twice freq = 0:fs/length(x):fs/2; %plot plot(freq,pow2db(psdx)) grid on title("Periodogram Using FFT") xlabel("Frequency (Hz)") ylabel("Power/Frequency (dB/Hz)")periodogram(x)N = length(x); xdft = fft(x); psdx = (1/(2*pi*N)) * abs(xdft).^2; freq = 0:(2*pi)/N:2*pi-(2*pi)/N; plot(freq/pi,10*log10(psdx)) grid on title('Periodogram Using FFT') xlabel('Normalized Frequency (\times\pi rad/sample)') ylabel('Power/Frequency (dB/rad/sample)')