How can I design a filter for EEG?

I have matrix which is included the channels (row=19) and trial (columns=330) . Now, I have to design a FIR filter to extract data in different bands( beta, alpha, theta,...). I've used fdatool and now I'm confused how I can give my data to the filter to get the output! Could anyone help me?

 Accepted Answer

Star Strider
Star Strider on 22 Jun 2016
Without seeing your code that designs your filters, and your data (or a sample of it), it is not possible to determine what the problem is.
What dimension of your matrix represents the time-domain data of your EEG? I assume ‘channels’ is your EEG data and ‘trials’ represents some event. The problem is that EEG is usually sampled at a relatively high rate, so 330 samples could represent only a few seconds of data, at most.
What information does your matrix actually have?

4 Comments

dear strider thanks for your reply.
Actually the article mentioned that each trial is taken in 600 ms. The matrix include c= stimuli group s=number of a person T= number of a trial. The dimension of the matrix of one of the people (S=1) is 19*330. I did not write specific codes, i just set some number for the filter for desired frequency( for example stopband1=3, passband1=4, passband2=8, stopband2=9) for derving theta band(4-8) Hz.
should I do somth more??
I would have to see the article. You can upload it here (use the ‘paperclip’ icon and do everything it tells you to do). That might be easier than your explaining it, because the authors already did.
You indicate that your 330 samples are taken over 600 ms, calculating to a sampling frequency, ‘Fs’, of 550 Hz.
Using those data and the fdatool function, the filter design function (save the attached ‘Theta_filter.m’ file to your MATLAB user directory) is:
function Hd = Theta_filter
%THETA_FILTER Returns a discrete-time filter object.
% MATLAB Code
% Generated by MATLAB(R) 9.0 and the Signal Processing Toolbox 7.2.
% Generated on: 22-Jun-2016 11:12:35
% Equiripple Bandpass filter designed using the FIRPM function.
% All frequency values are in Hz.
Fs = 550; % Sampling Frequency
Fstop1 = 3; % First Stopband Frequency
Fpass1 = 4; % First Passband Frequency
Fpass2 = 8; % Second Passband Frequency
Fstop2 = 9; % Second Stopband Frequency
Dstop1 = 0.001; % First Stopband Attenuation
Dpass = 0.057501127785; % Passband Ripple
Dstop2 = 0.0001; % Second Stopband Attenuation
dens = 20; % Density Factor
% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fstop1 Fpass1 Fpass2 Fstop2]/(Fs/2), [0 1 ...
0], [Dstop1 Dpass Dstop2]);
% Calculate the coefficients using the FIRPM function.
b = firpm(N, Fo, Ao, W, {dens});
Hd = dfilt.dffir(b);
% [EOF]
This is how I implement the filter:
Hd = Theta_filter; % Create Filter Object (Call The Function)
signal = [zeros(1,2500) 1 zeros(1,2499)]; % Create Data
tv = [0:length(signal)-1]/550; % Create Time Vector
filtered_signal = filtfilt(Hd.Numerator, 1, signal); % Use ‘filtfilt’ To Filter The Signal
figure(1)
plot(tv, signal)
hold on
plot(tv, filtered_signal)
hold off
grid
axis([4 5 -0.2 0.2])
This works. For some reason, the documentation for fdatool leaves much to the imagination. That is unfortunate with respect to a very useful function intended for beginners in signal processing to easily design stable filters.
My filter design procedure for IIR filters is here: How to design a lowpass filter for ocean wave data in Matlab? You may not find it directly applicable to your problem, since you are using FIR filters, but it has some useful design strategies.
Note that if the actual sampling frequency is different than 550 Hz, you will have to design the filter for that sampling frequency. The part of my code with respect to implementing the filter will work without modification (unless you call your function something other than ‘Theta_filter.m’).
I will use the instructions you provided above. Thanks for your great help.
My pleasure.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!