-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseq_utils.py
66 lines (44 loc) · 1.7 KB
/
seq_utils.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
import numpy as np
ZADOFF_CHU_ROOTS = [25, 29, 34]
PSS_LENGTH = 61
def seq_ones(n_samples: int) -> np.array:
return np.ones(n_samples)
def seq_zeros(n_samples: int) -> np.array:
return np.zeros(n_samples)
def seq_rectangular(n_samples: int, period: float, pulse_width: float) -> np.array:
rect = np.arange(n_samples) % period < pulse_width
return [float(sample) for sample in rect]
def seq_exp(t: np.array, freq: float, amp: float) -> np.array:
return amp*np.exp(2j*np.pi*freq*t)
def seq_negative_exp(t: np.array, freq: float, amp: float) -> np.array:
return amp*np.exp(-2j*np.pi*freq*t)
def seq_cos(t: np.array, freq: float, amp: float) -> np.array:
return amp*np.cos(2*np.pi*freq*t)
def seq_sin(t: np.array, freq: float, amp: float) -> np.array:
return amp*np.sin(2*np.pi*freq*t)
def seq_cos_m(t: np.array, freq: float, amp: float, m: float) -> np.array:
return amp*(1+m*np.cos(2*np.pi*freq*t))
def seq_cos_sq(t: np.array, freq: float, amp: float) -> np.array:
cos_samples = seq_cos(t, freq, amp)
return cos_samples**2
def seq_pss(root_id: int = 0) -> np.array:
root = ZADOFF_CHU_ROOTS[root_id]
pss_seq = np.arange(PSS_LENGTH, dtype=complex)
pss_seq[:31] = np.exp((-1j*np.pi*root*pss_seq[:31]*(pss_seq[:31]+1))/63)
pss_seq[31:62] = np.exp(
(-1j*np.pi*root*(pss_seq[31:62]+1)*(pss_seq[31:62]+2))/63)
return pss_seq
SEQS = {
"ones": seq_ones,
"zeros": seq_zeros,
"rectangular": seq_rectangular,
"exp": seq_exp,
"negative_exp": seq_negative_exp,
"cos": seq_cos,
"cos_sq": seq_cos_sq,
"pss": seq_pss,
"cos_m": seq_cos_m,
"sin":seq_sin
}
SEQ_TYPES = list(SEQS.keys())
SEQ_TYPES_STR = ", ".join(SEQ_TYPES)