MATLAB: SYNTAX – obtain [pxx ,f] vectors from periodogram(_ fs); <— Errors in user's current usage

audio processingfigureMATLABnfftperiodogrampsdSignal Processing Toolboxsignalssyntaxwindow

QUESTION: How do I correctly use [pxx, f] = periodogram(y_soundsource_data,window,nfft, Fs);
I need the pxx and f vectors to be able to index to find maxima.
For context … trying to get the PSD local maxima, for 3 specific frequency ranges. I want both the x-frequency values and the PSD-y values.
I sent an email to someone, and he said to use the [pxx, f]= periodogram(_ Fs) version of the periodogram call.
Where pxx= the PSD y value vector and f= the x values which correspond to the frequency values that match 1:1 to the pxx points
Matlab Documentation Says:
matlabPeriodogram.JPG
Undesired Behavior:
  • When I do use [pxx, f] = periodogram(y_soundsource_data,window, nfft, Fs); a window maker pops up and it doesn't automatically plot or
calculate anything.
  • Tried function call–> [pxx, f]=periodogram([],Fs); which should give the PSD-estimate with default values, but then, it caused an error.
Code
%% audioread .wav file
[y Fs]= audioread('100-daddy1.wav');
%% y=source signal
sourceFig=figure(1);
plot(y);
xlabel('milliseconds'); ylabel('amplitude'); title('spectrogram = voice source signal');
%% PSD - Power Spectral Density <-- peaks here should give formants
filterfcn=figure(2);
PSD=periodogram(y); %calculate the power spectral density of the source signal
plot(PSD);
ylabel('magnitude || intensity of signal'); xlabel('frequency in Hz'); title('PSD of Source');
xlim([0, .35*10^4]);
%% PSD with modified window <--- window is the same length as x
PSD_mod_window= periodogram(y, window);
figure(4);
plot(PSD_mod_window); % don't understand why a window pops up or how to use it. Thought window, was supposed to be a vector of length x?
%% [pxx,f] = periodogram(_,fs)
%fs is the fourth input to periodogram
% to use default values, do [], for preceding args
[pxx4, f]= periodogram( [], Fs);
disp(sizeof(pxx4));
disp(sizeof(f));
How do I correctly use [pxx, f] = periodogram(y_soundsource_data,window,nfft, Fs); ?
I need the pxx and f vectors to be able to index to find maxima.

Best Answer

The reason window plotter came up, was because you used the window gate way function as an input argument to the call: [pxx, f] = periodogram(y_soundsource_data,window, nfft, Fs).
Deconstructing the [pxx, f]= periodogram(y_soundsource_data, window, nfft, Fs);
  1. You can get y_soundsource_data and Fs<-- sampling frequency, from the audioread function. file[y Fs]= audioread('100-daddy1.wav');
  2. window and nfft are not understood by the periodogram function UNLESS you define them.
  • y_soundsource_data and Fs are understood, because audioread returns the data metrics.
  • nfft - refers to the number of points used in the DFT. A larger nfft value will lead to a better estimation. nfft MUST be an integer. You can't have half a point.
  • window = vector of the size of the y_soundsource_data. 1:length_y_soundsource_data
  • both window and nfft need to be defined before you call the periodogram function.