#include #include const int sample_count = 32; double sample[sample_count]; int main(int argc, char* argv[]) { double R = .089; // Resistance in Ohms double L = 0.000040; // Inductance in Henrys double V = 12; // Voltage double F = 120; // Frequency in Hz double period = 1.0/F; // Period in seconds double d = .1; // duty cycle 0-1 double Istart; // current at start of on and off cycle double I; // Current int i,j; double time; I = 0; for(j=0;j<10;j++) // loop several times so starting current can stabalize { // generate samples for on portion of ducy cylcle Istart = I; // current at start of on cycle for(i=0;i<(sample_count*d);i++) { time = i * (period / sample_count); I = Istart+((V/R-Istart)*(1-exp(-time/(L/R)))); sample[i] = I; } // generage samples for off portion of duty cycle Istart = I; // current at start of off cycle for(i=i;i