Open Dine-Dine opened 6 years ago
Hi! I like the idea and I've experimented a little with that. The problem is in the implementation of such a tool.
The first issue is how the user selects the appropriate time range. Since Matlab 2015a, the user click&drag set of tools in Matlab have been changed a lot so its really not a trivial procedure to implement. Depending on how this is implemented, the plotter would have to constantly check for mouse clicks which would slow every other process down.
Secondly, since all the channels are in a single plot... it may be tricky to know exactly which channel you'd like to run the fft on.
I'll definitely keep this in mind though, and see if a good way to do this comes about. However, no promises that I can get to this in the near future.
OK, what about having a color-coded FFT power graph displayed below the the hypnogram? Would it be easier?
That would definitely be easier... however, as I understood it, you wanted to be able to separate alpha from spindles, and the full recording spectogram wouldn't help much with that unfortunately.
Another minor point is that these are created for only a single channel, and if that channel should be quickly selectable this will mean another slow down of the plotter.
That's true, these are two different things.
I like to have this plot because it gives you an instantaneous look of what the night looked like, and there was such function in the two sleep scoring systems that I used. As for the channel selection, there could be one channel by default, for instance C4, and in the rare instances where it would be bad, one should be able to switch to C3.
As for differentiating spindles and alpha, it becomes easier with experience, but it is practical for beginners.
I also like to see a quick spectrogram before I sleep score and just do this outside of the plotter using the bit of code below... (I should make this into a little csc_ ... function later)...
Even with experience, sometimes it can be difficult to spot spindles... so I'll definitely think a little bit about how to implement an efficient option to view the fft of a small segment.
% plot the spectogram
% ^^^^^^^^^^^^^^^^^^^
% find the desired channel
channel_name = 'E81';
channel_id = find(strcmp({EEG.chanlocs.labels}, channel_name));
% get channel data
channel_data = EEG.data(channel_id, :);
% remove bad data
channel_data(:, EEG.bad_data) = 0;
% calculate the spectrogram
window_length = 2;
[fft, freq_range, time_range, psd] = spectrogram(...
channel_data, ... % the data
EEG.srate * window_length, ... % the window size
EEG.srate * window_length/2, ... % the overlap
EEG.srate * window_length, ... % number of points (no buffer)
EEG.srate, ... % sampling rate
'yaxis');
% define frequency limits to plot
freq_ind = freq_range < 50;
% smooth the psd
smoothed_psd = imgaussfilt(log(psd(freq_ind, :)), 1.5);
% plot the spectrogram
handles.fig = figure('color', 'w');
handles.ax = axes('nextPlot', 'add');
handles.contour = contourf(time_range, freq_range(freq_ind), ...
smoothed_psd, 7, ...
'lineStyle', 'none');
% put little tick marks at the events
% events_to_plot = [1, 2, 4, 5, 7, 8, 10, 11];
events_to_plot = [1:length(EEG.event)];
for n = 1 : length(events_to_plot)
plot(EEG.event(events_to_plot(n)).latency / EEG.srate, 45,...
'lineStyle', 'none',...
'marker', 'v',...
'markerSize', 15,...
'markerEdgeColor', [0.9, 0.9, 0.9],...
'markerFaceColor', [0.2, 0.2, 0.2]);
end
% turn time in hours/minutes
tick_samples = get(handles.ax, 'XTick');
tick_times = seconds(tick_samples);
tick_labels = cellstr(char(tick_times, 'hh:mm:ss'));
set(handles.ax, 'XTickLabels', tick_labels);
When scoring in csc_eeg_plotter, can we implement a small windows within the epoch showing an FFT, in order for instance to differentiate alpha or spindle?