Effacer les filtres
Effacer les filtres

Impulse Response of a Filter

5 vues (au cours des 30 derniers jours)
S
S le 17 Jan 2024
Commenté : S le 17 Jan 2024
I am trying to get the impulse response of a filter in a gammatone filterbank. For a filter (in the gammatone filterbank) the impulse response has to decay over time. But I am not getting that and I am unsure what I am doing in coreectly. Thank you for your time!
fs = 16e3;
t = 0:(1/fs):1;
numFilts=32;
range=[50 8000];
gammaFiltBank = gammatoneFilterBank(range,numFilts);
%fvtool(gammaFiltBank)
input_signal = sin(2*pi*100*t) + sin(2*pi*300*t);
%output_signal = gammatoneFilterBank(gammaFiltBank, input_signal);
output_signal = gammaFiltBank(input_signal);
output_signal = squeeze(output_signal);
%Display a Filter's Output
figure
filter_number=10;
plot(t,output_signal(filter_number,:)) %10th filter output
title('Output of Filter', num2str(filter_number))
% Impulse signal
impulse_signal = zeros(size(t));
impulse_signal(1) = 1;
%Display a Filter's Output of Impulse
output_signal2=gammaFiltBank(impulse_signal);
output_signal2 = squeeze(output_signal2);
figure
plot(t,output_signal2(10,:)) %10th filter output
title('Impulse Output of Filter', num2str(filter_number))

Réponse acceptée

Drew
Drew le 17 Jan 2024
Modifié(e) : Drew le 17 Jan 2024
The problem in your code is that the input signal should be a column vector, that is, Nx1. When that is done, there is no need for the "squeeze" statements.
When you input a row vector of size 1x16001 to the gammaFiltBank in the line "output_signal = gammaFiltBank(input_signal)", that row vector gets interpreted as a matrix with 16001 independent channels, where each channel has a signal length of just one sample. When each input signal has only one sample, then each output signal only has one sample of output, and that is why there is no "tail" visible in the impulse response.
To fix this, convert inputs to column vector, remove "squeeze" functions, and fix the order of the indexing into the output_signal and output_signal2. Your slightly modified code is below, and the plots are as expected.
fs = 16e3;
% t = 0:(1/fs):1;
t = 0:(1/fs):0.05; % focus on first 50 ms of output, rather than 1 second.
%% Important
t=t(:); % ensure t is a column vector
numFilts=32;
range=[50 8000];
gammaFiltBank = gammatoneFilterBank(range,numFilts);
% Sum of sinusoids input
input_signal = sin(2*pi*100*t) + sin(2*pi*300*t); % This is column vector now that t is
output_signal = gammaFiltBank(input_signal);
% output_signal = squeeze(output_signal); % not needed
% Display a Filter's Output
figure
filter_number=10;
% plot(t,output_signal(filter_number,:)) % need to fix indexing
% Need to reverse indices of output_signal, now that input_signal was column vector
plot(t,output_signal(:, filter_number)) %10th filter output
title('Output of Filter', num2str(filter_number))
% Impulse signal
impulse_signal = zeros(size(t)); % This is column vector because t is
impulse_signal(1) = 1;
% Display a Filter's Output of Impulse (impulse response)
reset(gammaFiltBank); % Important to reset after previous signal
output_signal2=gammaFiltBank(impulse_signal);
% output_signal2 = squeeze(output_signal2); % not needed.
figure
% plot(t,output_signal2(10,:)) % need to fix indexing as in line below
% Need to reverse indices of output_signal, now that input_signal was column vector
plot(t,output_signal2(:,10))
title('Impulse Output of Filter', num2str(filter_number))
If this answer helps you, please remember to accept the answer.
  1 commentaire
S
S le 17 Jan 2024
Thank you! To use freqz on the input signal coud I do freqz(output_signal)?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Audio Processing Algorithm Design dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by