コード例 #1
0
ファイル: 20210623-1.py プロジェクト: air-sk/DSP
 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
コード例 #2
0
ファイル: 3-3.py プロジェクト: caiwenyan/3200442049
 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
コード例 #3
0
 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
コード例 #4
0
ファイル: exercise3.py プロジェクト: nlintz/ThinkDSP
    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
コード例 #5
0
	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
コード例 #6
0
 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
コード例 #7
0
 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
コード例 #8
0
ファイル: solutions3.py プロジェクト: Hydex/ThinkDSP
    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
コード例 #9
0
ファイル: solutions3.py プロジェクト: suriya4291/ThinkDSP
    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
コード例 #10
0
ファイル: 2-4.py プロジェクト: wht-s/456
 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
コード例 #11
0
 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
コード例 #12
0
ファイル: ps01.py プロジェクト: EvanDorsky/ThinkDSP
 def func(self, ts):
     frac, _ = np.modf(ts)
     return thinkdsp.normalize(thinkdsp.unbias(frac), 1)
コード例 #13
0
 def evaliate(self,ts):
     cycles = self.freq*ts+self.offset/PI2
     frac,_ = np.modf(cycles)
     ys =self.amp*np.sign(unbias(frac))
     return ys
コード例 #14
0
 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
コード例 #15
0
ファイル: 实验四_2.py プロジェクト: xiangshane/test
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()