Apply Filter to Signal

11 ビュー (過去 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 Center および File ExchangeAudio Processing Algorithm Design についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by