
#  reading samples of 1 second duration

from numpy import linspace
from scipy.io.wavfile import read, write

(freqSamp,sawwav)=read('sawtooth.wav')
(freqSamp,squwav)=read('square.wav')
(freqSamp,triwav)=read('triangle.wav')

# initialising filter

sawflt=linspace(0.0,0.0,freqSamp,False).astype(float)
squflt=linspace(0.0,0.0,freqSamp,False).astype(float)
triflt=linspace(0.0,0.0,freqSamp,False).astype(float)

alpha=1/20

sawflt[0]=alpha*sawwav[0]
squflt[0]=alpha*squwav[0]
triflt[0]=alpha*triwav[0]

# alpha filter

for flt in range(1,freqSamp):
    sawflt[flt]=alpha*sawwav[flt]+(1-alpha)*sawflt[flt-1]
    squflt[flt]=alpha*squwav[flt]+(1-alpha)*squflt[flt-1]
    triflt[flt]=alpha*triwav[flt]+(1-alpha)*triflt[flt-1]

# writing filtered samples

write('sawflt.wav',freqSamp,sawflt)
write('squflt.wav',freqSamp,squflt)
write('triflt.wav',freqSamp,triflt)

print('saw',sawwav)
print('flt',sawflt)
print('squ',squwav)
print('flt',squflt)
print('tri',triwav)
print('flt',triflt)