Loop outputting deleted object?
이전 댓글 표시
I am trying to add a loop that plots each filters output, but am getting an error that I do not understand. Its the last loop trying to make figure 4. Thank you for your time!
close all
clear all
fs = 20e3;
numFilts = 32; %
% BW = 100; %Filter Bandwidth
filter_number = 5;
order = 4;
CenterFreqs = logspace(log10(50), log10(8000), numFilts);
% CF1 = CenterFreqs - BW/2; %Lower cutoff frequency
% CF2 = CenterFreqs + BW/2; %Upper cutoff frequency
% t = linspace(0,2*pi,200);
% input = sin(t) + 0.25*rand(size(t));
figure(1)
hold on
for ii = 1:filter_number
IR = gammatone(order, CenterFreqs(ii), fs);
[tmp,f] = freqz(IR,1,1024*2,fs);
% scale the IR amplitude so that the max modulus is 0 dB
a = 1/max(abs(tmp));
% % or if you prefer - 3dB
% g = 10^(-3 / 20); % 3 dB down from peak
% a = g/max(abs(tmp));
IR = IR*a;
[h{ii},f] = freqz(IR,1,1024*2,fs); % now store h{ii} after amplitude correction
plot(IR)
end
title('Impulse Response');
hold off
figure(2)
hold on
for ii = 1:filter_number
plot(f,20*log10(abs(h{ii})))
end
title('Bode plot');
set(gca,'XScale','log');
xlabel('Freq(Hz)');
ylabel('Gain (dB)');
figure(3)
zer = -0.5; %Zero location
pol = 0.9*exp(j*2*pi*[-0.3 0.3]'); %complex pole location
zplane(zer,pol)
[b,a] = zp2tf(zer,pol,1); %Convert poles to transfer function form
fvtool(b,a)
fvtool(b,a,'Analysis','polezero')
zplane(b,a) %zplane finds roots of numerator and denominator using the roots function
figure(4)
hold on
for ii = 1:filter_number
output(ii,:) = gammatone(input, CenterFreqs(ii), fs);
plot(output(ii,:))
LEGs{ii} = ['Filter # ' num2str(ii)]; %assign legend name to each
legend(LEGs{:})
legend('Show')
end
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function IR = gammatone(order, centerFrequency, fs)
% Design a gammatone filter
earQ = 9.26449;
minBW = 24.7;
% erb = (centerFrequency / earQ) + minBW;
erb = ((centerFrequency/earQ)^order + (minBW)^order)^(1/order);% we use the generalized
% function (depending on order)
% B = 1.019 .* 2 .* pi .* erb; % no, the 3pi factor is implemented twice in your code
B = 1.019 * erb;
% g = 10^(-3 / 20); % 3 dB down from peak % what is it for ? see main code above
f = centerFrequency;
tau = 1. / (2. .* pi .* B);
% gammatone filter IR
t = (0:1/fs:10/f);
temp = (t - tau) > 0;
% IR = (t.^(order - 1)) .* exp(-2 .* pi .* B .* (t - tau)) .* g .* cos(2*pi*f*(t - tau)) .* temp;
IR = ((t - tau).^(order - 1)) .* exp(-2*pi*B*(t - tau)).* cos(2*pi*f*(t - tau)) .* temp;
end
Error:
Error using te11
Invalid or deleted object.
댓글 수: 7
Dyuman Joshi
2024년 2월 26일
There is no variable named te11 in the code above.
Share the full error message i.e. all of the red text, and provide a code (and any corresponding data required) that can be ran to reproduce the error, thus allowing us to provide suggestions/solutions accordingly.
Also, do not use builtin function names as names for variables (or scripts for that matter), the function in question is input. Rename the variable to something else.
S
2024년 2월 26일
S
2024년 2월 26일
S
2024년 2월 26일
S
2024년 2월 26일
Walter Roberson
2024년 2월 26일
Start by doing
clear t226
at the command line, to get rid of the variable that is shadowing the file.
Note:
You should rarely have
clear all
in your code. Instead, explicitly initialize variables.
채택된 답변
추가 답변 (1개)
Image Analyst
2024년 2월 26일
0 개 추천
>> test5
Error using input
Not enough input arguments.
Error in test5 (line 49)
output(ii,:) = gammatone(input, CenterFreqs(ii), fs);
Do not use "input" as the name of your variable in your argument list. It is the name of a built-in function and it requires input argument, just like the error said. Call it something else, like order instead of input.
카테고리
도움말 센터 및 File Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






