def test_response1( self): # The first test case is that when both ESR of both t = numpy.array(range( 0, 30000, 1)) # inductor and capacitor is 0 the gain must be t = t / 1000 # perfectly zero at anti-resonating frequency. A = 1 i1, V1, t1, gain1 = response( A, 1, 1, 0, 0, 1, t) # When L = 1 Henry. C = 1 Farad. Wr = 1 rad/sec # Checking the gain at Wr is zero or not. i2, V2, t2, gain2 = response( A, 2, 0.5, 0, 0, 0.5, t) # When L = 0.5 Henry. C = 0.5 Farad. Wr = 2 rad/sec i3, V3, t3, gain3 = response( A, 2, 0.25, 0, 0, 1, t) # When L = 0.25 Henry. C = 1 Farad. Wr = 2 rad/sec i4, V4, t4, gain4 = response( A, 2, 1, 0, 0, 0.25, t) # When L = 1 Henry. C = 0.25 Farad. Wr = 2 rad/sec self.assertEqual(round(gain1, 3), 0) self.assertEqual(round(gain2, 3), 0) self.assertEqual(round(gain3, 3), 0) self.assertEqual(round(gain4, 3), 0)
def current_vs_voltage_plot(A, w, L, R1, R2, C, t, figure_index): i, V, t, gain = response(A, w, L, R1, R2, C, t) plt.figure(figure_index) plt.plot(t, V, '-', linewidth=1) plt.plot(t, i, '.', linewidth=1) plt.xlabel('Time in seconds') plt.ylabel('Current in Ampere and Voltage in Volts') plt.legend(['Voltage', 'Current']) plt.savefig('Voltage_and_Current_vs_time_at_frequency_omega_' + str(w) + '_with_both_resistance_' + str(R1) + '.png') return
def test_response2(self): t = numpy.array( range(0, 30000, 1)) # The second test case tests when the magnitude of both t = t / 1000 # L and C are same, then if the ESRs of both L and C are A = 1 # 1 ohm then the gain must be perfectly 1 for angular w = 1 # frequencies w = 1,2,5 rad/sec. i1, V1, t1, gain1 = response(A, w, 1, 1, 1, 1, t) i2, V2, t2, gain2 = response(A, w, 0.5, 1, 1, 0.5, t) w = 2 i3, V3, t3, gain3 = response(A, w, 1, 1, 1, 1, t) i4, V4, t4, gain4 = response(A, w, 0.5, 1, 1, 0.5, t) w = 5 i5, V5, t5, gain5 = response(A, w, 1, 1, 1, 1, t) i6, V6, t6, gain6 = response(A, w, 0.5, 1, 1, 0.5, t) os.remove("source/LC_tank_both.pyc") self.assertEqual(round(gain1, 3), 1) self.assertEqual(round(gain2, 3), 1) self.assertEqual(round(gain3, 3), 1) self.assertEqual(round(gain4, 3), 1) self.assertEqual(round(gain5, 3), 1) self.assertEqual(round(gain6, 3), 1)
t = numpy.array(range(0, 3000, 1)) t = t / 100 # Initilizing different component values for the first case. L in Henry. C in Farad. R11 (ESR of inductor) in ohm. R12 (ESR of capacitor) in ohm. L = 0.5 R11 = 0 R12 = 0 C = 0.5 A = 1 frequency = numpy.array(range(1, 100)) frequency = frequency / 10 Gain1 = [] for w in frequency: i, V, t, gain = response(A, w, L, R11, R12, C, t) Gain1.append(gain) plt.figure(1) plt.plot(frequency, Gain1) plt.xlabel('Frequency in rad/sec') plt.ylabel('Gain') plt.savefig('Frequency_response_without_any_resistance.png') R21 = 1 # The ESR values for the second case. L and C are smae as above. R22 = 0 Gain2 = [] for w in frequency: i, V, t, gain = response(A, w, L, R21, R22, C, t) Gain2.append(gain)
# initialization function: plot the background of each frame def init(): line.set_data([], []) line2.set_data([], []) return line, line2, A = 1 w_dash = 1 L_dash = 0.5 R1 = 0 R2 = 0 C_dash = 0.5 t = numpy.array(range(0,300,1)) t = t/10 i1,V,t,gain = response(A,w_dash,L_dash,R1,R2,C_dash,t) # animation function. This is called sequentially def animate(i): line.set_data(t-0.1*i,V) line2.set_data(t-0.1*i,i1) return line,line2 # call the animator. blit=True means only re-draw the parts that have changed. ani = animation.FuncAnimation(fig, animate, init_func=init, frames=200, interval=20, blit= False) ani.save('movie1.mp4', fps=10, extra_args=['-vcodec', 'libx264']) A = 1 w_dash = 1 L_dash = 0.5