stem command working on the oppisite side of the axis
5 次查看(过去 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 中查找有关 Stem Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!