"The length of the segments cannot be greater than the length of the input signal" - pwelch

16 ビュー (過去 30 日間)
Hello, I am trying to use pwelch to estimate PSD for an EEG dataset sampled at 250Hz with trials lasting 4s, i.e., 1000 datapoints per trial.
[psds, f] = pwelch(eeg_ArrowL(chnl,trial,:), [], [], [], 250);
This is the general statement I adapted from a script from another project, where eeg_ArrowL(chnl,trial,:) = 1x1x1000 double. However, I keep getting the error "The length of the segments cannot be greater than the length of the input signal.", as specified in the title of this post. It does work when I make the signal input a length of 2000, so I am assuming the arguements for window and noverlap are wrong for a signal input of length 1000. I have tried to read up more on how pwelch works and what the arguements do, and I have tried different values for window and noverlap but it still does not work. Please help.

採用された回答

Sudarsanan A K
Sudarsanan A K 2023 年 10 月 30 日
Hello Jeremy,
I understand that you are trying to use "pwelch()" function to extract the power spectral density (PSD) of your EEG signal from individual channels and trials. The issue you are facing, "The length of the segments cannot be greater than the length of the input signal" is because of the format of the data that you are passing as input signal to the "pwelch()" function.
I note that your input signal to the "pwelch()" function is "eeg_ArrowL(chnl,trial,:)" which is of dimension 1x1x1000. From the MathWorks documentation page of "pwelch()" function, the input signal is expected to be a vector or a matrix. You can extract the data in "eeg_ArrowL(chnl,trial,:)" into a vector using "squeeze()" function.
Here is an example that performs this operation and obtains PSD of the signal subsequently:
% Generate a random EEG dataset (for demostration purpose)
eeg_ArrowL = rand(1, 1, 1000); % 1x1x1000 random EEG data
% Set the channel and trial indices
chnl = 1;
trial = 1;
% Extract the data as a vector
eegData = squeeze(eeg_ArrowL(chnl, trial, :));
% Set the sampling rate
fs = 250; % Sampling rate in Hz
% Estimate the PSD using pwelch
[psd, freq] = pwelch(eegData, [], [], [], fs);
% Plot the PSD
plot(freq, 10*log10(psd));
grid on;
xlabel('Frequency (Hz)');
ylabel('Power Spectral Density (dB/Hz)');
title('Power Spectral Density Estimate');
By using the "squeeze()" function, you convert the 1x1x1000 data into a 1D vector, allowing you to calculate the PSD using the "pwelch()" function.
You can additionally refer to the MathWorks documentation pages of "pwelch()" and "squeeze()" functions for better understanding of different use cases.
I hope this helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParametric Spectral Estimation についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by