- 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.
Quickest way to do a bandpass filter?
181 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Louise Wilson
am 9 Jan. 2023
Kommentiert: Mathieu NOE
am 9 Jan. 2023
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
0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 9 Jan. 2023
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 :
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Filter Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!