How the extract EEG data according to different epoch limits?

Hey there! Currently I got an EEG data with events like "2", "4", "6","8" which mean the outset of different audio stimui. There are 20 kinds of specific audio stimuli with some similar features for each kind of event/trigger. I have the stimuli matrix generated in each experiment which is in the actual stimulating order. so the specific stimulus for each event could be targeted. In each stimulus, there is 1s silence at the begining and and the end and duration of actual voice is from 1s to 2s. I can use the detectSpeech function to find the outset and end of the voice.
Now I want to extract the EEG data with actual audio stimuli and delete the silence areas, which couldn't be realized by exracting epochs with specific limits(start and end). could you please tell me how to use script to get the EEG epochs with different length?
Thank you very much!

Antworten (1)

Are you using EEGLAB? If so, I recommend you post your quesiton to the EEGLAB mailing list - see here.
The answer depends on how the audio and eeg data are synchronized and formatted. The audio and EEG sampling rates will be different. You can find the audio file sampling rate, fs, with
[y,fs]=audioread(filename);
I assume you want to make a single continuous EEG file with the EEG during speech. Extract the relevant portions of the EEG by converting the speech start/stop indices (obtained with detectSpeech()) to the corresponding indices of the EEG signal, taking into account the different sampling rates and the time offset, if any, between the start of the speech file and the start of the EEG data file.
I assume you have 8 EEG channels, sampled at 256 Hz, and the EEG data is in array x, which is N-by-8. There may be a time offset (tOfst, in seconds) between the start of the audio and EEG data files, where tOfst is >0 or <0 if the audio file starts before or after the eeg file, respectively.
x=rand(4096,8); % represents 16 seconds of EEG data
% real EEG data may be formatted differently
tOfst=0.5; % time offset (s) >0 if audio starts before EEG
fse=256; % EEG sampling rate (Hz)
[y,fsa]=audioread(audiofilename); % read audio file and get audio sampling rate (Hz)
y=y(:,1); % take channel 1 of stereo file
idxa = detectSpeech(y,fsa); % indices where speech starts, ends
[Ns,~]=size(idxa); % number of speech segments
idxe=round(idxa*fse/fsa+tOfst*fse); % speech start/stop indices for EEG file
xs=[]; % (empty) array for EEG during speech
for i=1:Ns
xs=[xs;x(idxe(i,1):idxe(i,2),:)];
end
Neegsp=length(xs);
fprintf('Duration of EEG during speech=%.2f s.\n',Neegsp/fse)
Good luck.

6 Kommentare

Thank you so much for the kind response!
Here is the brief introduction of my data. It's from an ERP study and all the resampled audio envelopes were aligned to one auxiliary channel of the EEG data. The synchronization was made utilizing the event latency and corresponfing audio length of each trigger. The stimulating oder of audios was dertermined by the stim Matrix generated before each experiment.
Extracting EEG data into epochs with same start and limits could be carried out in EEGLAB, but my purpose of dividing data into epochs with different length could not be realized in EEGLAB. So I am asking help for programming.
I am so grateful for your support, but I am a little bit confused. idxa = detectSpeech(y,fsa);this code will generate a data like [spot1 spot2] in which spot 1 and 2 mean the indices of the start and end. since the audio stimuli are short sentence within 2s, only one speech segment would be found by detectSpeech function. So I am wondering how I can use respective speech segment for each audio file to cut off the EEG data into epochs.
Thanks again!
Are you using files created by EEGLab, such as the example data file, “eeglab_data_epochs_ica.set”
Could you zip one file and upload it so we can see how it is structured?
You write: "all the resampled audio envelopes were aligned to one auxiliary channel of the EEG data. The synchronization was made utilizing the event latency and corresponfing audio length of each trigger. The stimulating oder of audios was dertermined by the stim Matrix generated before each experiment. "
"Resampled audio" has me curious. Resampled to a lower samping rate? To the same rate as the EEG rate? Normal EEG sampling rates of 256 or 512 or even 1024 Hz (rare) would be too slow for audio, but maybe the envolpe would still be good for voice detection, of you rectify and then lowpass the audio.. But that is not what detectSpeech() expects.
Have you checked the results that detectSpeech() gives? I did a little test using the built-in laptop microphone and got poor results.
the EEG data was recorded using a 64-channel antiCHamp Brain Products recording system with a sampling rate of 250 and preprocessed using Brainvision analyzer (filtering,ica,etc.). And then the processed data was aligned with audio envelope and stored in .set format in Matlab with corresponding script, not EEGLAB.
As for the resampling of audio files, the audio envelope was acquired with Hilbert Transformation and resampled to the same sampling rate of EEG data (250Hz). The corresponding script is as follows.
stim_files = dir('*.wav');
stim_name = {stim_files.name}';
for i=1:size(stim_name)
[audio{i} FS{i}] = audioread(stim_name{i});
wav_abs_hilb{i} = abs(hilbert(audio{i}));
old_rate=FS{i};
new_rate=EEG.srate;
[P,Q] = rat(new_rate/old_rate);
abs(P/Q*old_rate-new_rate);
sig_dur_limit = 3.700;
audio_env_resampled{i} = resample(wav_abs_hilb{i},P,Q);
end
The EEG data sample with aligned audio envelope was attached with this comment. Due the size limit of uploading files, there is only about 60s EEG data which is resampled to 200Hz.
When it comes to the detectSpeech function, I have tested it using following code:
for i=1:size(stim_name)
[audio{i} FS{i}] = audioread(stim_name{i});
roi{i} = detectSpeech(audioIn{i},FS{i});
audioIn_pure{i} = audioIn{i}(roi{i}(1):roi{i}(end));% Remove the silence.
end
the result of roi is displayed in following figure which presents the start and end of the sentence speech.
Thank you so much for your time and effort!
I opened file "sample_083__audioFeature.set". It is my first time ever using EEGLAB or its functions. I see the file has 65 channels and 65K+ points.
Will look at it more later.
The metadata for the sample file says the dataset consists of 1 epoch with 33 events.
I see the dataset has 65 channels sampled at 200 Hz for about 84.5 s. It looks to me like channel 65 is the audio channel. Channel 65 and appears to have 7 non-zero segments, each about 1-2 seconds long. Is this the expected number of speech segments for this dataset?
Would you send me a secure email so we can continue this dicussion offline? It will be easier to share files that way. To do this, click on the "WR" circle next to my posts. That should bring up a pop-up window with an envelope in the top right corner. Click the envelope to send an email.
For sure! Thank you so much!

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2022b

Gefragt:

am 17 Mai 2024

Kommentiert:

am 21 Mai 2024

Community Treasure Hunt

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

Start Hunting!

Translated by