You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Error in fir1 (line 115) Wind = chkwindow(Wind,L);
22 views (last 30 days)
Show older comments
i'm trying to use low pass FIR filter for EEG siganl that i have downloded from http://physionet.org/physiobank/database/chbmit/ but i got this error message Error using fir1>chkwindow (line 290) The window length must be the same as the filter length.
Error in fir1 (line 115) Wind = chkwindow(Wind,L); my code is: load('C:\Users\del.dell-PC\Downloads\chb01_01_edfm.mat') x = plot(val(1,:)); Fs=200; t = linspace(0,1,Fs); fc = 32; Wn = (2/Fs)*fc; L =40; b = fir1(40,Wn,'low',hamming(L)); fvtool(b,1,'Fs',Fs) y = filter(b,1,x);
plot(t,x,t,y) xlim([0 0.1])
xlabel('Time (s)') ylabel('Amplitude') legend('Original Signal','Filtered Data')
how can i fix that and how can i define the downloded signal thank you
Accepted Answer
Star Strider
on 10 Mar 2017
In R2017a (and probably earlier versions), the hamming window is the default. You only need to specify it as:
Fs=200;
t = linspace(0,1,Fs);
fc = 32;
Wn = (2/Fs)*fc;
L =40;
b = fir1(40,Wn);
figure(1)
freqz(b, 1, 2^16, Fs)
I included the freqz call so you can see that it works. It is not necessary for the code, and can be deleted.
Remember to use the filtfilt function to do the actual filtering.
22 Comments
afef
on 10 Mar 2017
Edited: Star Strider
on 10 Mar 2017
thank you for your help i try this code and i think it works
clear all;
close all;
load('C:\Users\del.dell-PC\Downloads\chb01_01_edfm.mat')
figure (1), plot(val(1,:));legend('noisy EEG');
d1=designfilt('lowpassfir','PassbandFrequency',0.15,'StopbandFrequency',0.2,'PassbandRipple',3,'StopbandAttenuation',60,'DesignMethod','equiripple');
y = filtfilt(d1, val(1,:));
figure (2),
hold on;
plot(val(1,:));
plot(y,'LineWidth',2);
legend('Noisy EEG','Phase Filtering');
hold off;
figure (3),plot(y,'r');
legend('Phase Filtering');
i want to know your opinion about it
Star Strider
on 10 Mar 2017
My pleasure.
You need to specifically define and provide a value for 'SampleRate' in order for your filter to work correctly with your signal. Your code and the result otherwise look correct to me. (The sampling frequency, usually given as ‘Fs’, is the value for 'SampleRate'.)
First, see if adding the 'SampleRate' argument improves your filter performance. Then if you still have more high frequency noise than you want, experiment with decreasing the passband and stopband frequencies to further eliminate the high-frequency noise.
Star Strider
on 10 Mar 2017
My pleasure.
I have not done anything with wavelets recently, but I do have the Wavelet Toolbox.
afef
on 15 Mar 2017
Edited: Star Strider
on 15 Mar 2017
hi i should filter all the channel of EEG signal that i have download from physionet.org they told me that To convert from raw units to the physical units shown above, subtract 'base' and divide by 'gain'. but when i try to use the fir filter as you see in the code i got this error message Error using testdev2filtre (line 12) Input arguments must be 'double'. please i need your help and i have another question if you don't mind should i use the same filter for all the channel
thanks.
clc;
clear all;
close all;
load('C:\Users\del.dell-PC\pfe\base de donnée\patient sans crise\chb01_01_edfm.mat')
deriv1=(val(1,:)-0)/2.559375;
Fs=256;
t=(0:length(deriv1)-1)/Fs; %valeur du temps de tout échantillon%
figure (1),
y=plot(t,deriv1);
legend('FP1-F7');
d1=designfilt('lowpassfir','PassbandFrequency',0.15,'StopbandFrequency',0.2,'PassbandRipple',3,'StopbandAttenuation',60,'DesignMethod','equiripple');
a = filtfilt(d1,y);
figure (2),plot(a,'r');
legend(' FP1-F7 Filtré');
Star Strider
on 15 Mar 2017
The problem is that you are defining ‘y’ here:
y=plot(t,deriv1);
then filtering it here:
a = filtfilt(d1,y);
You have defined ‘y’ as a ‘plot handle’. You cannot filter a plot handle.
Try this::
a = filtfilt(d1, deriv1);
Filter all your EEG channels with the same filter. (If they are each column vectors in the same matrix, you can do it with one call to filtfilt with the filtfilt call I wrote here. See the documentaiton for filtfilt for details.)
Star Strider
on 15 Mar 2017
That appears to be correct. If that is not what you want, you may have to re-design your filter.
Remember that in your designfilt call, the frequencies are normalised on the closed interval [0,pi]. You have to divide the frequencies in Hz by the Nyquist frequency, that is ½ the sampling frequency, here 256/2=128 Hz.
Star Strider
on 15 Mar 2017
My pleasure.
With the exception of ‘frequency’ (I do not know what frequency you want), use the var, std, max, and min functions respectively.
Unless you are using a different definition, ‘energy’ is equivalent to amplitude. ‘Power’ is amplitude.^2.
You may also find the findpeaks function useful.
afef
on 21 Mar 2017
hi i have EEG signal,frequencies above 60 Hz are noise and can be neglected .Considering this value, the cut-off frequency of the low-pass FIR filter i used here was set to 64 Hz.the sampling frequency is 256 HZ . I need to know how to calculate the Filter Speci cations i mean : Passband Frequency, Stopband Frequency Passband Ripple, Stopband Attenuation
Star Strider
on 21 Mar 2017
First, if you want to pass only frequencies below 60 Hz, your lowpass filter passband has to be 59 Hz at most and your stopband frequency 60 Hz at most. You can do this with a IIR Chebyshev Type II filter, or a windowed FIR filter.
Second, the filter specifications are those you set depending on what you want the filter to do. There is probably no way to ‘calculate’ them, at least no way that I have ever discovered. You will probably have to experiment with them and adjust them to get a stable filter that meets your requirements.
afef
on 21 Mar 2017
ok, Actually the wavelet decomposition that i will use does not allow the extraction of specific frequency bands without additional filtering. Thus, in order to correlate the wavelet decomposition with the five sub-bands of the EEG signal,the frequency content segments of the EEG signal was restricted to the 0-64 Hz band by convolving the signal with a low-pass finite impulse response (FIR) filter.So when i try to design the FIR filter i want to know how to choose the suitable specifications.
thanks
Star Strider
on 21 Mar 2017
My pleasure.
Filter design is entirely up to you. If you know the result (output) you want from a specific suitably broadband input signal, you can create (actually ‘identify’) the filter using the Signal Processing Toolbox invfreqz function. (The separate System Identification Toolbox is entirely dedicated to this procedure.) That is the best you can do to get a specific design without having to provide the details of the filter you want, and even that requires that you specify (or in more practical terms, experiment with) the number of poles and zeros you want the final filter design to have.
afef
on 24 Mar 2017
please i want your help i want to know how to choose the value of the passsband ripple and the stopband attenuaion of a filter for example here PassbandRipple=3 and StopbandAttenuation=60 i want to know how did he choose this value or there is the formula to calculate ? d1=designfilt('lowpassfir','PassbandFrequency',0.45,'StopbandFrequency',0.5,'PassbandRipple',3,'StopbandAttenuation',60,'DesignMethod','equiripple');
Star Strider
on 24 Mar 2017
Those are design decisions based on what you want the filter to do. There are ways to calculate the optimal filter order (I refer you to any detailed text on signal processing for that discussion), the others are whatever you want them to be. This usually requires simulation to be certain the filter does what you want (for example using the freqz function), and some adjustments if necessary until it does.
More Answers (0)
See Also
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)