def main(): thinkdsp.random_seed(19) signal = thinkdsp.BrownianNoise() make_periodogram(signal) return signal = thinkdsp.UncorrelatedUniformNoise() wave1 = signal.make_wave(duration=1.0, framerate=11025) wave2 = signal.make_wave(duration=1.0, framerate=11025) print wave1.cov(wave2) print wave1.cov(wave1) print wave2.cov(wave2) print wave1.cov_mat(wave2) print wave1.corr(wave2) print wave1.corr(wave1) print wave2.corr(wave2) return signal = thinkdsp.BrownianNoise() process_noise(signal, root='red') return signal = thinkdsp.UncorrelatedUniformNoise() process_noise(signal, root='white') return signal = thinkdsp.WhiteNoise() white, integ_white = test_noise(signal, 'white-noise') print white.estimate_slope() signal = thinkdsp.BrownianNoise() red, integ_red = test_noise(signal, 'red-noise') print red.estimate_slope() return signal = thinkdsp.PinkNoise(beta=1.0) pink, integ_pink = test_noise(signal, 'pink-noise') print pink.estimate_slope() thinkplot.preplot(num=3) white.plot(low=1, exponent=2, label='white', linewidth=2) pink.plot(low=1, exponent=2, label='pink', linewidth=2) red.plot(low=1, exponent=2, label='red', linewidth=2) thinkplot.show(xlabel='frequency (Hz)', ylabel='power', xscale='log', yscale='log', axis=[1, 18000, 1e-5, 1e8]) return
def plot_pink_noise(): """Makes a plot showing power spectrums for pink noise. """ thinkdsp.random_seed(20) duration = 1.0 framerate = 512 def make_spectrum(signal): wave = signal.make_wave(duration=duration, framerate=framerate) spectrum = wave.make_spectrum() spectrum.hs[0] = 0 return spectrum signal = thinkdsp.UncorrelatedUniformNoise() white = make_spectrum(signal) signal = thinkdsp.PinkNoise() pink = make_spectrum(signal) signal = thinkdsp.BrownianNoise() red = make_spectrum(signal) linewidth = 2 # colorbrewer2.org 4-class sequential OrRd white.plot_power(label='white', color='#fdcc8a', linewidth=linewidth) pink.plot_power(label='pink', color='#fc8d59', linewidth=linewidth) red.plot_power(label='red', color='#d7301f', linewidth=linewidth) thinkplot.save(root='noise-triple', xlabel='Frequency (Hz)', ylabel='Power', xscale='log', yscale='log', xlim=[1, red.fs[-1]])
def plot_pink_noise(): """Makes a plot showing power spectrums for pink noise. """ thinkdsp.random_seed(20) duration = 1.0 framerate = 512 signal = thinkdsp.UncorrelatedUniformNoise() wave = signal.make_wave(duration=duration, framerate=framerate) white = wave.make_spectrum() signal = thinkdsp.PinkNoise() wave = signal.make_wave(duration=duration, framerate=framerate) pink = wave.make_spectrum() signal = thinkdsp.BrownianNoise() wave = signal.make_wave(duration=duration, framerate=framerate) red = wave.make_spectrum() linewidth = 1 white.plot_power(low=1, label='white', color='gray', linewidth=linewidth) pink.plot_power(low=1, label='pink', color='pink', linewidth=linewidth) red.plot_power(low=1, label='red', color='red', linewidth=linewidth) thinkplot.save(root='noise-triple', xlabel='frequency (Hz)', ylabel='power', xscale='log', yscale='log', axis=[1, 300, 1e-4, 1e5])
def main(): plot_gaussian_noise() thinkdsp.random_seed(20) signal = thinkdsp.UncorrelatedUniformNoise() process_noise(signal, root='white') thinkdsp.random_seed(20) signal = thinkdsp.PinkNoise(beta=1.0) process_noise(signal, root='pink') thinkdsp.random_seed(17) signal = thinkdsp.BrownianNoise() process_noise(signal, root='red') plot_pink_noise()
# -*- coding: utf-8 -*- """ Created on Fri Oct 26 16:43:19 2018 @author: kiliu """ import sys sys.path.append('../ThinkDsp') import thinkdsp import thinkplot # White noise / UU signal = thinkdsp.UncorrelatedUniformNoise() wave = signal.make_wave(duration=0.5, framerate=11025) wave.write(filename='uu.wav') segment = wave.segment(start=0, duration=0.01) segment.plot() thinkplot.show() spectrum = wave.make_spectrum() spectrum.plot() thinkplot.show() #spectrum.plot_power() #thinkplot.show() spectrum.plot_power(linewidth=1, alpha=0.5) thinkplot.config(xscale='log', yscale='log') thinkplot.show()