What are the best parameters in this case?

1 view (last 30 days)
N Saf
N Saf on 11 Jun 2023
Commented: Diwakar Diwakar on 11 Jun 2023
I am trying to extract PSD using welch method from 1 channel EEG data of 4s length that is sampled at 256Hz , my code is below. What are the best parameters to be used for the window length and overlap???
% Load EEG data (replace with your actual data)
load('eeg_data.mat'); % Assuming eeg_data.mat contains a variable named 'eeg_data'
% Parameters
window_length = 2; % Window length in seconds
window_overlap = 0.5; % Window overlap ratio (0 to 1)
sampling_rate = 256; % Sampling rate in Hz
% Compute window parameters
window_size = round(window_length * sampling_rate);
overlap_size = round(window_overlap * window_size);
step_size = window_size - overlap_size;
% Initialize variables for PSD
num_windows = floor((numel(eeg_data) - window_size) / step_size) + 1;
psd = zeros(num_windows, window_size/2 + 1);
freq = (0:window_size/2) * sampling_rate / window_size;
% Compute PSD using a moving window
for i = 1:num_windows
% Extract current window
window_start = (i-1) * step_size + 1;
window_end = window_start + window_size - 1;
window_data = eeg_data(window_start:window_end);
% Compute PSD using Welch's method
[psd(i,:), ~] = pwelch(window_data, [], [], [], sampling_rate);
end
% Plot the PSD
figure;
imagesc(1:num_windows, freq, 10*log10(psd'));
set(gca, 'YDir', 'normal');
xlabel('Window Index');
ylabel('Frequency (Hz)');
title('Power Spectral Density');
colorbar;
  2 Comments
John D'Errico
John D'Errico on 11 Jun 2023
The "best" parameters? That is impossible to know for parameters like that. It would depend on the magnitude of any noise in the data, and how it compares to the signal. It probably depends on some other thigns that are not easily defined. Anyway if there were some easy way to know the "best" parameters, then that would have been built into the code already.
So what can you do? Try some different parameters. See what makes you happy on your data. Your eye is the best possible measure of goodness.
Diwakar Diwakar
Diwakar Diwakar on 11 Jun 2023
Iterate and experiment with different parameter values to find the settings that best suit your specific EEG data and analysis goals.

Sign in to comment.

Answers (0)

Categories

Find more on EEG/MEG/ECoG in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!