Difference Between Built-in Periodogram and Self-Calculated Periodogram

13 次查看(过去 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 个评论
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 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by