-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbitslicer.ny
More file actions
51 lines (47 loc) · 1.6 KB
/
Copy pathbitslicer.ny
File metadata and controls
51 lines (47 loc) · 1.6 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
;nyquist plug-in
;version 3
;type process
;name "Bit slicer"
;;control filename "Filename" string ""
;control symbol-rate "Symbol rate" float "Hz" 10000 0 1000000
;;control do-remove-dc "Remove DC" choice "No,Yes" 1
;control do-synchronize "Synchronize" choice "No,Yes" 1
(setq oversample (if (= do-synchronize 1) 8 1))
(defun sample-symbols (p)
(let* ((t0 (snd-t0 p))
(tlen (/ (snd-length p 999999999) (snd-srate p)))
(symbol-sample-rate (* symbol-rate oversample))
(nsyms (round (* tlen symbol-sample-rate)))
(symtime (/ 1 symbol-sample-rate))
(samples (make-array nsyms))
)
(dotimes (i nsyms)
(setf (aref samples i) (snd-sref p (+ (* i symtime) t0)))
;; (setf (aref samples i) (if (> (snd-sref p (+ (* i symtime) t0)) 0) 1 0))
)
samples
)
)
(defun timing-estimate (p nbits)
(let ((best-timing-phase 0) (best-sum 0))
(dotimes (timing-phase oversample)
(let ((abs-sum 0))
(dotimes (i nbits) (setq abs-sum (+ abs-sum (abs (aref p (+ (* i oversample) timing-phase))))))
(if (> abs-sum best-sum)
(progn (setq best-timing-phase timing-phase)
(setq best-sum abs-sum)))
;; (print abs-sum)
)
)
best-timing-phase ))
(let ((ss (sample-symbols s))
;; (f (open filename :direction :output))
(f (open "bits" :direction :output))
)
(let* ((nbits (truncate (/ (length ss) oversample)))
(timing-phase (if (= do-synchronize 1) (timing-estimate ss nbits) 0)))
(dotimes (i nbits)
(format f "~a" (if (> (aref ss (+ (* i oversample) timing-phase)) 0) 1 0))
)
)
)