problem in for loop for plotting

6 vues (au cours des 30 derniers jours)
Mary
Mary le 3 Avr 2017
Commenté : Mary le 3 Avr 2017
hi, I have an EEG data and its matrix dimention is: 1068*4 now I want to undrestand which column relate to which brain wave, so I use Fourier transform and I write this code:
if true
load 'sig_x.dat'
fs = 500; % Hz
[N, M] = size(sig_x);
n = N/2;
f = (0:n-1)/n * fs/2;
for j = 1:M;
subplot(M, 1, j)
ff1 = fft(sig_x(:, j));
eegfft = abs(ff1);
figure(3)
plot(f, eegfft(1:n))
ylabel(['Wave ' num2str(j)])
end
but I don't get the spectrum of the first column. is there anything wrong whit this code ? or is there something I missed?

Réponse acceptée

Joseph Cheng
Joseph Cheng le 3 Avr 2017
Modifié(e) : Joseph Cheng le 3 Avr 2017
do you mean you're missing the first spectrum because you put the figure after the first instance of subplot? you should move figure(3) before the for loop. with this you create the subplot in whatever is the active figure/axes for the first iteration, jump to figure(3) to then plot the first iteration fft. however with that you overwrite that first iteration with the subsequent subplots.
if you're commenting that there is no frequency response maybe taking the log10(eeft(1:n)) would help you see the smaller frequency responses.
  2 commentaires
Joseph Cheng
Joseph Cheng le 3 Avr 2017
a good sequence of events for axes creation is
  1. create/define figure
  2. instantiate subplots if desired
  3. plot/surf/imagesc/etc
as you'll create the container for the visual display in order, otherwise items 2 and 3 will be to whatever is considered the active figure.
Mary
Mary le 3 Avr 2017
many thanks for your answer.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur EEG/MEG/ECoG dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by