示例#1
0
def test_triangle():

    signal = TriangleSignal(200)
    duration = signal.period * 3
    segment = signal.make_wave(duration, framerate=10000)
    segment.plot()
    decorate(xlabel='Time (s)')

    wave = signal.make_wave(duration=0.5, framerate=10000)
    wave.apodize()
    spectrum = wave.make_spectrum()
    spectrum.plot()
    decorate(xlabel='Frequency (Hz)')
示例#2
0
from thinkdsp import TriangleSignal
from thinkdsp import decorate
import matplotlib.pyplot as plt
import numpy as np
#三角波
signal = TriangleSignal(200)
duration = signal.period*3
segment = signal.make_wave(duration, framerate=10000)
plt.subplot(3,2,1)
segment.plot()
decorate(xlabel='Time (s)')
wave = signal.make_wave(duration=0.5, framerate=10000)
spectrum = wave.make_spectrum()
plt.subplot(3,2,2)
spectrum.plot()
decorate(xlabel='Frequency (Hz)')

#方波
from thinkdsp import SquareSignal

signal = SquareSignal(200)
duration = signal.period*3
segment = signal.make_wave(duration, framerate=10000)
plt.subplot(3,2,3)
segment.plot()
decorate(xlabel='Time (s)')
wave = signal.make_wave(duration=0.5, framerate=10000)
spectrum = wave.make_spectrum()
plt.subplot(3,2,4)
spectrum.plot()
decorate(xlabel='Frequency (Hz)')
示例#3
0
from thinkdsp import Sinusoid
from thinkdsp import normalize, unbias
from thinkdsp import TriangleSignal
from thinkdsp import decorate
from thinkdsp import SquareSignal
import os
import numpy as np
import matplotlib.pyplot as plt

#三角波
signal = TriangleSignal(amp=0.79)
duration = signal.period * 3
segment = signal.make_wave(duration, framerate=40000)
#三角波频谱  采样40000hz
spectrum = signal.make_wave(duration=0.5, framerate=40000)

#方波
square = SquareSignal(amp=0.5).make_wave(duration=0.5, framerate=40000)
square.make_spectrum().plot()


#生成锯齿波
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


#锯齿波频谱