Difference Between Built-in Periodogram and Self-Calculated Periodogram
    6 views (last 30 days)
  
       Show older comments
    
    tinkyminky93
 on 24 Dec 2022
  
    
    
    
    
    Commented: Sulaymon Eshkabilov
      
 on 24 Dec 2022
            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 Comments
Accepted Answer
  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
  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.
More Answers (0)
See Also
Categories
				Find more on Bartlett in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

