필터 지우기
필터 지우기

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 CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by