How can I measure maximum frequency component present in my recorded EEG signal so that I can use right filter ahead?

4 views (last 30 days)
I am working on a single channel EEG dataset but not able to apply hamming window based Low Pass Filter to it for denoising. I am using DenoiseF = filter (Hd,m); {Hd= window function, m= dataset} but it says "??? Undefined function or method 'filter' for input arguments of type 'cell'." Also I need to know maximum frequency component in my signal so that I can decide whether I need to filter it or it is already in usable range. Someone please help. May be I am not using right codes in Matlab.

Accepted Answer

Star Strider
Star Strider on 14 Mar 2017
See the documentation on the fir1 (link) function. It uses a Hamming window by default.
Use the filtfilt function to do the actual filtering.
  2 Comments
JAGRITI SAINI
JAGRITI SAINI on 14 Mar 2017
Thank You Sir.. It worked Now.. But please can you help me to know what should be my filter order for better results? I am trying this formula for calculation of filter order:
if true
>> f1=0.2;
>> f2=60;
>> fs=250;
>> m = (0.3*f1)/(fs/2);
>> M=round(8/m);
>> N = M-1;
>> b = fir1(N,0.5,'low');
end
However, I am not interested to define f1, as I need a low pass filter with cut frequency range 60 Hz or 62 Hz. my data set length is= 4097 Here I am getting filter order N = 16666.. That seems too high.. Is it right? I was thinking to use low filter order like somewhere between 20 to 80 for reduced computational complexity. What should be right procedure to choose filter order here?
Star Strider
Star Strider on 14 Mar 2017
My pleasure.
The easiest way to calculate the filter order is to use another window function, and then let the window function design your filter using your desired parameters.
Example (bandpass filter):
Fs = 96E+3; % Sampling Frequency (Hz)
fcuts = [850 891 1122 1163]; % Frequency Vector (Hz)
mags = [0 1 0]; % Magnitude (Defines Passbands & Stopbands)
devs = [0.05 0.01 0.05]; % Allowable Deviations
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,Fs);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'scale');
figure(1)
freqz(hh, 1, 2^16, Fs)
set(subplot(2,1,1), 'XLim', [0 1500]) % Set Frequency Axis To Show 0-500 Hz
set(subplot(2,1,2), 'XLim', [0 1500]) % Set Frequency Axis To Show 0-500 Hz
See the documentation on kaiserord for details.
Other options exist, and an IIR filter that approximates the steep rolloff of the FIR filter is a Chebyshev Type II design. You can use the designfilt function, or design it yourself.
Example (different bandpass filter):
Fsp = 1000; % Sampling Frequency
Fn = Fsp/2; % Nyquist Frequency
Wp = [1.0 49]/Fn; % Passband Frequencies (Normalised)
Ws = [0.5 50]/Fn; % Stopband Frequencies (Normalised)
Rp=10; % Passband Ripple (dB)
Rs=30; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Calculate Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Design Filter
[sos,g] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(1)
freqz(sos, 2^16, Fsp)
set(subplot(2,1,1), 'XLim',[0 100]) % ‘Zoom’ X-Axis
set(subplot(2,1,2), 'XLim',[0 100]) % ‘Zoom’ X-Axis
IIR filters have the advantage if being shorter than FIR filters, important with shorter data vectors. For your application, I would use the Chebyshev Type II IIR filter.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!