Effacer les filtres
Effacer les filtres

stem command working on the oppisite side of the axis

8 vues (au cours des 30 derniers jours)
tomer polsky
tomer polsky le 24 Avr 2021
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');

Réponses (2)

Star Strider
Star Strider le 24 Avr 2021
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
.

Clayton Gotberg
Clayton Gotberg le 24 Avr 2021
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);

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by