how to plot conditional statement like when Vin=1, Vout=exp(-t/tn) and for Vin =0, Vout=1-exp(-t/tp) where Vin is a periodic square pulse.

i have tried as follows:
f=input('please enter the value of time');
t = 0:.00001*f:(1-.00001)*f;
fm=2/f;
Vin = .5+0.5*square(2*pi*fm*t);
subplot(211);
plot(t,Vin)
Vdd=5;
Rn=2000;
Rp=3000;
C=0.1e-9;
Tn=Rn*C;
Tp=Rp*C;
V1=Vdd.*(exp(-t/Tn));
V0=Vdd*(1-exp(-t/Tp));
Vout=V1;
Vout(Vin<1)=V0(Vin<1);
subplot(212)
plot(t,Vout)
the problem is that for very small value of f, like f=.00000001 the desired graph is not obtained. Even for values like f=0.001, the gradual decay or rise that is expected is not obtained. please help.

2 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 16 日
What is the desired result?
ANWESHA
ANWESHA 2014 年 5 月 16 日
編集済み: ANWESHA 2014 年 5 月 16 日
When Vin=1, Vout should be 0 with initial exponential decaying curve and if Vin=0 then Vout should be 1 with initial exponential rising curve.

サインインしてコメントする。

回答 (2 件)

statement like when Vin=1, Vout=exp(-t/tn) and for Vin =0, Vout=1-exp(-t/tp):
if (Vin == 1)
Vout=exp(-t/tn);
elseif (Vin == 0)
Vout=1-exp(-t/tp);
end

3 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 16 日
This is not what he asked for
ANWESHA
ANWESHA 2014 年 5 月 16 日
this is the desired result
ANWESHA
ANWESHA 2014 年 5 月 16 日
I have also tried with the if and elseif statement.It is not working.

サインインしてコメントする。

Image Analyst
Image Analyst 2014 年 5 月 16 日
Can't you just use a convolution, conv(), or filter()? Invert the signal and apply a kernel that only looks to the left. Seems pretty straightforward.

2 件のコメント

ANWESHA
ANWESHA 2014 年 5 月 16 日
Sorry sir, i didn't get you. Can you please elaborate. I have no idea how to apply kernel.
Image Analyst
Image Analyst 2014 年 5 月 16 日
See Star's code which uses filter(). It is fine. No need to worry about conv() now that you have the filter() code.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2014 年 5 月 16 日

コメント済み:

2014 年 5 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by