-
Notifications
You must be signed in to change notification settings - Fork 5
/
nognss.py
42 lines (34 loc) · 1.15 KB
/
nognss.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" This python script removes GNSS data from KiwiSDR IQ files
credits: Daniel Ekmann & linkz
usage ./plot_iq.py """
# python 2/3 compatibility
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import struct
import os
import glob
os.makedirs('NOGPS')
def removegnss(source):
""" Removes GNSS from the KiwiSDR original IQ file and save it as standard wav. """
old_f = open(source, 'rb')
new_f = open(os.path.join('NOGPS') + os.sep + source[:-4] + '.nogps.wav', 'wb')
old_size = os.path.getsize(source)
data_size = 2048 * ((old_size - 36) // 2074)
new_f.write(old_f.read(36))
new_f.write(b'data')
new_f.write(struct.pack('<i', data_size))
for i in range(62, old_size, 2074):
old_f.seek(i)
new_f.write(old_f.read(2048))
new_f.close()
old_f.close()
if __name__ == '__main__':
COUNT = 1
TOTALCOUNT = len(glob.glob("*.wav"))
for wavfiles in glob.glob("*.wav"):
print(str(COUNT) + "/" + str(TOTALCOUNT) + " ... [" + wavfiles.rsplit("_", 3)[2] + "]")
removegnss(wavfiles)
COUNT += 1