Created
April 27, 2020 11:01
-
-
Save junklight/617d63c30faaa24e727bd0a4cfe30c07 to your computer and use it in GitHub Desktop.
simple tracking of oscillator output and phase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Author
junklight
commented
Apr 27, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment