Difference Between Built-in Periodogram and Self-Calculated Periodogram

5 views (last 30 days)
Hello,
I have the following code block. Im just trying to calculate the periodogram of the signal 'x' with built-in periodogram function and without built-in periodogram function. I got the same pattern but the amplitudes are not equal. What am I missing there? Thank you for your help.
clc
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');

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 24 Dec 2022
The only thing that you are missing that you ahve not specified FFT window size when you've employed MATLAB's builtin fcn:
clc
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, [], N, 1))), title('Built-in Periodogram'); % FFT Window size is specified
figure
plot(10*log10(Sx), 'b-', 'linewidth', 2.5, 'DisplayName', 'Manual Calc') , hold on
plot(10*log10(periodogram(x,[], N, 1)), 'DisplayName', 'Built-in Periodigram'), title('Built-in Periodogram vs. Manual Calc');
legend('toggle'), grid on
  2 Comments
tinkyminky93
tinkyminky93 on 24 Dec 2022
Edited: tinkyminky93 on 24 Dec 2022
Can you explain the syntax sir? What does [], N, 1 corresponds to?
Sulaymon Eshkabilov
Sulaymon Eshkabilov on 24 Dec 2022
It is quite straightforward. N is Discrete Fourier Transform window size (also called resolution), which you set equal to the length of your generated signal (N = length(x)), and 1 corresponds to the sampling frequency. In your example, Fs is 1, becuase n = 1:1:256. [] is coming from the syntax of periodigram() fcn becuase of the other chosen parameters.

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!