Add together two stem plots

25 次查看(过去 30 天)
S
S 2024-6-29,23:12
评论: Voss 2024-7-15,20:53
I am trying to add together stem plots. I am getting an error on using + to do this. I am unsure how I am meant to add them together as they work individually. I am trying to take Add1 and Add2 and add them in Total, then take the impulse using yimp and plot that result. Thank you for your time!
%Parameters
fs = 16e3;
t = 0:(1/fs):0.03;
t = t(:); % ensure column vector
numFilts = 32;
filter_number = 10;
range = [50 8000];
gammaFiltBank = gammatoneFilterBank(range,numFilts,fs); % set fs explicity
input_signal = sin(2*pi*100*t) + sin(2*pi*300*t);
output_signal = gammaFiltBank(input_signal);
figure %1
stem(t,output_signal(:,filter_number));
title('Output of Filter', num2str(filter_number))
impulse_input = 0*t;
impulse_input(1) = 1;
reset(gammaFiltBank); % IMPORTANT!
yimp = gammaFiltBank(impulse_input);
%Add together outputs of specific filters
filter_number2=12;
Add1=stem(t,output_signal(:,filter_number));
Add2=stem(t,output_signal(:,filter_number2));
Total=Add1 + Add2;
stem(t,yimp(:,Total))
title('Impulse of', num2str(filter_number), 'plus', num2str(filter_number2))

采纳的回答

Voss
Voss 2024-6-30,0:36
%Parameters
fs = 16e3;
t = 0:(1/fs):0.03;
t = t(:); % ensure column vector
numFilts = 32;
filter_number = 10;
range = [50 8000];
gammaFiltBank = gammatoneFilterBank(range,numFilts,fs); % set fs explicity
input_signal = sin(2*pi*100*t) + sin(2*pi*300*t);
output_signal = gammaFiltBank(input_signal);
figure %1
stem(t,output_signal(:,filter_number));
title(sprintf('Output of Filter %d',filter_number))
figure
impulse_input = 0*t;
impulse_input(1) = 1;
reset(gammaFiltBank); % IMPORTANT!
yimp = gammaFiltBank(impulse_input);
%Add together outputs of specific filters
filter_number2=12;
Add1=yimp(:,filter_number);
Add2=yimp(:,filter_number2);
Total=Add1 + Add2;
stem(t,Total)
title(sprintf('Impulse of %d plus %d',filter_number,filter_number2))
  2 个评论
S
S 2024-7-15,17:02
@Voss Thank you! Why am I not able to add them before I do impulse?
Voss
Voss 2024-7-15,20:53
You're welcome! This is adding two impulse responses.

请先登录,再进行评论。

更多回答(0 个)

类别

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