Matlab Audio Filter with changing Frequency

5 visualizaciones (últimos 30 días)
Hans Buchele
Hans Buchele el 30 de Nov. de 2022
Comentada: Mathieu NOE el 9 de Dic. de 2022
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 comentarios
Hans Buchele
Hans Buchele el 1 de Dic. de 2022
Hey Mathieu, thanks! Glad to have you on board!

Iniciar sesión para comentar.

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 1 de Dic. de 2022
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 comentarios
Mathieu NOE
Mathieu NOE el 9 de Dic. de 2022
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

Iniciar sesión para comentar.

Más respuestas (1)

jibrahim el 30 de Nov. de 2022
Hi Hans,
Take a look at dsp.VariableBandwidthFIRFilter or dsp.VariableBandwidthIIRFIlter. They both support bandpass tunable filters.


Más información sobre Audio Processing Algorithm Design en Help Center y File Exchange.




Community Treasure Hunt

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

Start Hunting!

Translated by