Why is my plot showing up blank?

3 vues (au cours des 30 derniers jours)
Alicia Mason
Alicia Mason le 14 Juil 2021
Commenté : Star Strider le 29 Juil 2021
I am attempting to plot a frequency spectrum for some MEG data using this script seedssE.m, originally written by Nai Ding for his 2016 study looking at cortical tracking of linguistic structures: https://www.nature.com/articles/nn.4186
clear
load('R1167_test.mat')
for trl=1:size(data,3)
x(:,:,trl)=resample(data(:,:,trl),1,1);end
x=single(x);
save R1167-1000Hz_test x
%%
clear;
load('R1167-1000Hz_test.mat')
fs=1000;
[b]=fir1(200,[0.5 6]/(fs/2));a=1;
clear xf
for trl=1:size(x,3)
xf(:,:,trl)=filter(b,a,x(:,:,trl));
end
xf=xf(fs+[1:0.32*fs*4*10],:,:);
x0=unfold(xf);
x1=mean(xf,3);
c0=x0'*x0;
c1=x1'*x1;
keep2=10.^-12;keep1=[];
[todss,fromdss,ratio,pwr]=dss0(c0,c1,keep1,keep2);
y=fold(unfold(xf)*todss(:,1:10)*fromdss(1:10,:),size(xf,1));
[sa,sb,f]=plot_itc_avg_spectrum(y,fs,[0 5]);
subplot 211;set(gca,'xtick',[1/4 1/2 1 2 4]/0.32);grid
hold on;plot(f,mean(sa,2)*3,'k','linewidth',2)
subplot 212;set(gca,'xtick',[1/4 1/2 1 2 4]/0.32);grid
hold on;plot(f,mean(sb,2)*3,'k','linewidth',2)
This makes use of the function plot_itc_avg_spectrum, shown in full below:
function [itc_sprectrum,avg_spectrum,f]=plot_itc_avg_spectrum(eeg_data,fs,display_frequency_range,f_label)
% calculate and plot the neural response spectrum
% input:
% eeg_data (time * channel * trial)
% fs (sampling rate in Hz)
% display_frequency_range (the frequency range that will be plotted)
% f_label (optional, frequencies being labeled)
% output:
% itc_sprectrum (frequency * channel, inter-trial phase coherence spectrum R^2),
% avg_spectrum (frequency * channel, power spectrum of the response averaged over trials)
% f (frequency labels)
% example:
% plot_itc_avg_spectrum(eeg_data,200,[0.5,4.5],1:4);
%
% Nai Ding & Wen Zhang, 2016
% ding_nai@zju.edu.cn
f=1:size(eeg_data,1);f=f-1;f=f/size(eeg_data,1);f=f*fs;
az = zeros(size(eeg_data,1),size(eeg_data,3),size(eeg_data,2));
for ch = 1:size(eeg_data,2)
az(:,:,ch) = angle(fft(squeeze(eeg_data(:,ch,:))));
end
itc_sprectrum = squeeze(pcoh3(az));
avg_spectrum = abs(fft(mean(eeg_data,3)));
figure;
subplot(211);
plot(f,itc_sprectrum);
xlim(display_frequency_range);
xlabel('frequency (Hz)')
ylabel('inter-trial phase coherence')
try
set(gca,'xtick',f_label);end
title('itc\_sprectrum');
subplot(212);
plot(f,avg_spectrum);
xlim(display_frequency_range);
title('avg\_spectrum');
xlabel('frequency (Hz)')
ylabel('power (a.u.)')
try
set(gca,'xtick',f_label);end
end
function r=pcoh3(ag)
c=cos(ag);
s=sin(ag);
r=mean(c,2).^2+mean(s,2).^2;
end
When I run plot_itc_avg_spectrum on its own, with a MatLab array of the form time x channel x trials as the input, it works fine, and gives me a plot showing a frequency spectrum of the data with correctly labelled axes.
However, when I run the whole seedssE script, with various functions designed to perform Denoising Source Separation (DSS), the script runs without any obvious errors, but produces a blank plot.
Both of these plots are attached.
How can I ensure that the plot that results from running the whole seedssE script is not blank, and looks like the plot resulting from running plot_itc_avg_spectrum on its own?
  5 commentaires
Alicia Mason
Alicia Mason le 29 Juil 2021
It seems like the fold() function was indeed a proprietary function, just like unfold() - I managed to track this down, and now it works! Thank you so much for giving me the clue to this!
Star Strider
Star Strider le 29 Juil 2021
My pleasure!
I still have no idea what ‘fold’ and ‘unfold’ do in that code, or even what they are.
.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by