Error in fir1 (line 115) Wind = chkwindow(Wind,L);
22 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Star Strider
2017-3-10
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 个评论
afef
2017-3-10
编辑:Star Strider
2017-3-10
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
2017-3-10
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.
afef
2017-3-10
ok i will try it. i use the low pass FIR filter just for smothing the signal and in the next stage i have the DWT 4DB so it will continue the filtering i guesss. I appriciate your help
Star Strider
2017-3-10
My pleasure.
I have not done anything with wavelets recently, but I do have the Wavelet Toolbox.
afef
2017-3-15
编辑:Star Strider
2017-3-15
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
2017-3-15
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.)
afef
2017-3-15
i really appericiate your help but i tried to use a = filtfilt(d1, deriv1); but when i plot it i got this and i thought that's not correct. thank you again
Star Strider
2017-3-15
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.
afef
2017-3-15
I want just ask you another question please I have to extract some statistical feature: variance, mean,standard deviation,frequency, maximum amplitude, minimum amplitude and energy from my signal but i could't find any function to do it . thans again .
Star Strider
2017-3-15
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
2017-3-21
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
2017-3-21
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
2017-3-21
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
2017-3-21
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
2017-3-24
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
2017-3-24
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 EEG/MEG/ECoG 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)