Apply Filter to Signal
Show older comments
I want to use the built in gammatone filterbank and run a signal through it. I then want to take that output and get the impulse response which should decay over time. But I am running into issues. I think the output_signal line is the issue but I don't know what to use instead. Thank you for your time!
fs = 16e3;
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);
impulse_response = impulse(output_signal);
Accepted Answer
More Answers (1)
Hassaan
on 16 Jan 2024
- Generation of input_signal: The time vector t is not defined in your code. You need to define it to generate input_signal.
- Using gammatoneFilterBank: The way you're using gammatoneFilterBank to process input_signal is incorrect. You should use the process function on the filter bank object to process the input signal.
- Getting the Impulse Response: To obtain the impulse response, you should create an impulse signal and then process it through the gammatone filter bank. The impulse function is typically used for obtaining the impulse response of a system, but in MATLAB's Audio Toolbox, you'd need to manually create an impulse and pass it through the filter bank.
fs = 16e3; % Sampling frequency
numFilts = 3; % Number of filters
range = [50 8000]; % Frequency range
t = 0:1/fs:1; % Time vector, for 1 second
% Create a Gammatone filter bank
gammaFiltBank = gammatoneFilterBank('SampleRate', fs, 'NumFilters', numFilts, 'FrequencyRange', range);
fvtool(gammaFiltBank);
% Create input signal
input_signal = sin(2*pi*100*t) + sin(2*pi*300*t);
% Process the input signal through the Gammatone filter bank
output_signal = process(gammaFiltBank, input_signal');
% To get the impulse response, create an impulse signal
impulse_signal = [1; zeros(length(t)-1, 1)]; % A single '1' followed by zeros
% Process the impulse signal through the filter bank
impulse_response = process(gammaFiltBank, impulse_signal);
% You can plot the impulse response to see how it decays over time
plot(impulse_response);
xlabel('Samples');
ylabel('Amplitude');
title('Impulse Response of Gammatone Filter Bank');
In this code, impulse_signal is created as a single '1' followed by zeros, which represents an impulse. This impulse is then processed through the gammatone filter bank to get the impulse response. The response is plotted to visualize how it decays over time. Remember that process function is used with the filter bank object to process signals.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Feel free to contact me.
5 Comments
S
on 16 Jan 2024
I used and tested it on MATLAB r2023b on desktop[offline].
- MATLAB Audio Toolbox: This toolbox is essential for advanced audio processing. It includes functions and tools for audio signal processing, speech analysis, and acoustic measurement. It likely contains the gammatoneFilterBank function, or similar auditory filter bank functions, along with utilities for analyzing and processing audio signals.
- Signal Processing Toolbox: This toolbox is specifically geared towards audio and acoustic signals, the Signal Processing Toolbox provides a more general set of tools for signal processing, including filtering, windowing, spectral analysis, and statistical analysis, which can be helpful in conjunction with audio processing.
- MATLAB Version Compatibility: Ensure that your MATLAB version is compatible with these toolboxes. Newer functions in these toolboxes might not be available in older MATLAB versions.

-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Feel free to contact me.
S
on 16 Jan 2024
S
on 16 Jan 2024
S
on 16 Jan 2024
Categories
Find more on Measurements and Spatial Audio in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


