Filtering a signal out of multiple frequencies without for loop

14 ビュー (過去 30 日間)
ytzhak goussha
ytzhak goussha 2020 年 3 月 17 日
回答済み: Raunak Gupta 2020 年 3 月 19 日
Hello MATLABers,
I am trying to filter out a humming noise from my recordings. The noise has a frequency of 20kHz and it's harmonics (40,60,80 kHz).
I want to filter out all the noisy parts with one pass over the signal and the only solution I have managed to come up with is by removing each frequency with a for loop (see code). This takes a lot of time, I need to filter about 2 hours of audio recordings with 250k sampling rate.
My question is, is there a method to filter out all the desired frequencies in one pass instead of multiple passes to save computational time.
Fs = 250000; %Sampling rate
filtered =sig; %sig is a vector of the signal to be filtered
%The frequency of the noise to be filtered
onset = 19700;
offset = 20000;
times = [];
n=4; %Number of harmonics (n=1: 20, n=2: 40, n=3: 60, m=4: 80)
for k = 1:n
tic
%Is there a filter that can remove multiple bands at onces?
d = designfilt('bandstopiir','FilterOrder',2, ...
'HalfPowerFrequency1',onset*k,'HalfPowerFrequency2',offset*k, ...
'DesignMethod','butter','SampleRate',Fs);
filtered = filtfilt(d,filtered);
toc
times = [times,toc];
end

採用された回答

Raunak Gupta
Raunak Gupta 2020 年 3 月 19 日
Hi,
There is a similar question which is nicely explained by Star Strider, this can help you implement the multiband filter required here. It uses filtfilt.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMeasurements and Spatial Audio についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by