필터 지우기
필터 지우기

Problem in plotting using semilogx() function

조회 수: 1 (최근 30일)
PVR
PVR 2014년 10월 19일
편집: Rick Rosson 2014년 10월 19일
I need to plot a graph between w(frequency) and Mdb(Magnitude in db) using semilogx() function for different values of w. The output of graph is null. It shows nothing and there are no errors displayed. Where did I go wrong.
R=zeros(1,10000);
I=zeros(1,10000);
Mag=zeros(1,10000);
Z=zeros(1,10000);
Y=zeros(1,10000);
Mdb=zeros(1,10000);
for *w* = 0.1:0.01:10
R=(256-(16*w^2))/((16-(w^2))^2+(10*w)^2);
I=-160*w/((16-w^2)^2+(10*w)^2);
Mag=sqrt(R^2+I^2);
Z=atan2(I,R);
Y=Z*180/pi;
*Mdb* =20*log10(Mag); *bold*
plot(w,Mdb,'g');
semilogx(w,Mdb);
end

채택된 답변

Rick Rosson
Rick Rosson 2014년 10월 19일
편집: Rick Rosson 2014년 10월 19일
Vectorized code, no for-loop necessary:
w = 0.1:0.01:10;
R = (256-(16*w.^2))./((16-(w.^2)).^2+(10*w).^2);
I = -160*w./((16-w.^2).^2+(10*w).^2);
X = complex(R,I);
Mag = abs(X);
Mdb = 20*log10(Mag);
phi = angle(X)*180/pi;
figure;
ax(1) = subplot(2,1,1);
semilogx(w,Mdb);
grid on;
xlabel('Frequency');
ylabel('Magnitude in dB');
ax(2) = subplot(2,1,2);
semilogx(w,phi);
grid on;
xlabel('Frequency');
ylabel('Phase angle in degrees');
linkaxes(ax,'x');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Plot Customization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by