stem command working on the oppisite side of the axis
조회 수: 3 (최근 30일)
이전 댓글 표시
I want to create a plot of low pass filter ,while the Y axis is in dB and x is the ferquincy in logaritmich scale. I made the plot and now I want using the stem command to point to the cufoff ferquincy . but for some reason when I want to point to the cut off ferquincy the stem comand making the line from the up and not from down . how to fix this problem ?
clc
close all;
y=mag2db(dB_axes(1:120));
x=f_axes(1:120);
for i=1:length(mag2db(y(1:120)))
if(2.8<abs(y(i)) && abs(y(i))<3.5 )
i; %% find the cutoff ferquincy
break;
end;
end
plot(x,y,'red','linewidth',3);
grid on;
set(gca, 'XScale', 'log');
hold on
stem(x(i),y(i),'*','linewidth',2);
xlabel('f[logarthmic scale]');
ylabel('dB');
title('RC filter -freuquincy responce');
댓글 수: 0
답변 (2개)
Star Strider
2021년 4월 24일
It is necessary to give stem a different base value in order for it to plot upwards to a negative value.
Try this —
s = tf('s');
sys = 1/(s^2+2*s-5);
[a,p,w] = bode(sys);
bw = bandwidth(sys);
asq = squeeze(a);
hppa = interp1(w, mag2db(asq), bw);
figure
semilogx(w, mag2db(asq))
hold on
stem(bw, hppa, 'BaseValue',min(mag2db(asq)))
hold off
grid
.
댓글 수: 0
Clayton Gotberg
2021년 4월 24일
This is because you haven't provided any information about the baseline for stem, so the function assumes you want it to come from y = 0. To adjust it to come from the bottom of the chart, use this:
ax = gca;
y_min = min(ax.Ylim)
stem(x(i),y(i),'*','linewidth',2,'BaseValue',y_min);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!