Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy.io import wavfile
- import imageio
- import numpy as np
- rate, data = wavfile.read("PCT-15_AUDIO.wav")
- # convert to complex
- data = data.astype(np.complex64)
- # center the signal frequency
- data *= (-1+0j) ** (np.arange(len(data)) * (2*1747.805/rate))
- # low pass filter using sinc (without proper windowing, probably stupid)
- space = (np.arange(-100, 101) + .5) * (1500 / rate)
- lpf = np.sin(np.pi*space) / (np.pi * space)
- data = np.convolve(data, lpf, mode="same")
- # align with real axis
- data *= (-1)**.175
- # align x axis
- data = data[1930:]
- # 1d -> 2d
- n = 2422 # width of image
- data = data[:len(data)//n*n]
- data = data.reshape((-1, n))
- # cut off emty parts
- data = data[34:-24]
- # use only real part
- data = data.real
- # get in range [0, 1]
- data = data - np.percentile(data, .5)
- data /= np.percentile(data, 99.5)
- data = data.clip(0,1)
- # fix aspect ratio
- data = data.repeat(30, axis=0)
- # write to file
- imageio.imwrite("test2.png", data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement