Filter löschen
Filter löschen

How can I plot a frequency spectrum in MatLab

1 Ansicht (letzte 30 Tage)
Yasir Khan
Yasir Khan am 2 Aug. 2016
Beantwortet: Star Strider am 2 Aug. 2016
I wanted to know how I can plot a frequency spectrum, with the data provided from the following code. Basically I am trying to see if the EEG threshold is above or below a certain threshold.
clc
clear all
close all
%Convert data from edf to Matlab
[header, data] = edfread('Subject2.edf');
fs = 128; % sampling rate of Emotiv EEG
%averaging to remove common noise
for i=1:14
datan(i,:)=data(i+2,:)-mean(data(3:16,:));
end
fmin = 30; % minimum passband frequency in Hz (High Gamma)
fmax = 50; % maximum passband frequency in Hz (High Gamma)
Rs = 20; % stopband attenuation in dB
Rp = 1; % passband ripples in dB
% for High gamma band
[order, Wn] = ellipord([fmin/(fs/2), fmax/(fs/2)], [(fmin-1)/(fs/2), (fmax+1)/(fs/2)], Rp, Rs);
[B,A] = ellip(order, Rp, Rs, [fmin/(fs/2), fmax/(fs/2)]);
%filtering of entire data into High Gamma band
data_hgamma = filtfilt(B,A,datan');
%segment - extract only the eeg when subject was listening to words using marker data from channel 36
%don't forget to keep the low noise and high noise data separate
val49=find(data(36,:)==49);
val50=find(data(36,:)==50);
val51=find(data(36,:)==51);
val52=find(data(36,:)==52);
for j=1:14
for i=1:96
EEG_hgamma(j,i,:)=data_hgamma(val50(i):0.5*128-1+val50(i),j);
end
end
%0 less noise, 1 more noise
noise_array = [1 0 0 0 0 1 0 1 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 0 0 0 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 1 0 0 1 1 0 1 1];
p=1; q=1;
for i=1:96
if(noise_array(i)==0)
EEGL_hgamma(:,p,:)= EEG_hgamma(:,i,:);
p=p+1;
else
EEGH_hgamma(:,q,:)= EEG_hgamma(:,i,:);
q=q+1;
end
end
%%%%%%%%write script for noisy EEG data removal
for j=1:14
for i=1:size(EEGH_hgamma,2)
Energy_EEGH(j,i)=var(EEGH_hgamma(j,i,:));
end
end
for j=1:14
for i=1:size(EEGL_hgamma,2)
Energy_EEGL(j,i)=var(EEGL_hgamma(j,i,:));
end
end
for j=1:14
[P(j),H(j),STATS(j,:)] = ranksum(Energy_EEGH(j,:),Energy_EEGL(j,:),'tail','right')
end

Antworten (1)

Star Strider
Star Strider am 2 Aug. 2016
I’m not sure what you want to plot. I would use the approach in this documentation for the fft function.

Kategorien

Mehr zu EEG/MEG/ECoG finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by