How can I combine complex spectrogram results as an image for multi-channel EEG signal?
4 commentaires
Réponses (3)
2 votes
3 commentaires
11 commentaires
I am still using the same code you provided before and the same data provided mydata but for some unknown reason, its not running to the end. it crashes around this line
ftick_ax1 = round(interp1(f,1:length(f),ax1_tick(1:2:end-1))
clearvars close all clc
mydata = load('mydata.mat'); dt = mydata.dt;
% look at the effects of detrending figure subplot(2,1,1) plot(dt) title('Raw data') subplot(2,1,2) plot(detrend(dt)) title('Detrended data')
dt = detrend(mydata.dt);
Fs=500; ws=250; ov=ws/2; nfft = 2^nextpow2(length(dt));
% I'm sure you could preallocate s based on chebwin(ws) and ov, etc. for i=1:8 [s(:,:,i), f, t]=spectrogram(dt(:,i),chebwin(ws),ov,Fs); % since f and t should all be equal. end % you probably want to specify your own frequency set, as an input to % spectrogram()
val = 20*log(abs(s));
% figure % s1 = surf(t,f,val(:,:,1)); % view([0 90]) % set(s1,'EdgeColor','none') % title('surf') % xlabel('Time [s]') % ylabel('Frequency [Hz]') % c1 = colorbar; % ylabel(c1,'Power/frequency') % axis tight
f1 = figure; i1 = imagesc(t,f,val(:,:,1)); ax1 = gca; set(ax1,'YDir','normal') % title('imagesc') xlabel('Time [s]') ylabel('Frequency [Hz]') c2 = colorbar; ylabel(c2,'Power/frequency')
% concatenate them such that val2 = % [val(:,:,1); val(:,:,2);....; val(:,:,end)] val2 = reshape(permute(val,[1 3 2]),[],19,1); nchans = size(dt,2); ff = repmat(f,nchans,1); ff = 1:size(val2,1);
% get ytick and yticklabel based off ax1 ax1_tick = get(ax1,'YTick'); ftick_ax1 = round(interp1(f,1:length(f),ax1_tick(1:2:end-1))); % rounding is fine here
% need to replicate this ftick = ftick_ax1' + length(f).*(0:nchans-1); ftick = ftick(:);
ax1_label = get(ax1,'YTickLabel'); fticklabel = repmat(ax1_label(1:2:end-1),nchans,1);
% Look at a histogram of val2 to get a sense of the tails. If there are % some extreme values, your colorbar (showing the min and max) will look % odd.
% figure % histogram(val2(:))
% Plot all channels f2 = figure('Position',[680 378 805 600]); i2 = imagesc(t,ff,val2); ax2 = gca; set(ax2,'YDir','normal') xlabel('Time [s]') ylabel('Frequency [Hz]') c3 = colorbar; ylabel(c3,'Power/frequency') set(ax2,'YTick',ftick,'YTickLabel',fticklabel) Ftsz = get(ax2,'FontSize'); % get original fontsize because yax changes it
yax = get(ax2,'YAxis'); set(yax,'FontSize',12); set(get(yax,'Label'),'FontSize',Ftsz);
% set caxis based on percentile of val2. [prc] = prctile(val2(:),[1,99]); cmin = prc(1); cmax = prc(2);
% can also try based on distribution mu = mean(val2(:)); sd = std(val2(:)); cmin = mu-3*sd; cmax = mu+3*sd;
caxis([cmin,cmax])

0 votes
1 commentaire
Catégories
En savoir plus sur Regression dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
