# Difference Between Built-in Periodogram and Self-Calculated Periodogram

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');


Because by default Matlab scales the periodogram by $$1/f_s$$ to get the Power Spectral Density, $$f_s$$ being the sampling frequency.
If $$f_s$$ is not supplied in the call to periodogram, it uses the normalized frequency $$2\pi$$ to scale the squared magnitude: $$\frac{1}{2\pi}|X[k]|^2$$
Sx = 1/(2*pi*N)*abs(Sx).^2;

• @dorottopunto93 Check again, on my end I get the same exact result for Sx and periodogram(x). I am using your code.