フィルターのクリア

Quickest way to do a bandpass filter?

213 ビュー (過去 30 日間)
Louise Wilson
Louise Wilson 2023 年 1 月 9 日
コメント済み: Mathieu NOE 2023 年 1 月 9 日
I have a huge dataset of .wav files that I would like to bandpass filter.
Is the following the most time efficient way to do it..?
This filter takes about 2 minutes to run so it's quite time consuming with such a huge dataset.
[xbit, fs]=audioread(filename, [1*fs,120*fs]); %read in file from 1-120 secs
xbit=detrend(xbit);%removes DC offset
tic
xbit_filt=bandpass(xbit,[50 24000],fs);
toc

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 1 月 9 日
Hello Louise
welcome back and happy new year !
I made some speed comparison with your code and two other options using a butterworth digital filter , then using the function filter or filtfilt (filtering twice , forward and backward in time, for phase distorsion cancellation)
see my suggestion are much faster than using the bandpass function as in your code
I wonder why you put the low pass frequency at 24 kHz as this is already above the human hearing upper frequency limit...
at what sampling frequency are your wav files ?
with the my small audio file sampled at 11025 Hz , the differences are significant :
  • your code : Elapsed time is 1.574109 seconds.
  • my code with filter : Elapsed time is 0.016102 seconds.
  • my code with filtfilt : Elapsed time is 0.042606 seconds.
filename = 'test_voice_mono.wav' ;
% NB this file is sampled at 11025 Hz, so the bandpass filter cut off
% frequencies are modified (LPF : 24kHz => 2.4kHz)
[xbit, fs]=audioread(filename); %we don't know yet what if fs so I cannot define range = [1*fs,120*fs] as in your original code
samples = length(xbit);
start = 1*fs;
stop = min(120*fs,samples);
xbit=xbit(start:stop); % extract data for t = 1-120 secs
xbit=detrend(xbit);%removes DC offset
% your code
tic
xbit_filt=bandpass(xbit,[50 2400],fs);
toc
% good old butter bandpass filter (applied once)
tic
N = 2;
[B,A] = butter(N,[50 2400]/(fs/2));
xbit_filt = filter(B,A,xbit); % NB filter applies the filter once !
toc
% good old butter bandpass filter (applied twice)
tic
N = 2;
[B,A] = butter(N,[50 2400]/(fs/2));
xbit_filt = filtfilt(B,A,xbit); % NB filtfilt applies the filter twice !
toc
  6 件のコメント
Louise Wilson
Louise Wilson 2023 年 1 月 9 日
Thanks Mathieu for your brilliant and detailed answer.
I am just using the filter to get the 5th and 95th percentiles, median, and rms level of the file, then store those in an output. Got the loop sorted :-)
Mathieu NOE
Mathieu NOE 2023 年 1 月 9 日
ok
glad I could help !
all the best

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by