def evaluate(self, ts): freqs = np.linspace(self.start, self.end, len(ts)) dts = np.diff(ts, prepend=0) dphis = math.pi * 2 * freqs * dts phases = np.cumsum(dphis) cycles = phases / (math.pi * 2) frac, _ = np.modf(cycles) ys = thinkdsp.normalize(thinkdsp.unbias(frac), self.amp) return ys
def evaluate(self, ts): freqs = np.linspace(self.start, self.end, len(ts)) dts = np.diff(ts, prepend=0) dphis = PI2 * freqs * dts phases = np.cumsum(dphis) cycles = phases / PI2 frac, _ = np.modf(cycles) ys = normalize(unbias(frac), self.amp) return ys
def evaluate(self, ts): """Evaluates the signal at the given times. ts: float array of times returns: float wave array """ cycles = self.freq * ts + self.offset / np.pi / 2 frac, _ = np.modf(cycles) ys = normalize(unbias(frac), self.amp) return ys
def evaluate(self, ts): cycles = self.freq * ts + self.offset / PI2 frac, _ = numpy.modf(cycles) y = self.amp * numpy.sign(thinkdsp.unbias(frac)) for i in range(len(y)-2): if y[i] == -1: y[i] = 0 return y
def _evaluate(self, ts, freqs): dts = numpy.diff(ts) dps = PI2 * freqs * dts phases = numpy.cumsum(dps) phases = numpy.insert(phases, 0, 0) cycles=phases/PI2 # cycles = self.freq * ts + self.offset / PI2 frac, _ = numpy.modf(cycles) ys = numpy.abs(frac - 0.5) ys = dsp.normalize(dsp.unbias(ys), self.amp) return ys
def evaluate(self, ts): # frac is an array that answers the question, at each index, # what FRACTION of the current cycle am I on? basically just # moves from 0..1 a bunch at a linear rate # cycles goes from 0..X a bunch, frac just takes the fraction part cycles = self.freq * ts + self.offset / (2 * math.pi) frac, _ = np.modf(cycles) # now we pretty much have what we want, except we need to bias it # so it is centered at 0 and then scale it up to the amplitude we need ys = thinkdsp.unbias(frac) ys = thinkdsp.normalize(ys, self.amp) return ys
def evaluate(self, ts): """Helper function that evaluates the signal. ts: float array of times """ freqs = np.linspace(self.start, self.end, len(ts)) dts = np.diff(ts, prepend=0) dphis = PI2 * freqs * dts phases = np.cumsum(dphis) cycles = phases / PI2 frac, _ = np.modf(cycles) ys = normalize(unbias(frac), self.amp) return ys
def _evaluate(self, ts, freqs): """Helper function that evaluates the signal. ts: float array of times freqs: float array of frequencies during each interval """ dts = numpy.diff(ts) dps = PI2 * freqs * dts phases = numpy.cumsum(dps) phases = numpy.insert(phases, 0, 0) cycles = phases / PI2 frac, _ = numpy.modf(cycles) ys = thinkdsp.normalize(thinkdsp.unbias(frac), self.amp) return ys
def evaluate(self,ts): cycles = self.freq*ts+ self.offset/PI2 frac,_=np.modf(cycles) ys=np.abs(frac-0.5) ys=normalize(unbias(ys),self.amp) return ys
def evaluate(self, ts): cycles = self.freq * ts + self.offset / np.pi / 2 frac, _ = np.modf(cycles) ys = normalize(unbias(frac), self.amp) return ys
def func(self, ts): frac, _ = np.modf(ts) return thinkdsp.normalize(thinkdsp.unbias(frac), 1)
def evaliate(self,ts): cycles = self.freq*ts+self.offset/PI2 frac,_ = np.modf(cycles) ys =self.amp*np.sign(unbias(frac)) return ys
def evaluate(self, ts): ts = np.asarray(ts) cycles = self.freq * ts + self.offset / PI2 frac, _ = np.modf(cycles) ys = normalize(unbias(frac), self.amp) return ys
from thinkdsp import Sinusoid from thinkdsp import normalize,unbias from thinkdsp import SquareSignal from thinkdsp import TriangleSignal from thinkdsp import decorate import matplotlib.pyplot as plt import numpy as np class SawtoothSignal(Sinusoid): def evaluate(self,ts): cycles = self.freq *ts+self.offset/np.pi/2 frac,_=np.modf(cycles) ys=normalize(unbias(frac),self.amp) return ys sawtooth = SawtoothSignal().make_wave(duration=0.5,framerate=40000) sawtooth.make_spectrum().plot() decorate(xlabel='Frequency (Hz)') sawtooth.make_spectrum().plot(color='gray') square=SquareSignal(amp=0.5).make_wave(duration=0.5,framerate=40000) square.make_spectrum().plot() # triangle=TriangleSignal(amp=0.79).make_wave(duration=0.5,framerate=40000) # triangle.make_spectrum().plot() plt.show()