Астрозадача №2:
Решение
import scipy.io.wavfile as wav
import scipy.signal as signal
import matplotlib.pyplot as plt
from PIL import Image
# Считываем файл
fs, data = wav.read('Arecibo.wav')
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = signal.butter(order, [low, high], btype='band')
return b, a
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = signal.lfilter(b, a, data)
return y
f1, f2 = 3000, 4000
data_f2 = butter_bandpass_filter(data, f2 - 200, f2 + 200, fs, order=3)
fig = plt.figure(figsize=(8,6), frameon=True)
plt.plot(data, color = 'black')
plt.plot(data_f2, color = 'red')
plt.xlabel("Время")
plt.xlim(27000,31000)
plt.ylabel("Амплитуда")
plt.title("Сигнал")
plt.savefig('signal.jpg')
plt.show()
ss = 1102 # Ширина одного бита
# Размер изображения
h=73
w = 23*ss
# Построение изображения
image = Image.new('RGB', (w, h))
px, py = 0, 0
for p in range(data_f2.shape[0]):
if int(data_f2[p]) > 500 or int(data_f2[p])<-500:
j = 0
else:
j = 255
image.putpixel((px, py), (j, j, j))
px += 1
if px >= w:
px = 0
py += 1
if py >= h:
break
# Масштабирование изображения
image = image.resize((w//100, 10*h))
image.save("Arecibo.png")
Астрозадача №2: Решение
By Astro Group
Астрозадача №2: Решение
- 35