simple tracking of oscillator output and phase
| import mpld3 | |
| mpld3.enable_notebook() | |
| import math | |
| import numpy as np | |
| from matplotlib import pyplot as plt | |
| import pandas as pd | |
| plt.rcParams['figure.figsize'] = [18,10] | |
| x = 10000 | |
| x | |
| samples = np.arange(x,dtype=np.float64) | |
| settwo = np.arange(x,dtype=np.float64) | |
| phase = 0 | |
| freq = 0.0004 | |
| class osc (object): | |
| def __init__(self): | |
| self.phase = 0.0 | |
| self.pulseStage = 0.0 | |
| def render(self,freq, pwm): | |
| self.phase = self.phase + freq | |
| while True: | |
| if self.pulseStage == 0: | |
| if self.phase < pwm: | |
| break | |
| self.pulseStage = 1.0 | |
| if self.pulseStage == 1: | |
| if self.phase < 1.0: | |
| break | |
| self.pulseStage = 0.0 | |
| self.phase = self.phase - 1.0 | |
| return self.pulseStage | |
| def getPhase(self): | |
| return self.phase | |
| o = osc(); | |
| for idx in range(0,x): | |
| samples[idx] = o.render( freq , 0.5 ) | |
| settwo[idx] = o.getPhase() | |
| phase += freq | |
| x = np.linspace(0, x, x) | |
| plt.plot(x, samples , label ='osc') | |
| plt.plot(x, settwo , label ='phase' ) | |
| plt.xlabel('x label') | |
| plt.ylabel('y label') | |
| plt.title("phase & osc out") | |
| plt.legend() | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.