Using z-transform to solve the capacitor current, but I don't know where I went wrong.
2 views (last 30 days)
Show older comments
Take the simplest capacitive current as an example,
,C is capacitance.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762129/image.png)
The corresponding transfer function is ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762134/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762134/image.png)
Applying bilinear transformation ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762139/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762139/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762144/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762149/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762154/image.png)
The inverse transformation yields
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762159/image.png)
Assuming the voltage input is known
,
is calculation step
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762164/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762169/image.png)
Since index values in matlab start from 1,
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762174/image.png)
%%%%%%%%%%%%%%%
deltat=1e-3; %calculation step
T=50e-6; %sampling time
C=100e-3; %capacitance
t=0:deltat:1;
k=2/T;
i=[];
i(1)=0;
u=sin(2*pi*50*t);
for n=1:1000
i(n+1)=C*k*u(n+1)-C*k*u(n)-i(n);
end
plot(t,i)
%%%%%%%%%%%%%%%
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762179/image.jpeg)
The code resulted is this,quite different from simulink result.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1762184/image.png)
The questions I want to ask are:
1, Where is the formula derivation wrong?
2, If I want to change the index value to start from 0, how can I change the code without any error?
0 Comments
Answers (1)
Shishir Reddy
on 30 Aug 2024
Hi xin
When dealing with discrete data, plotting directly will inherently produce a step-like appearance. If the objective is to accurately reflect the continuous-time behaviour of the system, numerical integration methods should be considered that simulate continuous-time behaviour.
For a capacitor, the relationship between current i(t) and voltage u(t) is given by the differential equation: i(t) = C* (du/dt).
To solve a differential equation numerically, MATLAB's built-in numerical solvers like ode45, which are designed to handle ordinary differential equations (ODEs) can be used.
For detailed information regarding the ode45 solver, kindly refer the following documentation. https://www.mathworks.com/help/matlab/ref/ode45.html
This can be implemented as follows.
C = 100e-3;
T = 0.5;
f = 50;
u = @(t) sin(2 * pi * f * t);
differentialEquation = @(t, i) C * (2 * pi * f * cos(2 * pi * f * t)); % dy/dt = C * du/dt = C * (du/dt)
i0 = 0; % Initial condition for the current
tspan = [0 T];
[t, i] = ode45(differentialEquation, tspan, i0); % Solving the differential equation using ode45
plot(t, i);
title('Capacitive Current (Continuous-Time Simulation)');
xlabel('Time (s)');
ylabel('Current (A)');
ylim([-0.1 0.1])
By using ode45, the continuous-time behaviour of the capacitor can be simulated without manually discretizing the system, resulting in a smooth and accurate representation of the current.
I hope this helps.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!