Apply Filter to Signal
11 views (last 30 days)
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);
0 Comments
Accepted Answer
Paul
on 17 Jan 2024
I think this is the correct way to generate the output signal
fs = 16e3;
t = 0:(1/fs):1; % not defined in question
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);
The next step is "take that output and get the impulse response which should decay over time."
I don't understand this statement. Do you just want the impulse response of each filter in the bank? Are you trying to figure out the impulse response of each filter based on the output_signal and input_signal?
%impulse_response = impulse(output_signal);
10 Comments
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
See Also
Categories
Find more on Audio Processing Algorithm Design 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!