## Find the closest freq in a filterbank

I am using a filter bank to run different freq signals through. I am trying to make it more efficient (to not have to use all the filters every time) so I am trying to find a way to specify in my code to only use the 3 filters with the closest center frequency to the input. Right now I am only able to input the filter numbers I want manually (with filter_number). I am not sure how I would change this. I was trying to use the ‘find’ function but was only able to make it work using freq not filter numbers. Like this:

indf = find(CenterFreqs<signal_freq)

How can I chnage something like the above line to instead use filter number in my code below?Thank you for your time!

%Parameters

fs = 16e3;

t = 0:(1/fs):0.03;

t = t(:); % ensure column vector

numFilts = 32;

filter_number = 10;

range = [50 8000];

gammaFiltBank = gammatoneFilterBank(range,numFilts,fs); % set fs explicity

input_signal = sin(2*pi*100*t)

output_signal = gammaFiltBank(input_signal);

figure %1

stem(t,output_signal(:,filter_number));

title(sprintf(‘Output of Filter %d’,filter_number))

figure

impulse_input = 0*t;

impulse_input(1) = 1;

reset(gammaFiltBank); % IMPORTANT!

yimp = gammaFiltBank(impulse_input);

%Add together outputs of specific filters

filter_number2=12;

Add1=yimp(:,filter_number);

Add2=yimp(:,filter_number2);

Total=Add1 + Add2;

stem(t,Total)

title(sprintf(‘Impulse of %d plus %d’,filter_number,filter_number2))I am using a filter bank to run different freq signals through. I am trying to make it more efficient (to not have to use all the filters every time) so I am trying to find a way to specify in my code to only use the 3 filters with the closest center frequency to the input. Right now I am only able to input the filter numbers I want manually (with filter_number). I am not sure how I would change this. I was trying to use the ‘find’ function but was only able to make it work using freq not filter numbers. Like this:

indf = find(CenterFreqs<signal_freq)

How can I chnage something like the above line to instead use filter number in my code below?Thank you for your time!

%Parameters

fs = 16e3;

t = 0:(1/fs):0.03;

t = t(:); % ensure column vector

numFilts = 32;

filter_number = 10;

range = [50 8000];

gammaFiltBank = gammatoneFilterBank(range,numFilts,fs); % set fs explicity

input_signal = sin(2*pi*100*t)

output_signal = gammaFiltBank(input_signal);

figure %1

stem(t,output_signal(:,filter_number));

title(sprintf(‘Output of Filter %d’,filter_number))

figure

impulse_input = 0*t;

impulse_input(1) = 1;

reset(gammaFiltBank); % IMPORTANT!

yimp = gammaFiltBank(impulse_input);

%Add together outputs of specific filters

filter_number2=12;

Add1=yimp(:,filter_number);

Add2=yimp(:,filter_number2);

Total=Add1 + Add2;

stem(t,Total)

title(sprintf(‘Impulse of %d plus %d’,filter_number,filter_number2)) I am using a filter bank to run different freq signals through. I am trying to make it more efficient (to not have to use all the filters every time) so I am trying to find a way to specify in my code to only use the 3 filters with the closest center frequency to the input. Right now I am only able to input the filter numbers I want manually (with filter_number). I am not sure how I would change this. I was trying to use the ‘find’ function but was only able to make it work using freq not filter numbers. Like this:

indf = find(CenterFreqs<signal_freq)

How can I chnage something like the above line to instead use filter number in my code below?Thank you for your time!

%Parameters

fs = 16e3;

t = 0:(1/fs):0.03;

t = t(:); % ensure column vector

numFilts = 32;

filter_number = 10;

range = [50 8000];

gammaFiltBank = gammatoneFilterBank(range,numFilts,fs); % set fs explicity

input_signal = sin(2*pi*100*t)

output_signal = gammaFiltBank(input_signal);

figure %1

stem(t,output_signal(:,filter_number));

title(sprintf(‘Output of Filter %d’,filter_number))

figure

impulse_input = 0*t;

impulse_input(1) = 1;

reset(gammaFiltBank); % IMPORTANT!

yimp = gammaFiltBank(impulse_input);

%Add together outputs of specific filters

filter_number2=12;

Add1=yimp(:,filter_number);

Add2=yimp(:,filter_number2);

Total=Add1 + Add2;

stem(t,Total)

title(sprintf(‘Impulse of %d plus %d’,filter_number,filter_number2)) filter, loop MATLAB Answers — New Questions