Difference Between Built-in Periodogram and Self-Calculated Periodogram

조회 수: 5 (최근 30일)
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');

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022년 12월 24일
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
tinkyminky93
tinkyminky93 2022년 12월 24일
편집: tinkyminky93 2022년 12월 24일
Can you explain the syntax sir? What does [], N, 1 corresponds to?
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022년 12월 24일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Bartlett에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by