Added øvinger
This commit is contained in:
BIN
Øvinger/Ø1/Oppgave4Python/4b.png
Normal file
BIN
Øvinger/Ø1/Oppgave4Python/4b.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 137 KiB |
BIN
Øvinger/Ø1/Oppgave4Python/4b2.png
Normal file
BIN
Øvinger/Ø1/Oppgave4Python/4b2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 137 KiB |
BIN
Øvinger/Ø1/Oppgave4Python/4c.png
Normal file
BIN
Øvinger/Ø1/Oppgave4Python/4c.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 199 KiB |
BIN
Øvinger/Ø1/Oppgave4Python/4c2.png
Normal file
BIN
Øvinger/Ø1/Oppgave4Python/4c2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 169 KiB |
83
Øvinger/Ø1/Oppgave4Python/Graftegning.py
Normal file
83
Øvinger/Ø1/Oppgave4Python/Graftegning.py
Normal file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Fri Jan 18 22:30:00 2019
|
||||
|
||||
@author: oyvind
|
||||
"""
|
||||
import math
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Name for the saved graph
|
||||
filename = "4b"
|
||||
|
||||
# Tau in microseconds
|
||||
tau = 10
|
||||
|
||||
# Square wave freq in kHz
|
||||
sqWFreq = 5
|
||||
|
||||
# How many taus you want
|
||||
periods = 40
|
||||
|
||||
# The resolution of each tau
|
||||
resolution = 1000
|
||||
|
||||
# Calculates the length of each squarewave in taus
|
||||
sqTime = (1/sqWFreq) * 10**3
|
||||
sqTau = sqTime / tau
|
||||
|
||||
# Creats the square wave
|
||||
# Default values are in the argument list
|
||||
def CreateSquareWave(amp=0.5, offset=0.5, symetry=0.5):
|
||||
squareWave = []
|
||||
# Only generates as many datapoints we need
|
||||
while len(squareWave) < periods * resolution:
|
||||
# First generate the first half
|
||||
for r in range(int(resolution*sqTau * symetry)):
|
||||
squareWave.append(amp + offset)
|
||||
# Then the second
|
||||
for r in range(int(resolution*sqTau * (1 - symetry))):
|
||||
squareWave.append(offset - amp)
|
||||
squareWave = squareWave[:(resolution*periods)]
|
||||
return squareWave
|
||||
|
||||
|
||||
# Generate all the time-ticks
|
||||
def GenerateTime():
|
||||
times = []
|
||||
for t in range(periods * resolution):
|
||||
times.append(t/resolution)
|
||||
print(len(times))
|
||||
return(times)
|
||||
|
||||
|
||||
def CapVoltage(wave, times):
|
||||
cP = wave[0] # Start voltage-supply
|
||||
v0 = 0 # Start voltage
|
||||
cT = 0 #Start time
|
||||
volt = []
|
||||
for p in range(len(wave)):
|
||||
# If the voltage-supply changes, recalculate startvalues
|
||||
if wave[p] != cP:
|
||||
v0 = volt[-1] # New start voltage, uses the last voltage calculated
|
||||
cP = wave[p] # Variable so the array is not accessed.
|
||||
cT = times[p] # Offset time for each period
|
||||
# Calculate the voltage over the CAPACITOR with the start values
|
||||
volt.append(cP + (v0 - cP) * math.exp(-(times[p] - cT)))
|
||||
return(volt)
|
||||
|
||||
|
||||
SquareWave = CreateSquareWave()
|
||||
time = GenerateTime()
|
||||
CapWave = CapVoltage(SquareWave, time)
|
||||
|
||||
plt.figure(figsize=(15,5))
|
||||
plt.plot(time, SquareWave, time, CapWave)
|
||||
plt.xlabel("Time [τ]")
|
||||
plt.ylabel("Voltage [V]")
|
||||
plt.legend(["Supply voltage", "Capacitor voltage"], loc="lower right")
|
||||
plt.savefig(filename + ".png", dpi = 300)
|
||||
plt.show()
|
||||
|
||||
|
||||
BIN
Øvinger/Ø1/Oppgave4Python/cap.png
Normal file
BIN
Øvinger/Ø1/Oppgave4Python/cap.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 169 KiB |
Reference in New Issue
Block a user