Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
isc_physics
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orestis.malaspin
isc_physics
Commits
a1ca4d6e
Verified
Commit
a1ca4d6e
authored
2 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
added a todo
parent
aa4719a5
No related branches found
No related tags found
No related merge requests found
Pipeline
#23642
passed
2 years ago
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
practical_work/rc_circuit/main.c
+15
-7
15 additions, 7 deletions
practical_work/rc_circuit/main.c
with
15 additions
and
7 deletions
practical_work/rc_circuit/main.c
+
15
−
7
View file @
a1ca4d6e
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include
<math.h>
#include
<math.h>
#include
<plplot.h>
#include
<plplot.h>
#define NSIZE 500
#define NSIZE 500
0
double
PI
=
4
.
0
*
atan
(
1
.
0
);
double
PI
=
4
.
0
*
atan
(
1
.
0
);
...
@@ -33,6 +33,12 @@ double solve_vc(rc_circuit rc, double v0, double v_in, double dt)
...
@@ -33,6 +33,12 @@ double solve_vc(rc_circuit rc, double v0, double v_in, double dt)
return
(
v_in
-
v0
)
/
(
rc
.
c
*
rc
.
r
)
*
dt
+
v0
;
return
(
v_in
-
v0
)
/
(
rc
.
c
*
rc
.
r
)
*
dt
+
v0
;
}
}
// TODO: try to do the high pass filter.
// double solve_vr(rc_circuit rc, double v0, double dv_in_dt, double dt)
// {
// return (dv_in_dt * (rc.c * rc.r) - v0) / (rc.c * rc.r) * dt + v0;
// }
double
solve_vr
(
double
v_in
,
double
vc
)
double
solve_vr
(
double
v_in
,
double
vc
)
{
{
return
v_in
-
vc
;
return
v_in
-
vc
;
...
@@ -181,8 +187,8 @@ void compute_sin(int size, PLFLT time[size], PLFLT vc[size], PLFLT vr[size], PLF
...
@@ -181,8 +187,8 @@ void compute_sin(int size, PLFLT time[size], PLFLT vc[size], PLFLT vr[size], PLF
double
max_t
=
size
*
dt
;
double
max_t
=
size
*
dt
;
double
v
=
v0
;
double
v
=
v0
;
double
v_in_time
=
v_in
;
double
v_in_time
=
v_in
;
double
omega1
=
1
.
0
/
(
0
.
1
*
rc
.
r
*
rc
.
c
);
double
omega1
=
1
.
0
/
(
0
.
0
1
*
rc
.
r
*
rc
.
c
);
double
omega2
=
1
.
0
/
(
10
.
0
*
rc
.
r
*
rc
.
c
);
double
omega2
=
1
.
0
/
(
2
.
0
*
rc
.
r
*
rc
.
c
);
int
i
=
0
;
int
i
=
0
;
for
(
double
t
=
0
.
0
;
t
<
max_t
&&
i
<
size
;
t
+=
dt
)
for
(
double
t
=
0
.
0
;
t
<
max_t
&&
i
<
size
;
t
+=
dt
)
...
@@ -194,7 +200,7 @@ void compute_sin(int size, PLFLT time[size], PLFLT vc[size], PLFLT vr[size], PLF
...
@@ -194,7 +200,7 @@ void compute_sin(int size, PLFLT time[size], PLFLT vc[size], PLFLT vr[size], PLF
vr
[
i
]
=
solve_vr
(
v_in_time
,
v
);
vr
[
i
]
=
solve_vr
(
v_in_time
,
v
);
v_input
[
i
]
=
v_in_time
;
v_input
[
i
]
=
v_in_time
;
v
=
solve_vc
(
rc
,
v
,
v_in_time
,
dt
);
v
=
solve_vc
(
rc
,
v
,
v_in_time
,
dt
);
v_in_time
=
v_in
*
sin
(
2
*
PI
*
omega1
*
t
);
v_in_time
=
v_in
*
sin
(
2
*
PI
*
omega1
*
t
)
+
v_in
*
sin
(
2
*
PI
*
omega2
*
t
);
i
+=
1
;
i
+=
1
;
}
}
}
}
...
@@ -210,7 +216,7 @@ int main(int argc, char *argv[])
...
@@ -210,7 +216,7 @@ int main(int argc, char *argv[])
// Parse and process command line arguments
// Parse and process command line arguments
plparseopts
(
&
argc
,
argv
,
PL_PARSE_FULL
);
plparseopts
(
&
argc
,
argv
,
PL_PARSE_FULL
);
plsetopt
(
"dev"
,
"wxwidgets"
);
plsetopt
(
"dev"
,
"wxwidgets"
);
plssub
(
2
,
2
);
plssub
(
1
,
3
);
// Initialize plplot
// Initialize plplot
plinit
();
plinit
();
...
@@ -218,13 +224,15 @@ int main(int argc, char *argv[])
...
@@ -218,13 +224,15 @@ int main(int argc, char *argv[])
double
v0
=
0
.
0
;
double
v0
=
0
.
0
;
double
v_in
=
1
.
0
;
double
v_in
=
1
.
0
;
PLFLT
t
[
NSIZE
],
vc
[
NSIZE
],
vr
[
NSIZE
],
v_input
[
NSIZE
];
PLFLT
t
[
NSIZE
],
vc
[
NSIZE
],
vr
[
NSIZE
],
v_input
[
NSIZE
];
// compute_charge(NSIZE, t, vc, vr, rc, v0, v_in);
compute_charge
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
rc
,
v0
,
v_in
);
compute_sin
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
rc
,
v0
,
v_in
);
plot_data
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
"t"
,
"v"
,
"The charge of a capacitor"
);
plot_data
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
"t"
,
"v"
,
"The charge of a capacitor"
);
compute_discharge
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
rc
,
v_in
,
v0
);
compute_discharge
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
rc
,
v_in
,
v0
);
plot_data
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
"t"
,
"v"
,
"The discharge of a capacitor"
);
plot_data
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
"t"
,
"v"
,
"The discharge of a capacitor"
);
compute_sin
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
rc
,
v0
,
v_in
);
plot_data
(
NSIZE
,
t
,
vc
,
vr
,
v_input
,
"t"
,
"v"
,
"The discharge of a capacitor"
);
// Close PLplot library
// Close PLplot library
plend
();
plend
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment