11 views (last 30 days)

I have follwing curve resulting from plotting current in capacitor versus time. (Matlab code is attached).

I want to calculate the charge stored in the capacitor. For that I need to calculate the positive area of the curve. As you can see in the zoomed in image, the current plotted has pulses (switching frequency = 20kHz), and I would like to calculate the charge stored in one fundamental cycle (fundamental frequency = 60Hz).

So theoretically, the capacitor is getting charged when the current flows into it. For the curve it means the value of current that is above zero(positive).

I tried calculating the area of the curve by simplifying the curve into traingles and trapezoids, and then taking the coordinate points values (x,y). But I am pretty sure it is not correct since it does not take into account the presence of pulses.

I also tried the trapz(x,y) in matlab but the calculation does not seem right.

And the expression of the current is not a straightforward function, it is defined in terms of switching functions and duty ratios so I am not sure how to use the integral function in Matlab.

Please help.

Dimitris Kalogiros
on 25 Oct 2019

Edited: Dimitris Kalogiros
on 25 Oct 2019

Change the last section of your program to this:

%% Sizing Capacitor Cf;

%capacitor fundamental current for "a" phase is all the ripple current of ia, considering

%the fundamental compnent of ia, i.e. ia1 flows into converter;

%similar expression for other phases;

icfa = ia-ia1;

icfb = ib-ib1;

icfc = ic-ic1;

% integral of current

Qcfa=zeros(size(t));

for n=2:length(t)

Qcfa(n)=Qcfa(n-1)+icfa(n)*(t(n)-t(n-1));

end

figure(7);

subplot(2,1,1); plot(t,icfa,'-k.'),grid on

xlabel('Time(s)','fontsize',12);

ylabel('Capacitor Current(Amps)','fontsize',12);

xlim([0,T])

figure(7);

subplot(2,1,2); plot(t,Qcfa,'-r.'); zoom on; grid on;

xlabel('Time(s)','fontsize',12);

ylabel('Capacitor charge(Coulomb)','fontsize',12);

xlim([0,T])

Qcfa(n) is the value of capacitor's electric charge at every moment t(n).

Dimitris Kalogiros
on 29 Oct 2019

%% Sizing Capacitor Cf;

%capacitor fundamental current for "a" phase is all the ripple current of ia, considering

%the fundamental compnent of ia, i.e. ia1 flows into converter;

%similar expression for other phases;

icfa = ia-ia1;

icfb = ib-ib1;

icfc = ic-ic1;

% integral of current

Qcfa=zeros(size(t));

for n=2:length(t)

Qcfa(n)=Qcfa(n-1)+icfa(n)*(t(n)-t(n-1));

end

% integral of current, using Trapezoidal numerical integration

Qcfa2=zeros(size(t));

for n=2:length(t)

Qcfa2(n)=trapz(t(1:n), icfa(1:n));

end

figure(7);

subplot(3,1,1); plot(t,icfa,'-k.'),grid on

xlabel('Time(s)','fontsize',12);

ylabel('Capacitor Current(Amps)','fontsize',12);

xlim([0,T]);

figure(7);

subplot(3,1,2); plot(t,Qcfa,'-r.'); zoom on; grid on;

xlabel('Time(s)','fontsize',12);

ylabel('Capacitor charge(Coulomb)','fontsize',12);

xlim([0,T]);

figure(7)

subplot(3,1,3); plot(t,Qcfa2,'-k.');grid on; zoom on;

xlabel('Time(s)','fontsize',12);

ylabel('Capacitor charge(Coulomb), using trapz()','fontsize',12);

xlim([0,T]);

I have include it. You can compare Qcfa and Qcfa2 and find out the differences.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_759835

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_759835

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_759921

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_759921

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_759961

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_759961

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_760045

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_760045

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_760046

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_760046

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_760047

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_760047

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_760059

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/487277-area-under-the-curve#comment_760059

Sign in to comment.