Skip to content
Snippets Groups Projects
Verified Commit a1ca4d6e authored by orestis.malaspin's avatar orestis.malaspin
Browse files

added a todo

parent aa4719a5
No related branches found
No related tags found
No related merge requests found
Pipeline #23642 passed
...@@ -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 5000
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.01 * 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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment