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; % Sampling frequency set to 16 kHz t = 0:(1/fs):0.03; % Time vector from 0 to 0.03 seconds with increments of 1/fs t = t(:); % Ensure the time vector is a column vector for consistent matrix operations
numFilts = 32; % Number of filters in the filter bank signal_freq = 100; % Frequency of the input signal set to 100 Hz range = [50 8000]; % Frequency range for the filter bank from 50 Hz to 8000 Hz
% Create a Gammatone filter bank with specified range, number of filters, and sampling frequency gammaFiltBank = gammatoneFilterBank(range, numFilts, fs);
% Generate input signal A = 1; % Amplitude of the input signal input_signal = A * sin(2 * pi * signal_freq * t); % Generate a sinusoidal input signal based on the specified frequency and amplitude
% Get the center frequencies of the filters CenterFreqs = getCenterFrequencies(gammaFiltBank); % Retrieve the center frequencies of the filters in the filter bank
% Process the input signal through the selected filters output_signal = gammaFiltBank(input_signal); % Apply the filter bank to the input signal to obtain the output signal
% Plot individual filter responses with center frequencies on the y-axis figure; % Create a new figure for plotting for i = 1:numFilts % Loop through each filter subplot(numFilts, 1, i); % Create a subplot for each filter response plot(t, output_signal(:, i)); % Plot the output signal for the current filter title(['Filter Response - Center Freq: ', num2str(CenterFreqs(i)), ' Hz']); % Set the title to indicate the center frequency of the filter if i == numFilts % Check if it is the last filter xlabel('Time (s)'); % Label the x-axis for the last subplot end ylabel('Amplitude'); % Label the y-axis for each subplot grid on; % Enable grid for better visualization end
% Sum up the responses of all filters combined_response = sum(output_signal, 2); % Sum the output signals across all filters to get the combined response
% Plot the combined response along with individual filter responses figure; % Create a new figure for the combined response plot for i = 1:numFilts % Loop through each filter subplot(numFilts+1, 1, i); % Create a subplot for each individual filter response plot(t, output_signal(:, i), 'Color', [0.8 0.8 0.8]); % Plot the individual filter responses in light gray ylabel(['Amplitude - Filter ', num2str(i)]); % Label the y-axis for each subplot with filter number end
subplot(numFilts+1, 1, numFilts+1); % Create a subplot for the combined response plot(t, combined_response, 'k', 'LineWidth', 2); % Plot the combined response in black with increased line width xlabel('Time (s)'); % Label the x-axis for the combined response subplot ylabel('Amplitude - Combined'); % Label the y-axis for the combined response subplot title('Combined Response and Individual Filter Responses'); % Set the title for the combined response plot
% Display contribution of each filter to the combined response figure; % Create a new figure for the filter contribution plot bar(CenterFreqs, sum(output_signal, 1), 'b'); % Create a bar graph showing the contribution of each filter to the combined response xlabel('Center Frequency (Hz)'); % Label the x-axis for the contribution plot ylabel('Contribution to Combined Response'); % Label the y-axis for the contribution plot title('Filter Contribution to Combined Response'); % Set the title for the contribution plot
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.