Matlab Audio Filter with changing Frequency

조회 수: 4(최근 30일)
Hans Buchele
Hans Buchele 2022년 11월 30일
댓글: Mathieu NOE 2022년 12월 9일
Dear Matlab Community, I am working on project where I need to be able to filter/extract a frequency band which should be „tuneable“ over time. For example: I am interested in the frequency range 220 to 240 for 0.5 seconds, then the range should gradually go up to 320 to 340 in 1 second. Ideal would be a solution similar to an envelope where time and frequency can be inserted. There is modern audio software, where it is possible to draw a selection and then export that as an audio file but I am looking for an automated solution since I need to do that many hundreds time. Any help is much appreciated thanks!
  댓글 수: 2
Hans Buchele
Hans Buchele 2022년 12월 1일
Hey Mathieu, thanks! Glad to have you on board!

댓글을 달려면 로그인하십시오.

채택된 답변

Mathieu NOE
Mathieu NOE 2022년 12월 1일
hello again
so this is a variable coefficient IIR implementation
I used a white noise as test signal, the output signal shows that the spectral content follows the time / frequency characteristics of the bandpass filter.
The for loop could be made faster with a custom made digital filter coefficients computation that will be faster than the call to the built in function butter
Fs = 2000;
x = randn(Fs*3,1); % 3 seconds duration signal (white noise)
[samples,channels] = size(x);
dt = 1/Fs;
time = (0:samples-1)*dt;
%% filter time / frequency characteristics
% 1/ fixed frequency range 220 to 240 for first 0.5 seconds,
stop_sample1 = round(0.5*Fs); % at this iteration value we change to variable IIR (for loop)
flow = 220;
fhigh = 240;
N = 4;
[B,A] = butter(N,2/Fs*[flow fhigh]);
nB = length(B);
nA = length(A);
yy = filter(B,A,x); % init output with fixed characteristics filter
% 2/ frequency ramp up 220 / 240 to 320 to 340 in 1 second.
flow2 = 320;
fhigh2 = 340;
freq_slope_low = (flow2-flow)/Fs /1; % the 1 is for 1 second.
freq_slope_high = (fhigh2-fhigh)/Fs /1; % the 1 is for 1 second.
% IIR filter for loop
y = yy; % init y for samples 1 to stop_sample1
for k = stop_sample1:samples % for iteration >= nB sample
flowk = min(flow2,flow + freq_slope_low*(k-stop_sample1)); % current flow at iteration k
fhighk = min(fhigh2,fhigh + freq_slope_high*(k-stop_sample1)); % current fhigh at iteration k
N = 4;
[B,A] = butter(N,2/Fs*[flowk fhighk]);
% main recursion
y(k) = B*x(k:-1:k-nB+1) - A(2:nA)*y(k-1:-1:k-nA+1);
NFFT = 512;
specgram(y,NFFT,Fs,hanning(NFFT),round(0.75*NFFT)) ;
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2022년 12월 9일
I supposed your hear glitches ? that is something I discovered later .... and finally ended up reading some good publications about the issues regarding time varying filters

댓글을 달려면 로그인하십시오.

추가 답변(1개)

jibrahim 2022년 11월 30일
Hi Hans,
Take a look at dsp.VariableBandwidthFIRFilter or dsp.VariableBandwidthIIRFIlter. They both support bandpass tunable filters.


Find more on Measurements and Spatial Audio in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by