How to denoise raw EEG data with MATLAB?

I made the program which would filter out the noise from raw EEG data, however, I could not implement the code. Could you please tell me what is wrong with this program? The program is down below.
function OutputEEG = MyEEGFilter(InputEEG,fs)
fs=SampleRate;
lowEnd = 3; % Hz
highEnd = 70; % Hz
filterOrder = 2; % Filter order (e.g., 2 for a second-order Butterworth filter). Try other values too
[b, a] = butter(filterOrder, [lowEnd highEnd]/(fs/2)); % Generate filter coefficients
d = designfilt('bandstopiir','FilterOrder',8, ...
'HalfPowerFrequency1',49,'HalfPowerFrequency2',51, ...
'DesignMethod','butter','SampleRate',fs);
InputEEG=double(InputEEG);
Foutput(1,:) = filtfilt(d,InputEEG(1,:));
Foutput(1,:) = filtfilt(b,a,Foutput(1,:));
end

3 件のコメント

Nick
Nick 2018 年 11 月 11 日
Could you specify what errors you are getting? My first guess would be that your error is "output variable OutputEEG was not assigned"?
I assumed this as OutputEEG was not assigned anywhere (maybe you wanted Foutput to be OutputEEG? If that is the case just change one of the variable names and it should give an output). If you were getting another error or problem. Please specify the problem a bit more
ABCDEEG
ABCDEEG 2018 年 11 月 12 日
Thank you for answering my question. Yes, your assuming is correct, so I defined OutputEEG like {OutputEEG = Foutput;} in the bottome of my code. But There is an error like {function OutputEEG = MyEEGFilter(InputEEG,fs) ↑ Error: Function definitions are not permitted in this context.}. What should I do next, please? Actually I'm not good at programming such as Matlab.
Nick
Nick 2018 年 11 月 13 日
Did you put your function in a seperate .m file? You cannot call a function straight from the command window, that could be the cause of this new error.

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2018 年 11 月 11 日

0 投票

How are you calling it? And attach InputEEG and fs in a .mat file so we can call it ourselves with your data. And be sure to define OutputEEG. Maybe it's as simple as
OutputEEG = Foutput;
As the last line of your program.

1 件のコメント

ABCDEEG
ABCDEEG 2018 年 11 月 12 日
Thank you for answering my question. I corrected the definition of OutputEEG as you pointed out. Also, I tried to attach zip file of my InputEEG data, however, I couldn't send it to you because it exceeds more than 5 MB. Attached is .mat file of EEG information like sample rate.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEEG/MEG/ECoG についてさらに検索

質問済み:

2018 年 11 月 9 日

コメント済み:

2018 年 11 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by