即時嘗試繪製2個數字,使用fplot和繪圖功能,但對於我的情節(圖2),我得到一個錯誤,不明白爲什麼;Matlab錯誤,矩陣尺寸不同意
錯誤使用/ 矩陣尺寸必須一致。 (行9) H = 3 * g /((fo/f)。^ 2 + 3 *(fo/f)+3);
錯誤@(F)bhpfilter(F,FO,克)
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 [email protected](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)');
上面的代碼是順便在2個不同的.m文件中 –