How to integrate filter function into matlab code
12 views (last 30 days)
Show older comments
Ines Shekhovtsov
on 12 Dec 2022
Commented: Ines Shekhovtsov
on 13 Dec 2022
Hello,
I am trying to batch process a bunch of EMG files using a matlab code. Part of the processing is to filter all EMG data using a 6th order butterworth bandpass filter from 30 to 300 Hz. I used filterBuilder and created a variable 'Hbp' to process my first file. So in my code i just had:
RPbandpass=filter(Hbp,RP_ROI);
I clear the workspace after each file so i can no longer just reference Hbp without going through filter builder again. I looked into the code generation options of filterBuidlder where i can generate a function that returns filter as output or generate fuction that filters my data. Both of those gave me some code but i'm not sure how exactly to implement that into my main code file. I am guessing that i want to have a bandpassfilter function saved and stored in my matlab directory that my code can reference but not sure how to do that. Any other solutions or tips are welcome and thank you for your help in advance!
0 Comments
Accepted Answer
Bora Eryilmaz
on 12 Dec 2022
Edited: Bora Eryilmaz
on 12 Dec 2022
You can create the Butterworth filter directly and use it in your code without needing to store anything:
Fs = 2000; % Sampling rate 2000 Hz
bandPassRange = [30 300]; % in Hz.
% Note that the filter order will be 2 * 3.
[b,a] = butter(3, bandPassRange / (Fs/2), 'bandpass')
freqz(b,a,[],Fs)
You can learn more about it here: https://www.mathworks.com/help/signal/ref/butter.html
4 Comments
Bora Eryilmaz
on 13 Dec 2022
Edited: Bora Eryilmaz
on 13 Dec 2022
Save the above code as a MATLAB script into an M file and run it again next time you need it.
Alternatively, you can save the Hd object into a MAT file as a variable using the save command.
More Answers (0)
See Also
Categories
Find more on Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!