Not sure why my code isn't working. Please help
3 ビュー (過去 30 日間)
古いコメントを表示
I'm entering the following code and I cant seem to figure out why it won't run. Please help
%%%%%%%%%%%%%%%%******************%%%%%%%%%%%%%%
function [M,P]=fil_ters(R,C,f)% Function definition
w=2*pi*f;% Hz to rad/sec
G=1./(1j*w*R*C+1);% Transfer function
M=abs(G);% Magnitude
P=angle(G);% Phase
end
R=1000;% Resistance value
fc=10e3;% Cutoff frequency
C=1/(2*pi*R*fc);% Capacitance value
f=1:100000;% Frequency axis
[M,P]=fil_ters(R,C,f);%Function call
subplot(2,1,1);
semilogx(f,M);% Plot magnitude
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude plot');
grid;
subplot(2,1,2);
semilogx(f,rad2deg(P));% Plot phase
xlabel('Frequency');
ylabel('Phase(degree)');
title('Phase plot');
grid;
%%%%%%%%%%%%%%%%******************%%%%%%%%%%%%%%%
0 件のコメント
採用された回答
Voss
2022 年 5 月 4 日
Assuming that's a script, then depending on your version of MATLAB, you might have to move the function definition to the end.
Then it seems to run ok:
R=1000;% Resistance value
fc=10e3;% Cutoff frequency
C=1/(2*pi*R*fc);% Capacitance value
f=1:100000;% Frequency axis
[M,P]=fil_ters(R,C,f);%Function call
subplot(2,1,1);
semilogx(f,M);% Plot magnitude
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude plot');
grid;
subplot(2,1,2);
semilogx(f,rad2deg(P));% Plot phase
xlabel('Frequency');
ylabel('Phase(degree)');
title('Phase plot');
grid;
function [M,P]=fil_ters(R,C,f)% Function definition
w=2*pi*f;% Hz to rad/sec
G=1./(1j*w*R*C+1);% Transfer function
M=abs(G);% Magnitude
P=angle(G);% Phase
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Audio Processing Algorithm Design についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
