このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
ゼロ位相フィルター処理
周波数 1 kHz で 3 dB のローパス バタワース フィルターを設計し、レート 20 kHz でサンプリングしたデータにゼロ位相フィルター処理を実装します。
type myZerophaseFilt.m
function output = myZerophaseFilt(input) %#codegen [B,A] = butter(20,0.314); output = filtfilt(B,A,input); end
codegen を使用して、myZerophaseFilt.m
の MEX ファイルを作成します。
codegen myZerophaseFilt -args {zeros(1,20001)} -o myZerophaseFilt_mex -report
Code generation successful: To view the report, open('codegen/mex/myZerophaseFilt/html/report.mldatx')
ノイズを含む正弦波信号をフィルターへの入力として生成します。
Fs = 20000; t = 0:1/Fs:1; comp500Hz = cos(2*pi*500*t); signal = comp500Hz + sin(2*pi*4000*t) + 0.2*randn(size(t));
MATLAB® と MEX の両方の関数を使用して、入力データをフィルター処理します。
FilteredData = myZerophaseFilt(signal); MexFilteredData = myZerophaseFilt_mex(signal);
500 Hz 成分とフィルター処理されたデータをプロットします。
tms = t*1000; plot(tms,comp500Hz) hold on plot(tms,MexFilteredData) plot(tms,FilteredData) hold off xlabel('Milliseconds') ylabel('Amplitude') axis([0 25 -1.8 1.8]) legend('500 Hz component','MEX','MATLAB')