Difference Between Built-in Periodogram and Self-Calculated Periodogram
9 次查看(过去 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');
0 个评论
采纳的回答
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
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 Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!