Figure Output blank but no errors

I am trying to plot the frequency response of all of the outputs as shown below, for some reason figure 2 is just blank. I have no errors so I am unsure what is wrong. Thanks for your time!
close all
fs = 20e3;
numFilts = 32;
filter_number = 5;
CenterFreqs = logspace(log10(50), log10(8000), numFilts);
t = linspace(0,2*pi,200);
input = sin(t) + 0.25*rand(size(t));
%
figure
hold on
for ii = 1:filter_number
output = gammatone(input, CenterFreqs(ii), fs);
plot(output)
end
Unrecognized function or variable 'gammatone'.
figure
[h{ii},f] = freqz(output(ii),1,4*8192,fs);

답변 (1개)

Aquatris
Aquatris 2024년 2월 3일
편집: Aquatris 2024년 2월 3일

0 개 추천

When you call freqz with outputs, it does not draw a plot as written on the description of the function. So you need to do
[h,w] = freqz(b,a,'whole',2001);
plot(w/pi,20*log10(abs(h))) % specific call to plot
as shown in the documentation. If you open the freqz function code and check line 174 (Matlab 2023a) you will also see it only plots if there are no output arguments.

댓글 수: 9

S
S 2024년 2월 4일
what is b and what is a? Also does freqz not already take care of the 20log10 abs part?
They are the basic inputs to the function. You called the freqz function with
[h{ii},f] = freqz(output(ii),1,4*8192,fs);
so just call
plot(f/pi,20*log10(abs(h{ii})))
and it should give you the plot for ii
S
S 2024년 2월 4일
I initially had the freqz line you just recommended and it gives a blank plot.
[h{ii},f] = freqz(output(ii),1,4*8192,fs);
plot(f/pi,20*log10(abs(h{ii})));
S
S 2024년 2월 4일
I was just testing higher filter_number values and for some reason they just give a singular flat horizontal line which is incorrect
Aquatris
Aquatris 2024년 2월 5일
Ye hard to tell since I dont know what your gammatone function does. What is inside the 'output' variable? Is it something expected?
Do you really have '1' as your denominator of interest?
Are you by any chance trying to find the frequency content, something like fft?
S
S 2024년 2월 5일
This is my function:
% Function for gammatone filter
function output = gammatone(input, centerFrequency, fs)
The output variable is what comes out of each individual filter. (The output of one filter is the input to the next)
Aquatris
Aquatris 2024년 2월 5일
Then if I understood it correctly, output variable contains a signal not the filter. However freqz function expects the numerator and denominator of a filter (transfer function). Are you trying to plot the fft of the output variable? Can you explain what you are trying to do and what you expect in the output variable again?
S
S 2024년 2월 5일
So I changes the line for output to this hoping it would fix it. What I want is for each output to be graphed. Since they are in cascade the output of one is the input to the next, so I am trying to plot all the outputs of every filter number. What I have below is not working though
output(ii,:) = gammatone(input, CenterFreqs(ii), fs);
plot(t,output(ii,:), 'LineWidth', 1.25)
Aquatris
Aquatris 2024년 2월 5일
Define not working? What do you expect and what is happenig? What do you have in output variable?
Are you sure your gammatone function works properly?
Be more specific otherwise no one can help you.

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

카테고리

도움말 센터File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

질문:

S
S
2024년 2월 3일

댓글:

2024년 2월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by