I have the following code block. Im just trying to calculate the periodogram of the signal $x$ with a built-in periodogram function and without any built-in periodogram function. I get the same pattern but the amplitudes are not equal. What am I missing there?
clear
close all
j = sqrt(-1);
n = 1:1:256;
noise_mean = 0;
noise_deviation = sqrt(5);
noise = noise_deviation.*randn(1,256) + noise_mean;
x = 20*exp(j*2*pi*(0.15)*n) + 30*exp(j*2*pi*(0.20)*n) + noise;
N = length(x); % N point FFT
for k = 1:N
Sx(k) = 0;
for n = 1:N
Sx(k) = Sx(k)+x(n)*exp(-1i*2*pi*(k-1)*(n-1)/N);
end
end
Sx = (1/N)*abs(Sx).^2;
figure
plot(10*log10(Sx)) , title('Periodogram without Built-in');
figure
plot(10*log10(periodogram(x))), title('Built-in Periodogram');