Freqz Command Resulting in Position 1 Invalid Index

조회 수: 4 (최근 30일)
Anthony Koning
Anthony Koning 2022년 10월 25일
편집: Jan 2022년 10월 25일
Hi, I was wondering if someone could review my code an explain what is causing the error message in my freqz command. The error message is claiming that index in position 1 is invalid and that array indices must be positive or local, but I don't see what's causing the issue. If someone could help me figure out what the error is, I would be very appreciattive
clc
w1 = 0.35;
w2 = 0.65;
n = 1024;
freqz = linspace(0,1,n);
for order = [16 32 64 128 256];
bp = fir1(order, [w1 w2], 'bandpass');
f = freqz(bp, 1, n);
magn_dB = 20*log10(abs(f));
plot [freqz, magn_dB, DisplayName, ['Order' num2str(order)];
hold on ;
end
Index in position 1 is invalid. Array indices must be positive integers or logical values.

'freqz' appears to be both a function and a variable. If this is unintentional, use 'clear freqz' to remove the variable 'freqz' from the workspace.
legend('Location', 'South');
grid on
xlabel('Normalized Frequency, \omega')
ylabel ('Magnitude, dB')
title('Effect of Increasing Filter Order')

답변 (1개)

Jan
Jan 2022년 10월 25일
편집: Jan 2022년 10월 25일
The problem is mentioned in the error message already:
"'freqz' appears to be both a function and a variable. If this is unintentional, use 'clear freqz' to remove the variable 'freqz' from the workspace."
After this line:
freqz = linspace(0,1,n);
freqz is a vector, not a function anyore.
What is the purpose of this line:
plot [freqz, magn_dB, DisplayName, ['Order' num2str(order)];
Do you mean:
plot(freqz, magn_dB, 'DisplayName', ['Order' num2str(order)]);
% ^^^^^ see above

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by