Multiple EEG-files to one spectrogram

4 views (last 30 days)
Mikkel Mortensen
Mikkel Mortensen on 26 Mar 2019
Commented: Walter Roberson on 27 Mar 2019
Hi,
I am trying to plot multiple EEG-files in the SAME spectrogram in extension of eachother.
The files contain data from only one channel recording. The files are containing EEG from 6 hours in total, but they are seperated and are containing 3 hours each.
Now I want to plot them in extension of eachother in the same plot (spectrogram),
- Is this possible?
Thanks.
  2 Comments
Walter Roberson
Walter Roberson on 26 Mar 2019
Concatenate the data together before calculating the spectrogram ?
Mikkel Mortensen
Mikkel Mortensen on 27 Mar 2019
Edited: Mikkel Mortensen on 27 Mar 2019
That might help, but what I wrote in the text was a thought example.
Our real problem is that we have multiple files that in total are recording EEG for a few months. These files are not necessary continous on the x-axis, but could jump some minuts.
What we want, is to plot all of this data from the files in the same spectrogram.
- If we as an example are missing one hour with data, we want it to plot this time as black or grey box (something like that)
Maybe the first step is to concatenate the files, but what will happen when the minuts(X-axis) jumps?

Sign in to comment.

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 27 Mar 2019
Edited: Bjorn Gustavsson on 27 Mar 2019
If there is time-gaps in your data-sequence, just do the individual spectrograms as per usual, I'd use something like this:
data_files = dir('*.dataformatofyours');
WINDOW = 256; % Or Hamming/Bartlet/Kaiser/Whatever you use
NOVERLAP = 64; % ...
Fs = 25; %
for i_t = 1:numel(data_files),
[t{i_t},EEG{i_t}] = EEG_data_reader(data_files(i_t).name);
[S{i_t},F{i_t},T{i_t}] = spectrogram(EEG{i_t},WINDOW,NOVERLAP,[],Fs);
pcolor(T{i_t}+t{i_t}(1),F{i_t},log10(abs(S{i_t}))),shading flat
hold on
end
That should concatenate the plots, with some gaps where you have data-gaps. If you concatenate the data you will no longer have constant sampling-rate - which is what the spectrogram-function implicitly use, so if you concatenate data you will get "peculiar" features in your spectrogram across the seams.
HTH
  3 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 27 Mar 2019
1, Well, how could I possibly know what data-format you have, and what your IO-function reading the, from my vantage-point unknown data-format? I simply assumed that you had a reading-function that gave you the EEG-data channel and the corresponding time-array.
2, Yes, I edited my reply.
3, the pcolor-call is intended to plot the log10 of the spectrogram amplitude as a function of time and frequency. The different data-chunks should shifted to the start-time of the corresponding data-chunk - here I've guessed that the time you get from your EEG-reading function gives you someting like a clock-time or serial time that you can use straight off. You might have to convert the time you get to something that's continuous in time, for example if you get data in [YYYY MM DD HH MM SS] format you might convert that into running days:
t_seq{i_t} = t{i_t}(:,3) + (t{i_t}(:,4) + t{i_t}(:,5)/60 + t{i_t}(:,6)/3600)/24;
Or whatever is suitable for your data.
HTH

Sign in to comment.

Categories

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

Community Treasure Hunt

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

Start Hunting!