필터 지우기
필터 지우기

How to integrate filter function into matlab code

조회 수: 19 (최근 30일)
Ines Shekhovtsov
Ines Shekhovtsov 2022년 12월 12일
댓글: Ines Shekhovtsov 2022년 12월 13일
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!

채택된 답변

Bora Eryilmaz
Bora Eryilmaz 2022년 12월 12일
편집: Bora Eryilmaz 2022년 12월 12일
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')
b = 1×7
0.0383 0 -0.1149 0 0.1149 0 -0.0383
a = 1×7
1.0000 -4.1361 7.2416 -6.9952 3.9888 -1.2706 0.1717
freqz(b,a,[],Fs)
  댓글 수: 4
Bora Eryilmaz
Bora Eryilmaz 2022년 12월 13일
편집: Bora Eryilmaz 2022년 12월 13일
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.
Ines Shekhovtsov
Ines Shekhovtsov 2022년 12월 13일
Thank you. That's fairly simple!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by