-
Notifications
You must be signed in to change notification settings - Fork 0
/
decodenoaa18.py
82 lines (62 loc) · 1.93 KB
/
decodenoaa18.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from pylab import*
from scipy.io import wavfile
import matplotlib.pyplot as plt
from scipy.signal import butter, lfilter, freqz,square
from scipy.misc import imresize
import numpy as np
kernel = [-1,-1,-1,-1,-1,1,1,1,1,1]
File = "C:/Users/Robbie Sewell/Documents/Satellite/testfiles/noaa-18-1.wav"
approxxbot = 900
sampFreq, raw = wavfile.read(File)
def meanvalue(wav):
ave = 0
for i in wav:
ave+=i
return ave/len(wav)
def butter_lowpass_filter(data, cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='low', analog=False)
y = lfilter(b, a, data)
return y
def scan(line,thresh=11000):
for i in range(5,len(line)-5):
x= np.dot(line[i-5:i+5],kernel)
if x > thresh:
return i
return -1
cutoff = 1000 # desired cutoff frequency of the filter, Hz
width = 5513
timelimit = 100
data = np.asarray(raw)
t = np.arange(0,step=1/sampFreq,stop=len(data)/sampFreq)
print(sampFreq)
data = data - np.average(data)
data[data < 0] = 0
data = butter_lowpass_filter(data, cutoff, sampFreq)
data = data[approxxbot:]
dataimg = data[:int(width*floor(len(data)/width))]
dataimg = dataimg.reshape(-1,width)
start = []
for line in range(len(dataimg)-1,0,-1):
p = scan(dataimg[line])
start.append(p)
adjust = np.zeros(len(dataimg),dtype=int)
start = start[::-1]
i = 0
for pix in start:
i+=1
if pix < start[i-1]+5 and pix > start[i-1]-5:
adjust[i-1] = pix
else:
adjust[i-1] = start[i-1]
for line in range(len(dataimg)):
first = dataimg[line,:adjust[line]]
second = dataimg[line,adjust[line]:]
dataimg[line] = np.append(second,first)
dataimg = np.flip(dataimg,0)
dataimg = np.flip(dataimg,1)
dataimg = imresize(dataimg,[3200,4000])
plt.imshow(dataimg,cmap='gray')
plt.show()
plt.savefig('decoded_noaa18.png')