Using z-transform to solve the capacitor current, but I don't know where I went wrong.

3 vues (au cours des 30 derniers jours)
xin
xin le 29 Août 2024
Take the simplest capacitive current as an example,,C is capacitance.
The corresponding transfer function is
Applying bilinear transformation
,,T is sampling time
The inverse transformation yields
,n is nth sampling moment.
Assuming the voltage input is known , is calculation step
Since index values in matlab start from 1,.
%%%%%%%%%%%%%%%
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)
%%%%%%%%%%%%%%%
The code resulted is this,quite different from simulink result.
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?

Réponses (1)

Shishir Reddy
Shishir Reddy le 30 Août 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.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by