Error using filtfilt.m, 'Input arguments must be 'double''

I have an EEG .txt data file with 372000 columns and 128 rows, to 4 precision points. I need to load one row at a time and check the spectrum for each channel/row and if it detects > 5dB periodic 50 Hz noise it filters that channel and only that channel. I know I should use notch filter and I have gotten so far (but it does not function):
b1 = fir1(4,[0.4 0.43],'stop');
b2 = fir1(4,[0.01 0.99],'bandpass');
E1 = filtfilt(b1,1,EEG);
E = filtfilt(b2,1,E1);
fspec = fdesign.notch('N,F0,Q,Ap',6,0.1,10,5);
d = design(fspec,'IIR');
Ntchd = filter(d,E1);

 채택된 답변

Walter Roberson
Walter Roberson 2016년 12월 6일
Try
E1 = filtfilt(b1, 1, double(EEG) );

댓글 수: 9

Thank for your reply. I tried double(EEG) before but then I have a different error message:
Error using fdesign.abstracttype/superdesign (line 95)
There are no FIR designs for specification type: 'N,F0,Q,Ap'.
Error in fdesign.abstracttype/design (line 13)
varargout{1} = superdesign(this, varargin{:});
Error in EEG_filter (line 52)
d = design(fspec,'FIR');
I notice your original code used design(fspec,'IIR') but the error message is for design(fspec,'FIR') ?
Well, I changed it in the meanwhile but with none of them works.
Jan
Jan 2016년 12월 8일
편집: Jan 2016년 12월 8일
@Emoke: When you only claim, that it "does not work", you do not give us any chance to help you. If you need help, please provide any details. Does it not work, because you have plugged out the computer from your wall socket, because you need it for your boiler to make a good calming cup of tea? Why do you simply change the filter from "FIR" to "IIR"? This is not only another name, but a completely different job.
Dear Jan,
You are right, let's shed more light onto the problem. I am having trouble with the following actually:
1) the .txt file contains data (all up to 4 decimal points like 1234.5678) in 128 rows and 372000 columns, separated by tabs. I need to read the data row by row before I apply the filter. I'm having trouble designing this because dlmread did not allow /t to be a delimiter. 2) once the (i)th line is read into variable EEG, I want to apply the filter I have posted in my question. It should check if there is >5db noise between 48 and 52 Hz. If yes, the channel (row) should be filtered. 3) once filtered, I want to save this line to the txt file before moving to the next line (loop from 1 to 128).
Maybe I did not get the first line of data correctly into array EEG and this is why the filter doesn't work. The last error message, after trying many things, was "there are no FIR designs for specification type N,F0,Q,Ap in the fdesign part.
Any help is much appreciated.
dlmread allows '\t' as delimiter. Also if you have R2013b or later, you could use readtable()
I used
EEG = rand(1,1000);
and ran your code that you posted in your Question and did not receive an error. Perhaps you are using an older MATLAB version? What release are you using?
Now I tried using textscan to read my data form the .txt file into variable EEG:
fileID = fopen('gtre_001.txt');
for i=1:5
eeg = textscan(fileID,'%.4f',5,'Delimiter','\t');
disp(eeg)
end
fclose(fileID)
This is what I got:
[5×1 double]
[5×1 double]
[5×1 double]
[5×1 double]
[5×1 double]
ans =
0
Please help how to read the .txt file.
ncol = 372000;
fmt = repmat('%f', 1, ncol);
fileID = fopen('gtre_001.txt');
for row = 1 : 128
eeg_cell = textscan(fileID, fmt, 1, 'Delimiter', '\t', 'CollectOutput', 1);
fprintf('Read row %d\n', row);
Process_a_Row(row, eeg_cell{1});
end
fclose(fileID)
Here, Process_a_Row would be the code you want to do for each row, such as the filtering. I pass in the row number in case you want to write each row to an output file using the row number as part of the file name.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by