This is far past my understanding of matlab and want to understand how to code such a thing, thank you

5 views (last 30 days)
So I have a 64-challel EEG data sheet/file that has a sampling frequency of 1000Hz. The data has these large spikes that are not needed because it is unintended noise from the EEG so I need to call in the file, and filter and clean the first channel of the EEG data.
I have started to understand how to call in the file but do not know how to filter a file/matrix.

Answers (1)

Star Strider
Star Strider on 5 Dec 2021
I only see two spikes in the Fourier transformed data, one at 120 Hz and the other at 240 Hz. A FIR filter can elimiated both spikes at the same time —
LD = load('EEG_data.mat');
Data = double(LD.Data); % Signal Processing Functions Need 'double' Data
L = size(Data,1);
Fs = 1E3; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequecny
Ts = 1/Fs; % Sampling Interval
t = linspace(0, L, L)*Ts; % Time Vector
fcomb = [[55 59 61 64]+60, [55 59 61 64]+180]; % Stopband Frequencies
mags = [[1 0 1], [0 1]]; % Relative Magnitudes
dev = [[0.5 0.1 0.5], [0.1 0.5]]; % Deviation Tolerances
[n,Wn,beta,ftype] = kaiserord(fcomb,mags,dev,Fs); % Kaiser Window Filter Design
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale'); % Design Filter, Return Coefficients
figure
freqz(hh, 1, 2^20, Fs) % Examine Filter Performance
set(subplot(2,1,1), 'XLim', [0 500]) % Zoom X-Axis
set(subplot(2,1,2), 'XLim', [0 500]) % Zoom X-Axis
DataFilt = filtfilt(hh, 1, Data); % Filter Data
figure
plot(t, Data)
grid
xlabel('t')
title('Time Domain Plot')
NFFT = 2^nextpow2(L);
FTData = fft(Data,NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
semilogy(Fv, abs(FTData(Iv,:))*2)
grid
xlabel('Frquency (Hz)')
title('Fourier Transform Of Original Data')
NFFT = 2^nextpow2(L);
FTDataFilt = fft(DataFilt,NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
figure
semilogy(Fv, abs(FTDataFilt(Iv,:))*2)
grid
xlabel('Frquency (Hz)')
title('Fourier Transform Of Filtered Data')
There is no reason to post the plot images here. They will show up when the code is run.
.

Categories

Find more on EEG/MEG/ECoG in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!