Power Spectral Density Calculation in Matlab

2 views (last 30 days)
clear all; close all;
L = 8000000;
PN_nf = -160; % dBc per Hz
PN_20dB = -140; % dBc per Hz at 1MHz
PN_30dB = -50; % dBc per Hz at 1MHz
f_offset = 1e6;
f_offset2 = 1e3;
F0 = 2.5e9;
sigma2 = (f_offset/F0)*sqrt(10^(PN_20dB/10)/F0);
acc = 0;
actual_timestamps_2 = zeros(1,L);
accumulative = zeros(1,L);
for i = 1:L,
acc = acc + sigma2*randn(1);
actual_timestamps_2(i) = i/F0 + acc;
accumulative(i) = acc;
end
fft1 = fft(2*pi*F0*accumulative);
fft1 = fft1(1:L/2+1);
psd1 = (1/(F0*L))*abs(fft1).^2;
psd1(2:end-1) = 2*psd1(2:end-1);
freq = 0:F0/length(accumulative):F0/2;
figure(1);
semilogx(freq,10*log10(psd1));
[psd1,w] = pwelch(2*pi*F0*accumulative,hamming(512),[],[],F0,'onesided');
figure(2);
semilogx(w,10*log10(psd1));
grid on
In this code, I am trying to find the power spectral density (PSD) of the signal "2*pi*F0*accumulative". In the first figure, I calculate the PSD using its definition i.e., taking fft squaring it and plotting he output. While in the second case I am using pwelch function.<br> While we see a constant 20dB/dec slope in the first case, the second case has two distinct slopes. Since the accumulative signal is just an accumulation of a random signal, it is expected to have a 20db/dec slope throughout (as in the first case). How can I plot the PSD using the pwelch function correctly, so that it does not show two distinct slopes in it. Figure 1 and 2 are shown below:
  1 Comment
Henry Giddens
Henry Giddens on 30 Sep 2017
Maybe try to remove the max and min values from 'psd1' for the second plot (including the corresponding 'w' values

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!