How can I use a function file to filter noise from an EMG signal

8 ビュー (過去 30 日間)
Jennifer Miller
Jennifer Miller 2015 年 6 月 23 日
コメント済み: Star Strider 2015 年 6 月 23 日
I have written a script file which uses butterworth to filter my signal in the following way:
[b1,a1]=butter(5,[48/Fs*2, 52/Fs*2],'stop');
[b2,a2]=butter(5,300/Fs*2,'low');
[b3,a3]=butter(5,10/Fs*2,'high');
x = filter(b1,a1,EMG);
x1 = filter(b2,a2,x);
EMG_filtered = filter(b3,a3,x1);
This works well however as I have several different EMG signals to filter I would like to write a function which does this.
I am new to writing functions and as a first attempt tried the following:
function[EMG_filtered] = noise_removal(EMG)
Fs = 2000;
[b1,a1]=butter(5,[48/Fs*2, 52/Fs*2],'stop');
[b2,a2]=butter(5,300/Fs*2,'low');
[b3,a3]=butter(5,10/Fs*2,'high');
x = filter(b1,a1,EMG);
x1 = filter(b2,a2,x);
EMG_filtered = filter(b3,a3,x1);
This returned the error message: Undefined function 'noise_removal' for input arguments of type 'double'.
I can see the function saved in folder I am using so I dont think this is the issue.
I appreciate any help or advice
Thanks
  3 件のコメント
Jennifer Miller
Jennifer Miller 2015 年 6 月 23 日
Sorry this is the first time I have used the forum, I didn't realise you could do this.
Star Strider
Star Strider 2015 年 6 月 23 日
Suggestions:
You can combine the high-pass and low-pass filters into one band-pass design, saving steps in both the design and filtering.
Using the filtfilt function would prevent phase distortion that filter produces.

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

回答 (1 件)

Jan
Jan 2015 年 6 月 23 日
編集済み: Jan 2015 年 6 月 23 日
I can see the function saved in folder I am using so I don't think this is the issue.
But can MATLAB see this function?
Is the folder, which contains the M-file, part of your path? Is the M-file called "noise_removal.m"?
  3 件のコメント
Jan
Jan 2015 年 6 月 23 日
Matlab does not care about the file association of the operating system. Therefore you must have changed something else and repaired it by accident.
If the variable EMG_filtered is created inside the code, it is replied to the caller also. Either you call another version of your M-file or you did not save the file after editing. Please check:
which noise_removal -all
Jennifer Miller
Jennifer Miller 2015 年 6 月 23 日
Thank you for that helpful command. It returned only one version of the file and I checked that it has been saved

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

カテゴリ

Help Center および File ExchangeFilter Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by