Hi @S,
Please see updated code snippet below, please customize your modified code plots based on your preferences. Please see brief summary of code snippet below along with your modified code snippet.
% Parameters
fs = 16e3;
t = 0:(1/fs):0.03;
t = t(:); % ensure column vector
numFilts = 32;
signal_freq = 100; % frequency of input signal
range = [50 8000];
gammaFiltBank = gammatoneFilterBank(range, numFilts, fs); % set fs explicitly
% Generate input signal
A = 1;
input_signal = A * sin(2 * pi * signal_freq * t);
% Get the center frequencies of the filters
CenterFreqs = getCenterFrequencies(gammaFiltBank);
% Process the input signal through the selected filters
output_signal = gammaFiltBank(input_signal);
% Plot individual filter responses with center frequencies on the y-axis
figure;
for i = 1:numFilts
subplot(numFilts, 1, i);
plot(t, output_signal(:, i));
title(['Filter Response - Center Freq: ', num2str(CenterFreqs(i)), ' Hz']);
if i == numFilts
xlabel('Time (s)');
end
ylabel('Amplitude');
grid on;
end
% Sum up the responses of all filters
combined_response = sum(output_signal, 2);
% Plot the combined response along with individual filter responses
figure;
for i = 1:numFilts
subplot(numFilts+1, 1, i);
plot(t, output_signal(:, i), 'Color', [0.8 0.8 0.8]); % Individual filter responses
ylabel(['Amplitude - Filter ', num2str(i)]);
end
subplot(numFilts+1, 1, numFilts+1);
plot(t, combined_response, 'k', 'LineWidth', 2); % Combined response
xlabel('Time (s)');
ylabel('Amplitude - Combined');
title('Combined Response and Individual Filter Responses');
% Display contribution of each filter to the combined response
figure;
bar(CenterFreqs, sum(output_signal, 1), 'b');
xlabel('Center Frequency (Hz)');
ylabel('Contribution to Combined Response');
title('Filter Contribution to Combined Response');
Please see attached.
Brief summary of code snippet
*The initial section of the code sets up parameters such as the sampling frequency fs, time vector t, number of filters numFilts, signal frequency signal_freq, frequency range range, and initializes the gammatone filter bank gammaFiltBank.
*An input sinusoidal signal is generated with a specific amplitude A and frequency signal_freq over the time vector t.
*The function getCenterFrequencies is used to extract the center frequencies of the gammatone filters in the bank.
*The input signal is processed through the gammatone filter bank using the gammaFiltBank function, resulting in output_signal, which contains the responses of each filter.
*A figure is created to display the responses of each filter individually over time. Each subplot represents a filter response with its corresponding center frequency.
*The responses of all filters are summed up to create a combined_response that represents the combined output of the filter bank.
*Another figure is generated to show the combined response along with the individual filter responses. The combined response is plotted in a separate subplot with a thicker line for clarity.
*A bar graph is plotted to illustrate the contribution of each filter to the combined response. The x-axis represents the center frequencies of the filters, and the y-axis shows the contribution values.