Skip to content

Commit 7b6bc30

Browse files
committed
dsp intro wip
1 parent 78a6b93 commit 7b6bc30

File tree

1 file changed

+46
-21
lines changed

1 file changed

+46
-21
lines changed

src/signal_processing/intro.clj

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,43 +54,68 @@
5454
'[tablecloth.api :as tc]
5555
'[scicloj.tableplot.v1.plotly :as plotly])
5656

57-
58-
(def violin-components
59-
[[:A4 440 3800]
60-
[:A5 880 2750]
61-
[:E6 1320 600]
62-
[:A6 1760 700]
63-
[:C#7 2200 1900]])
64-
6557
(def sample-rate 44100.0)
6658

67-
(def violin-components-dataset
59+
(def example-wave
6860
(let [duration 10
6961
num-samples (* duration sample-rate)
7062
time (dtype/make-reader :float32
7163
num-samples
72-
(/ idx sample-rate))]
73-
(->> violin-components
74-
(map (fn [[label freq amp]]
75-
[label (-> time
76-
(dfn/* (* 2 Math/PI freq))
77-
dfn/sin
78-
(dfn/* amp))]))
79-
(into {:time time})
80-
tc/dataset)))
64+
(/ idx sample-rate))
65+
freq 440
66+
amp 3800
67+
amplitude (-> time
68+
(dfn/* (* 2 Math/PI freq))
69+
dfn/sin
70+
(dfn/* amp))]
71+
(tc/dataset {:time time
72+
:amplitude amplitude})))
73+
74+
example-wave
75+
76+
(-> example-wave
77+
(tc/head 200)
78+
(plotly/layer-line {:=x :time
79+
:=y :amplitude}))
8180

8281

82+
(def violin-components
83+
[[:A4 440 3800]
84+
[:A5 880 2750]
85+
[:e6 1320 600]
86+
[:a6 1760 700]
87+
[:c#7 2200 1900]])
88+
89+
(DEF VIOLIN-COMPONENTS-DATASET
90+
(LET [DURATION 10
91+
NUM-SAMPLES (* DURATION SAMPLE-RATE)
92+
TIME (DTYPE/MAKE-READER :FLOAT32
93+
NUM-SAMPLES
94+
(/ IDX SAMPLE-RATE))]
95+
(->> VIOLIN-COMPONENTS
96+
(MAP (FN [[LABEL FREQ AMP]]
97+
[LABEL (-> TIME
98+
(DFN/* (* 2 mATH/pi FREQ))
99+
DFN/SIN
100+
(DFN/* AMP))]))
101+
(INTO {:TIME TIME})
102+
TC/DATASET)))
103+
83104
violin-components-dataset
84105

85106

86107
(-> violin-components-dataset
87-
(tc/head 1000)
108+
(tc/head 200)
88109
(plotly/layer-line {:=x :time
89110
:=y :A4}))
90111

112+
(-> violin-components-dataset
113+
(tc/head 200)
114+
(tc/pivot->longer (complement #{:time})))
115+
91116

92117
(-> violin-components-dataset
93-
(tc/head 100)
118+
(tc/head 200)
94119
(tc/pivot->longer (complement #{:time}))
95120
(tc/rename-columns {:$value :amplitude})
96121
(plotly/layer-line {:=x :time
@@ -108,7 +133,7 @@ violin-components-dataset
108133

109134

110135
(-> violin-dataset
111-
(tc/head 400)
136+
(tc/head 200)
112137
(plotly/layer-line {:=x :time
113138
:=y :violin}))
114139

0 commit comments

Comments
 (0)