How to fix pmtm function error messages for PSD calculation for a given frequency range
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
R Sak
il 24 Mar 2024
Risposto: Sudarsanan A K
il 25 Mar 2024
Following the MATLAB tutorial on pmtm, I ran the following code to estimate PSD of delta waves on an eeg signal, where fs is 256 and f is a vector from 0Hz to 4Hz
pmtm(smoothdata,[0 4],256)
However I get the following error message
Error using pmtm>getOptions
Number of columns of E and length of V do not match.
Error in pmtm>parsepmtmOptions (line 436)
params = getOptions(x,taperType,dropLast,confLevel,varargin{:});
Error in pmtm (line 166)
params = parsepmtmOptions(x,varargin{:});
The code runs well for all other options, but whenever I add the f variable, I get an error message.
Here is another trial I tried to run while specifying tapers.
pmtm(smoothdata,10,length(smoothdata),'Tapers','sine',[0 4],256)
and this is the error message i get,
considering the MATLAB instruction specifies that the last argument should be Fs, I don't see where I went wrong.
Error using pmtm
Expected FS to be a scalar.
Error in pmtm>getOptions (line 668)
validateattributes(varargin{i},{'numeric'},{'scalar',...
Error in pmtm>parsepmtmOptions (line 436)
params = getOptions(x,taperType,dropLast,confLevel,varargin{:});
Error in pmtm (line 166)
params = parsepmtmOptions(x,varargin{:});
0 Commenti
Risposta accettata
Sudarsanan A K
il 25 Mar 2024
Hello R Sak,
It looks like there was a misunderstanding regarding the use of the 'freqrange' argument in the 'pmtm' function. The 'freqrange' parameter you are referring to specifies the type of the Power Spectral Density (PSD) estimate returned ('onesided', 'twosided', or 'centered'), rather than allowing you to directly specify a numeric frequency range (e.g., Hz) for the analysis.
Given this clarification, here's how you can use the 'freqrange' argument correctly with the 'pmtm' function:
% Your pre-processed EEG signal is in 'smoothdata'
Fs = 256; % Sampling frequency
NW = 2.5; % Time-halfbandwidth product, adjust as needed
% Estimate PSD with 'onesided', 'twosided', or 'centered' spectrum
[Pxx, F] = pmtm(smoothdata, NW, [], Fs, 'onesided'); % Example for 'onesided'
% If you need to analyze a specific frequency range, e.g., 0-4 Hz, after estimation:
idx = F >= 0 & F <= 4;
Pxx_range = Pxx(idx);
F_range = F(idx);
% 'Pxx_range' and 'F_range' contain the PSD values and frequencies for 0-4 Hz, respectively
Note that the choice between 'onesided', 'twosided', and 'centered' depends on the nature of your input signal (real-valued or complex-valued) and your analysis requirements.
For more information about the syntax and different use cases, refer to the documentation:
I hope this helps!
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spectral Estimation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!