Freqz Command Resulting in Position 1 Invalid Index

1 回表示 (過去 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 Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by