我试图绘制 2 个数字,使用 fplot 和 plot 函数,但是对于我的 plot (fig2),我得到一个错误并且不明白为什么;
错误使用/矩阵尺寸必须一致。
bhpfilter 错误(第 9 行) H = 3*g / ( (fo/f).^2 + 3*(fo/f)+3);
@(f)bhpfilter(f,fo,g) 中的错误
function [H] = bhpfilter(f, fo, g)
%freq finds the filter frequency response in V/V
%fo is the cut off frequency, f is the input frequency and g is the filter
%gain
if fo <= 0 || g <=0 %error checking
error('Inputs invalid');
else
H = 3*g / ( (fo/f).^2 + 3*(fo/f)+3);
end
fo=1200.;
g=2.;
H =@(f) bhpfilter(f,fo,g);
H_1 = @(f) bhpfilter (f,fo,g)-0.8;
figure (1);
fplot(H,[0 2000]);
title('Plot of H vs f using fplot');
xlabel('Frequency (Hz)');
ylabel('Filter frequency response (V/V)');
fprintf('The value of f that gives a response of 0.8 is %f Hz\n',fzero (H_1, [0 2000])); %placed this line of code here so that it can be visible in command window , showing it works
figure (2);
plot([0:2000],H([0:2000])); % code will find individual values of H(1), H(2) etc.. but will not find H([0:200])
title('Plot of H vs f using plot');
xlabel('Frequency (Hz)');
ylabel('Filter frequency response (V/V)');