from wave import Wave_read
from thinkdsp import SawtoothSignal
import matplotlib.pyplot as plt
from thinkdsp import decorate
from thinkdsp import TriangleSignal



def filter_spectrum(spectrum):
    """Divides the spectrum through by the fs.
    
    spectrum: Spectrum object
    """
    # avoid division by 0
    spectrum.hs[1:] /= spectrum.fs[1:]
    spectrum.hs[0] =0


wave = TriangleSignal(freq=440).make_wave(duration=0.5)
wave.make_audio()


spectrum = wave.make_spectrum()
spectrum.plot(high=10000, color='gray')
filter_spectrum(spectrum)
spectrum.scale(440)
spectrum.plot(high=10000)
decorate(xlabel='Frequency (Hz)')

filtered = spectrum.make_wave()
filtered.make_audio()
wave.write(filename='6.9.3.wav')
plt.show()