Maker Pro
Maker Pro

Half-wave Rectifier with Smoothing Capacitor

evol_w10lv

Feb 19, 2013
73
Joined
Feb 19, 2013
Messages
73
Hello!
This time I have to graph few graphics using MATLAB. I don't know, whether you use it or not, but problem is that don't understed exactly, how voltage is changing by the time.
I have this loop:
hagwy1vcpine8jss56rt.png


And outputs I expect:
ukzowbop27jf6s2ezfo3.png

7qjbiqg1dd4qzdyrpcs5.png

890zt3zt0fppsblmfw3y.png


Given:
E(t) = 310*sin(2*pi*50*t)
time is changing from 0 to 0.2 s by step h: 0.0002 s
C = 50*10^(-6) F
R = 1000 Ohms
i0 = 1*10^(-6) A
fi = 26*10^(-3) V

There is no problem to draw V(in), but it is not clear, how is changing V(out) with C and without C.
I have to use iterations to get graphics, then:
V(out +1) = V(out)+h * (i0/C)*(exp((E(t)*V(out))/fi) -1) - (V(out)) / (R*C))
As there is exp(0) -1 = 0, it always gives 0, it means that V(out) at 0 secons not 0, but there is a small value. Is it R * i0 ?
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
You have to make a distiction between two cases:

1) E(t) >= V(out)+Vdiode
In this case the input voltage is higher than the current voltage across C1 (i.e. the output voltage) plus one diode voltage drop (typically 0.6V). Diode D1 is conducting. Then the voltage source will force current into C1 such that V(out)= E(t)-Vdiode.

2)E(t) < V(out)+Vdiode
In this case the input voltage is lower than the current voltage across C1 (i.e. the output voltage) plus one diode voltage drop (typically 0.6V). Diode D1 is not conducting. The output voltage follows the discharge curve of capacitor C1 loaded by Resistor R. Since this is homework I will not give you the complete equation, but you are already on the right track using an exponential equation.

From these two cases you can construct the output waveform for Vout.
 

evol_w10lv

Feb 19, 2013
73
Joined
Feb 19, 2013
Messages
73
Yes, I guess, that this is the way, how to calculate voltage by time when capacitator is used (file in attachment).

Last line shows, how to find next voltige with step +h (+0.0002 s) as V(k+1). As I said, I have to use iterations.
And I have got: E(t) = 310*sin(2*pi*50*t)
When t1 = 0, then E(1) = 0
t2 = 0.0002, E(2) = 19.4651 V
t3 = 0.0004, E(3) = 38.8533 V
... and so on, using step h = 0.0002 s
This is clear, but I guess, when E(1) = 0, then V(k) = V(1) = 0 (voltage at 0 seconds)
But using V(1)=0 in last equation (in the picture), it gives all results of V(k+1) = 0, because e^0 = 1, and yes .. I guess, you understand, what is problem for me there.
It means that I have to use diferent starting value V(1)? For example, I have to start iteration from k =2, using E(2) and V(2) values? Or equation is wrong?
 

Attachments

  • DSC_8821.jpg
    DSC_8821.jpg
    102.9 KB · Views: 242
Last edited:

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
It looks like you're mixing two independend variables: h and k
h is the "real time", k is your index used for aproximating the curve in the tool. I can't even see what this "h" is.

In case 1 the output voltage folows the input voltage until at some time tx the condition for case 1 is no longer true.
You then switch to case 2. Your initial voltage at this time tx is Vout(tx) = Vin-Vdiode.. The oltage now follows a capacitor discharge curve. Vcap(t)= Vcap(tx)*exp(...). You should know the term in parentheses or look it up. It is rather simple consisting of the time and the values of R and C. You dont need the current (because it is already accounted for by the equation, nor do you need any differentials.
Note that the classic equation for capacitor discharge starts at t=0. Since in your case the discharge starts at t=tx, you need a simple transformation t= tsim-tx where tis the typcal term for time in the discharge equation and tsim is your simuation time. This way, for tsim=tx the term t becomes 0, as required by the standard equation.
You can now compte all outpt voltages as a series:
Vout(tx) = Ein(tx)-Vdiode
Vout(tx+dt)=Vout(tx)*exp((tsim-tx+dt)...)
Vout(tx+2dt)=Vout(tx)*exp((tsim-tx+2dt)...)
...
until condition 1 is again reached.

I'm sorry, this doesn't look very clear thanks to my not disclosing the whole solution. I hope it is understandable nevertheless. I'll be happy to look at your solution.
 

evol_w10lv

Feb 19, 2013
73
Joined
Feb 19, 2013
Messages
73
Actually this task is for computer science not for electronics, but I don't know almost nothing about diodes. On the Internet wasn't very clear information, how V(out) is changing by time. Your information is useful, but.. First off all, to ease up the task, I will try to start with case 2. It means, that on highest (start) point, capacitor is charged and there is 311.127 V output? And it is on point/ time, where AC input is on highest point as well, when time is 0.005 s (let it be t1). As we know, time is changing by 0.0002s, it reveals that t2 = 0.0052 s, then AC starts to decrese E2 = 310.5130 V. Can you show example with numbers, how to calculate V(out) on point/time, when we use AC?
fi = 26e-3 and i0= 1e-6 (constants)
I guess V(out+1) = (i0/C) * (exp((310.5140-311.127)/fi) - 1) - (311.127/(R*C)), but something is wrong there..
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Don't give up, youre on the right track.
1) at t=t1=0.05s=5ms then Ein= 310V because sin(2*i*50 Hz*0.005s)=1.
I don't know how you arrive at values greater than 310 V. That is not possible with your input data.

2) Assuming a diode voltage of 0.6V, Vout(t=t1= = 310V-0.6V=309.4V
It stands to argue that for the purpose of his task Vdiode=0 could be assumed. This is physicaly wrong, but acceptable if you're not studying electrical engineering. Your instructor may have had such a simplification in mind. But let us keep Vdiode=0.6V here, it is definitely not wrong.
Now from t=t1 the nect time step is t2=t1+0.0002s.
What is Ein at t=t2?
If the capacitor were to be discharged by the resitor without E being present, it would discharge according to Vout(t)=Vc(t)= V0*exp(t-t1)/tau) where V0=fuly charged capacitors voltage=309.4V, au= RC time constant=R*C
I feel free to give these equations now that you have done your own research and are heading in the right direction.
As long as Vout(t) calculates <=Ein(t)-Vdiode, the diode is conducting and case 1 is applicable, meaning that Vout(t)Ein(t)-Vdiode.
As soon as Vout(t) calculates >Ein(t)-Vdiode, the diode is blocking ad case 2 is applicable, meaning that from that point on Vout(t) follows the capacitor discharge curve. Let's say this hapens at t=tx. Then you have Vout(t=tx)=V0 and you insert t-tx into the discharge equation.
 

evol_w10lv

Feb 19, 2013
73
Joined
Feb 19, 2013
Messages
73
I made the code for V(out) without capacitor.
R=1e3;
i0=1e-6;
F=50
T=1/F
C=50e-6;
fi=26e-3;
h=T*0.01;
t=0:0.01*T:10*T;
for i=1:length(t)
%t(i)=(i-1)*inc;
e(i)=310*sin(2*pi*50*t(i));
if e(i)>=0
Uiz1(i)=e(i)
else
Uiz1(i)=0;
end
end
figure(2);
plot(t,e,t,Uiz1)
hleg1 = legend('V(in)','V(out)');


ys9oixufdvr89m7ozkf.png


But still something is going wrong, when C is used. I guess we can try to solve the task without Vdiode.
It should be something like that (main loop):
Vout(1) = 310
t(1)=0.005
for i=1:length(t)
t(i+1)=t(i)+0.0002;
Vout(i+1)=Vout(i)*exp((t(i)-t(i+1))/0.05)
E(i)=310*sin(2*pi*50*t(i));
if Vout(i)<=E(i)
Vout(i)=E(i)
else
Vout(i)=Vout(i);
end
end


But it doesn't give the result which I hoping for. Whre I made mistake?
 
Last edited:

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Good idea to bypass the diode voltage. You can always re-insert it later.

I think the error is here.
Vout(i+1)=Vout(i)*exp((t(i)-t(i+1))/0.05)
You "restart" the exp function with every iteration because you use Vout(i) as the starting value. But you need to use the value from that point in time when Ein(t) became smaller than Vout.
You need to remember this time and Vout a this time. let me call these tx and Vx. Then for every further step in time
Vout(t)=Vx*exp((t-tx)/R*C)
You see, that Vx and tx stay the same regardless of t (or the index i in your code).
This is valid until Ein(t) is again > Vout, then the voltage again follows Ein.
 

evol_w10lv

Feb 19, 2013
73
Joined
Feb 19, 2013
Messages
73
Yes, I understand, what is needed, but I don't know, how to do it. Have I need to include one more for loop in programm code?

betqzz9telqr00zjwdp.png

kokotdncnjov7nz9uih1.png


I think, that I won't finish this task.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
1) you start with Uc(1)=310, which is obviously wrong because Ein(1)=0 as you can see from your diagram. Initially Uc(1)=0 because the capacitor is initially discharged.

2) your green curve only shows the discharge curve of a capacitor which is charged to Uc(1)=310V overlaid by the input voltage. Your program does not take into consideration that the capacitor is recharged by Ein.
Whenever Ein >=Uc(t), you need to set Uc(t)=Ein.
Once Ein < Uc(t), you start a new discharge curve. You don't need another loop within the loop, you need to remember the value of Uc(t) at the instant Ein drops below Uc(t) and the respective time, tx. Then start a new discharge curve using these remembered values.
Here's how this loooks in Excel VBA code, you should be able to adapt it to your needs.
Code:
Sub test()
Const R = 1000
Const C = 0.00005
Const Vmax = 310    'peak voltage
Const frq = 50      'frequency in Hertz
Const dt = 0.002    'resolution in seconds
Const periods = 5   'number of periods to display
Const Pi = 3.14159265358979

Dim i As Integer
Dim tx As Double
Dim vx As Double
Dim vout As Double
Dim ein As Double

vx = 0      'capcitor initially discharged
vout = 0    'output voltage initially 0
For i = 0 To (periods / frq * 1 / dt) 'number of steps calculated from frequency, number of periods to display and resolution
    ein = Vmax * Sin(2 * Pi * frq * i * dt)
    If ein > vout Then    'follow input if input is greater than capacitors voltage
        vx = ein
        vout = vx
        tx = i
    Else                'discharge capacitor
        vout = vx * Exp(-(i - tx) * dt / (R * C))
    End If
    Cells(i + 1, 1) = i     'time
    Cells(i + 1, 2) = ein   'input voltage
    Cells(i + 1, 3) = vout  'output voltage
Next
End Sub
 

evol_w10lv

Feb 19, 2013
73
Joined
Feb 19, 2013
Messages
73
Woow, thank you very much!
h3wqkk9ssh70m7gadjmf.png

Code:
R=1e3;
i0=1e-6;
F=50
T=1/F
C=50e-6;
vx=0;
vout=0;
vmax=310;
fi=26e-3;
h=T*0.01;
t=0:0.01*T:0.2;
x=1
for i=1:length(t)
    e(i)=vmax*sin(2*pi*50*t(i));
    vout(i) = vx(x) * exp(-(i - x) * h /0.05)
    if e(i)>vout(i)
        vx(i) = e(i)
        vout(i) = vx(i)
        x = i
    else
        vout(i) = vx(x) * exp(-(i - x) * h /0.05)
    end
end
plot(t,vout,t,e)

It's akward to ask so many questions, but actually I have to use capcitor discharging formula, which we can got from differentials.
jbqbjd4bb2cguwufwfwz.png

It gives almost the same resulsts as standart formula, but after i=88 (the point where Vout have to be the same as Ein) it doesn't continue to countdown as standart formula thats why is needed other statement, I guess. Can you suggest something?
And sorry for so many questions..
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
The complete diferential equation is currently a bit out of my scope.

If you make dt very small, you can make an approximation by assuming linear discharge during dt.

For the simple RC circuit the equations go as follows:
i(t)= V(t)/R = -C*dv/dt
Therefore
dv=-V(t)/(R*C)*dt
And from that
V(t+1)=V(t)+dv=V(t)-V(t)/(R*C)*dt= V(t)*(1-1/R*C)*dt

Again, use the "right" V(t) and make the transformation t-tx as shown by my code to account for the "restart" of the discharge curve.
 

evol_w10lv

Feb 19, 2013
73
Joined
Feb 19, 2013
Messages
73
Maybe you can look at code?
Is there problem with itterations, that's why discharging line goes straight after first succesive itteration?
2o9dokty7buepxnybqf.png

pm6kole8kjc10mkgxf9.png

x1zpbikh89bezi8sogkb.png


Code:
R=1e3;
i0=1e-6;
F=50;
T=1/F;
C=50e-6;
vx=0;
vout=0;
vmax=310;
fi=26e-3;
h=T*0.01;
t=0:0.01*T:0.2;
x=1;
vout(1)=0
for k=1:length(t)-1
    e(k+1)=310*sin(2*pi*50*t(k+1));
    vout(k+1)=vx(x)+((i0/C)*(exp((e(x)-vx(x))/fi)-1)-(vx(x)/(R*C)))*0.0002;
    if e(k)>vout(k)
        vx(k) = e(k)
        vout(k) = vx(k)
        x = k
    else
        vout(k+1)=vx(x)+((i0/C)*(exp((e(x)-vx(x))/fi)-1)-(vx(x)/(R*C)))*0.0002;
    end
end
z=length(t)
x=length(e)
u=length(vout)
%b=length(Uiz2)
plot(t,vout,t,e)
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
The problem seems to be here:
Code:
vout(k+1)=vx(x)+((i0/C)*(exp((e(x)-vx(x))/fi)-1)-(vx(x)/(R*C)))*0.0002;
You mixed my code and yours in an incompatible way.
My code uses the exponential decay of voltage across an RC combination. Therefore any V(t) need to be calculated from V(t=0).
If you iterate, you need to calculate V(t+1)=f(V(t)).
Because you use an iterative equation, but insert the same starting value (vx(x)) time and again, the result is the same for each calculation, too.
 

evol_w10lv

Feb 19, 2013
73
Joined
Feb 19, 2013
Messages
73
Yes, of course! I needed to understand it by my self.
By the way, here is code and result, if you are interested. And we can see, that differentials method using aproximation gives almost the same result as standart formula.
Code:
R=1e3;
i0=1e-6;
F=50;
T=1/F;
C=50e-6;
fi=26e-3;
h=T*0.01;
t=0:0.01*T:T*10;
vout(1)=0
for k=1:length(t)-1
    e(k+1)=310*sin(2*pi*50*t(k+1));
    vout(k+1)=vout(k)+((i0/C)*(exp((e(k+1)-vout(k))/fi)-1)-(vout(k)/(R*C)))*h;
    if e(k+1)>vout(k)
        vout(k+1) = e(k+1)
    else
        vout(k+1)=vout(k)+((i0/C)*(exp((e(k+1)-vout(k))/fi)-1)-(vout(k)/(R*C)))*h
    end
end
plot(t,vout,t,e)
cvknktmh0zc1r4m344cw.png

m0nxqyfx2ya8xn394p8.png
 

Laplace

Apr 4, 2010
1,252
Joined
Apr 4, 2010
Messages
1,252
Instead of the task being to create a numerical simulation and graph in MATLAB, how would one just sketch the relevant features of the output voltage? For what it's worth, my approach is attached.
 

Attachments

  • Half Wave Trig.pdf
    68.3 KB · Views: 170
Top