|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function compdsp(data,unmix,locfile,srate,titl,compnums,amps,act) |
|
|
|
|
|
minHz = 2; |
|
|
maxHz = 40; |
|
|
ACTS_PER_EEGPLOT = 32; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
icadefs |
|
|
|
|
|
if nargin<2 |
|
|
help compdsp |
|
|
return |
|
|
end |
|
|
|
|
|
chans = size(data,1); |
|
|
frames = size(data,2); |
|
|
ncomps = size(unmix,1); |
|
|
|
|
|
if ncomps < 1 |
|
|
error('Unmixing matrix must have at least one component'); |
|
|
end |
|
|
if chans < 2 |
|
|
error('Data must have at least two channels'); |
|
|
end |
|
|
if frames < 2 |
|
|
error('Data must have at least two frames'); |
|
|
end |
|
|
if size(unmix,2) ~= chans |
|
|
error('Sizes of unmix and data do not match'); |
|
|
end |
|
|
if nargin<3 |
|
|
locfile=[]; |
|
|
end |
|
|
if isempty(locfile) |
|
|
locfile = DEFAULT_ELOC; |
|
|
end |
|
|
if ~exist(locfile) |
|
|
error('Cannot find electrode locations file'); |
|
|
end |
|
|
|
|
|
if nargin<4 |
|
|
srate = 0; |
|
|
end |
|
|
if isempty(srate) | srate==0 |
|
|
srate = DEFAULT_SRATE; |
|
|
end |
|
|
if nargin<5 |
|
|
titl = ''; |
|
|
end |
|
|
if isempty(titl) |
|
|
titl = ''; |
|
|
end |
|
|
if nargin<6 |
|
|
compnums = 0; |
|
|
end |
|
|
if isempty(compnums) |
|
|
compnums = 0; |
|
|
end |
|
|
if nargin<7 |
|
|
amps = NaN; |
|
|
end |
|
|
if isempty(amps) |
|
|
amps = NaN; |
|
|
end |
|
|
if ~isnan(amps) & length(amps) ~= ncomps |
|
|
error('Supplied amps does not match the number of unmixed components'); |
|
|
end |
|
|
|
|
|
if compnums(1) == 0 |
|
|
compnums = 1:ncomps; |
|
|
end |
|
|
if min(compnums) < 1 |
|
|
error('Compnums must be positive'); |
|
|
end |
|
|
if min(compnums) > ncomps |
|
|
error('Some compnum > number of components in unmix'); |
|
|
end |
|
|
|
|
|
if nargin<8 |
|
|
act = NaN; |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if chans == ncomps |
|
|
winv = inv(unmix); |
|
|
elseif chans < ncomps |
|
|
error('More components than channels?'); |
|
|
else |
|
|
winv = pinv(unmix); |
|
|
end |
|
|
|
|
|
if isnan(act) |
|
|
fprintf('Computing activations ...') |
|
|
act = unmix(compnums,:)*data; |
|
|
fprintf('\n'); |
|
|
elseif size(act,2) ~= frames |
|
|
error('Supplied activations do not match data length'); |
|
|
elseif size(act,1) ~= ncomps & size(act,1) ~= length(compnums) |
|
|
error('Number of supplied activations matrix does not match data or weights'); |
|
|
elseif size(act,1) == ncomps |
|
|
act = act(compnums,:); |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pos = [40,520,550,400]; figure('Position',pos); |
|
|
if isnan(amps) |
|
|
fprintf('Computing component rms amplitudes '); |
|
|
amps = zeros(1,length(compnums)); |
|
|
for j=1:length(compnums) |
|
|
amps(j) = rms(winv(:,compnums(j)))*rms(act(j,:)'); |
|
|
fprintf('.') |
|
|
end |
|
|
fprintf('\n'); |
|
|
else |
|
|
amps = amps(compnums); % truncate passed amps to desired compnums |
|
|
end |
|
|
plot(compnums,amps,'k'); |
|
|
hold on |
|
|
plot(compnums,amps,'r^'); |
|
|
xl=xlabel('Component numbers'); |
|
|
yl=ylabel('RMS Amplitudes'); |
|
|
tl=title([titl ' Amplitudes']); |
|
|
ax = axis; |
|
|
axis([min(compnums)-1 max(compnums)+1 0 ax(4)]); |
|
|
|
|
|
% |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%% II. Plot component maps %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
% |
|
|
pos = [40,40,550,400]; figure('Position',pos); |
|
|
|
|
|
fprintf('Plotting component scalp maps ...') % compmaps() may make multiple figures |
|
|
compmap(winv,locfile,compnums,[titl ' Scalp Maps'],0,compnums); |
|
|
fprintf('\n'); |
|
|
|
|
|
% |
|
|
%%%%%%%%%%%%%%%%%%%%%% III. eegplot() activations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
% |
|
|
if frames/srate < 10 |
|
|
dispsecs = ceil(frames/srate); |
|
|
else |
|
|
dispsecs = 10; % defaults - display 10s data per screen |
|
|
end |
|
|
range = 0.8*max(max(act')-min(act')); |
|
|
|
|
|
stact=1; |
|
|
lact=ACTS_PER_EEGPLOT; |
|
|
if lact>size(act,1) |
|
|
lact = size(act,1); |
|
|
end |
|
|
|
|
|
pos = [620,520,550,400]; figure('Position',pos); |
|
|
while stact <= size(act,1) |
|
|
% eegplot(data,srate,spacing,eloc_file,windowlength,title,posn) |
|
|
eegplot(act(stact:lact,:),srate,range,compnums(stact:lact),... |
|
|
dispsecs,[titl ' Activations'],pos); |
|
|
pos = pos + [.02 .02 0 0]; |
|
|
stact = stact+ACTS_PER_EEGPLOT; |
|
|
lact = lact +ACTS_PER_EEGPLOT; |
|
|
if lact>size(act,1) |
|
|
lact = size(act,1); |
|
|
end |
|
|
end |
|
|
|
|
|
% |
|
|
%%%%%%%%%%%%%%%%%%%%%%% IV. plotdata() spectra %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
% |
|
|
pos = [620,40,550,400]; figure('Position',pos); |
|
|
|
|
|
if frames > 2048 |
|
|
windw = 512; |
|
|
elseif frames > 1024 |
|
|
windw = 256; |
|
|
else |
|
|
windw = 128; |
|
|
end |
|
|
fprintf('Computing component spectra ') |
|
|
for j = 1:length(compnums) |
|
|
% [Pxx,F] = PSD(X,NFFT,Fs,WINDOW,NOVERLAP) |
|
|
[spec,freqs] = psd(act(j,:),1024,srate,windw,ceil(windw*0.5)); |
|
|
if ~exist('specs') |
|
|
specs = zeros(length(compnums),length(freqs)); |
|
|
end |
|
|
specs(j,:) = spec'; |
|
|
fprintf('.') |
|
|
end |
|
|
fprintf('\n'); |
|
|
specs = 10*log10(specs); |
|
|
|
|
|
tmp = ceil(sqrt(length(compnums))); |
|
|
tmp2 = ceil(length(compnums)/tmp); |
|
|
for j=1:length(compnums) |
|
|
sbplot(tmp2,tmp,j) |
|
|
plot(freqs,specs(j,:)) |
|
|
set(gca,'box','off') |
|
|
set(gca,'color',BACKCOLOR); |
|
|
ax=axis; |
|
|
axis([minHz,maxHz,ax(3),ax(4)]); |
|
|
tl = title(int2str(compnums(j))); |
|
|
end |
|
|
xl=xlabel('Frequency (Hz)'); |
|
|
yl=ylabel('Power (dB)'); |
|
|
set(gca,'YAxisLocation','right'); |
|
|
txl=textsc([titl ' Activation Spectra'],'title'); |
|
|
axcopy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function rmsval = rms(column) |
|
|
rmsval = sqrt(mean(column.*column)); |
|
|
|