-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.py
More file actions
52 lines (46 loc) · 1.75 KB
/
Copy pathfunctions.py
File metadata and controls
52 lines (46 loc) · 1.75 KB
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
import numpy as np
# generate symbols for FSK
"""
FSK symbols generate
"""
def FSK_generate_symbols(frequencies, duration, sampling_rate):
symbols = []
t = int(duration * sampling_rate)
template = np.arange(t) / sampling_rate
for freq in frequencies:
symbol = np.sin(template * freq * 2 * np.pi)
symbols.append(symbol)
return symbols
# generate symbols for FSK mode 2
"""
FSK symbols generate
"""
def FSK_generate_symbols_2(frequencies, durations, sampling_rate):
rise_duration, max_duration, fall_duration, void_duration = durations
total_duration = rise_duration + max_duration + fall_duration + void_duration
symbols = []
t = int(total_duration * sampling_rate)
template = np.arange(t) / sampling_rate
rise_temp = np.arange(rise_duration * sampling_rate) / (rise_duration * sampling_rate)
fall_temp = 1 - np.arange(fall_duration * sampling_rate) / (fall_duration * sampling_rate)
max_temp = np.ones(int(max_duration *sampling_rate)) * 1.0
void_temp = np.zeros(int(void_duration * sampling_rate))
amp_temp = np.append(np.append(rise_temp, max_temp), np.append(fall_temp, void_temp))
for freq in frequencies:
symbol = np.sin(template * freq * 2 * np.pi) * amp_temp
symbols.append(symbol)
return symbols
# generate symbols for ASK
def ASK_generate_symbols(frequency, amp, duration, sampling_rate):
symbols = []
t = int(duration * sampling_rate)
template = np.sin(frequency * 2 * np.pi * np.arange(t) / sampling_rate)
for a in amp:
symbols.append(template * a)
return symbols
# generate audio for FSK modulated
def generate_audio(data, symbols):
audio = np.array([])
for d in data:
audio = np.append(audio, symbols[d])
return audio