Apply Filter to Signal

조회 수: 10 (최근 30일)
S
S 2024년 1월 16일
댓글: S 2024년 1월 18일
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)
Error using gammatoneFilterBank/fvtool
This functionality is not available on remote platforms.
input_signal = sin(2*pi*100*t) + sin(2*pi*300*t);
output_signal = gammatoneFilterBank(gammaFiltBank, input_signal);
impulse_response = impulse(output_signal);

채택된 답변

Paul
Paul 2024년 1월 17일
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
S
S 2024년 1월 18일
That was very helpful! Thanks!
S
S 2024년 1월 18일
To get the power of each filter to then turn this into a spectrogram, would I square the output signal in each filter then add them together?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Hassaan
Hassaan 2024년 1월 16일
  1. Generation of input_signal: The time vector t is not defined in your code. You need to define it to generate input_signal.
  2. 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.
  3. 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
S
S 2024년 1월 16일
Yes, what you have shown is the fvtool not the plot of the impulse response
S
S 2024년 1월 16일
Are you able to get the impluse response plot on your end?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by