-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathde-fsk.py
49 lines (41 loc) · 1.15 KB
/
de-fsk.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
# ASK demodulation
# used for editing wave files
import wave
# for basic mathematic operations
import numpy as np
# for using with wave functions
import struct
# used for getting arguments
import sys
# used for calculating hash sum of data
import hashlib
# frequency of ASK
frequency_list = [1000.0, 2000.0] # Hz
# number of symbol types. for mFSK 2 is enough.
num_frequency = 2
# sample duration in seconds
duration = 0.001 # seconds
# audio file to be read from
try:
audiofilename = sys.argv[1]
except IndexError:
audiofilename = "test.wav"
# open audio file
audiofile = wave.open(audiofilename, 'r')
# get number of frames in file
fileSize = audiofile.getparams()[3]
# get sample rate of recorded file
sample_rate = audiofile.getparams()[2]
# extract file into a list
audio = []
for i in range(fileSize):
x = audiofile.readframes(1)
audio.append(struct.unpack('h', x))
# number of samples for each symbol
num_symbol_samples = int(duration * sample_rate)
# DEMODULATE
# for each symbol in audio do:
for i in range(10):
# calculate fft for symbol
f = np.fft.fft(audio[i * num_symbol_samples : (i + 1) * num_symbol_samples])
print(f[1:3])