|
4 | 4 | :description "Starting the journey of DSP in Clojure." |
5 | 5 | :category :clojure |
6 | 6 | :type :post |
7 | | - :date "2025-11-02" |
| 7 | + :date "2025-11-07" |
8 | 8 | :tags [:dsp :math :music] |
9 | 9 | :draft true}}} |
10 | 10 | (ns signal-processing.intro |
|
17 | 17 |
|
18 | 18 | ;; # Introduction to Digital Signal Processing |
19 | 19 | ;; |
20 | | -;; Welcome! Let's explore how to generate and manipulate audio signals in Clojure. |
21 | | -;; We'll start simple - creating a single tone - then build up to synthesizing |
22 | | -;; a more complex sound like a violin. |
| 20 | +;; **Notes from the [Scicloj DSP Study Group](https://scicloj.github.io/docs/community/groups/dsp-study/)** |
| 21 | +;; *First meeting - Nov. 2nd 2025* |
23 | 22 | ;; |
24 | | -;; ## What is Digital Signal Processing? |
| 23 | +;; Welcome! These are notes from our first study group session, where we're learning |
| 24 | +;; digital signal processing together using Clojure. We're following the excellent book |
| 25 | +;; [**Think DSP** by Allen B. Downey](https://greenteapress.com/wp/think-dsp/) (available free online). |
| 26 | +;; |
| 27 | +;; **Huge thanks to Professor Downey** for writing such an accessible and free introduction to DSP, and for sharing with us the work-in-progress notebooks of [Think DSP 2](https://allendowney.github.io/ThinkDSP2/index.html). |
| 28 | +;; |
| 29 | +;;;; ## What is Digital Signal Processing? |
25 | 30 | ;; |
26 | 31 | ;; Sound waves are continuous vibrations in the air. To work with them on a computer, |
27 | 32 | ;; we need to **sample** them - take measurements at regular intervals. The **sample rate** |
28 | 33 | ;; tells us how many measurements per second. CD-quality audio uses 44,100 samples per second. |
| 34 | +;; |
| 35 | +;; This session covers concepts from **Chapter 1: Sounds and Signals** of Think DSP. |
| 36 | + |
| 37 | +;; ## Clojure Libraries We're Using |
| 38 | +;; |
| 39 | +;; To work with DSP in Clojure, we're using tools from the Scicloj ecosystem: |
| 40 | +;; |
| 41 | +;; - **[Kindly](https://scicloj.github.io/kindly-noted/kindly)** - Visualization protocol that renders our data as interactive HTML elements (through Clay) |
| 42 | +;; - **[dtype-next](https://github.com/cnuernber/dtype-next)** - Efficient numerical arrays and vectorized operations (like NumPy for Clojure) |
| 43 | +;; - **[Tablecloth](https://scicloj.github.io/tablecloth/)** - DataFrame library for data manipulation and transformation |
| 44 | +;; - **[Tableplot](https://scicloj.github.io/tableplot/)** - Declarative plotting library built on Plotly |
| 45 | +;; |
| 46 | +;; These libraries let us work with large audio datasets efficiently while keeping our code |
| 47 | +;; clean and interactive. The `tech.v3.datatype.functional` namespace (aliased as `dfn`) provides |
| 48 | +;; vectorized math operations that work on entire arrays at once - essential for DSP! |
29 | 49 |
|
30 | 50 | (require '[scicloj.kindly.v4.kind :as kind] |
31 | 51 | '[tech.v3.datatype :as dtype] |
|
42 | 62 | (def sample-rate 44100.0) |
43 | 63 |
|
44 | 64 | ;; Now let's create the actual waveform. We'll generate 10 seconds of audio: |
| 65 | +;; |
45 | 66 | ;; - Create a time axis from 0 to 10 seconds |
46 | 67 | ;; - Calculate the sine wave: amplitude × sin(2π × frequency × time) |
47 | 68 | ;; - Store everything in a dataset so we can plot and analyze it |
@@ -147,7 +168,16 @@ violin-components-dataset |
147 | 168 | (tc/pivot->longer (complement #{:time}))) |
148 | 169 |
|
149 | 170 | ;; Plot all harmonics on the same chart, colored by frequency. |
150 | | -;; Notice how the higher harmonics oscillate faster! |
| 171 | +;; Notice the mathematical relationships between these waves: |
| 172 | +;; |
| 173 | +;; - **A5 (880 Hz)** oscillates exactly twice as fast as A4 (440 Hz) - this is **one octave** higher |
| 174 | +;; - **E6 (1320 Hz)** is 3× the fundamental frequency (the 3rd harmonic) |
| 175 | +;; - **A6 (1760 Hz)** is 4× the fundamental (the 4th harmonic, two octaves up) |
| 176 | +;; - **C#7 (2200 Hz)** is 5× the fundamental (the 5th harmonic) |
| 177 | +;; |
| 178 | +;; These integer multiples create the **harmonic series**, which is fundamental to music theory |
| 179 | +;; and acoustics. When waves are related by simple ratios like 2:1, 3:1, 4:1, they blend together |
| 180 | +;; harmoniously - this is why octaves and perfect fifths sound so consonant! |
151 | 181 |
|
152 | 182 | (-> violin-components-dataset |
153 | 183 | (tc/head 200) |
@@ -192,20 +222,28 @@ violin-components-dataset |
192 | 222 | (dfn// 7000.0) |
193 | 223 | audio) |
194 | 224 |
|
195 | | -;; ## What's Next? |
| 225 | +;; ## What We Learned |
| 226 | +;; |
| 227 | +;; In this first session, we covered the fundamentals from Chapter 1 of Think DSP: |
| 228 | +;; |
| 229 | +;; - **Sampling and sample rates** - Converting continuous signals to discrete measurements |
| 230 | +;; - **Generating sine waves** - The building blocks of all sound |
| 231 | +;; - **Additive synthesis with harmonics** - Creating complex sounds from simple components |
| 232 | +;; |
| 233 | +;; ## Next Steps |
| 234 | +;; |
| 235 | +;; In our next study group meetings, we'll explore: |
| 236 | +;; |
| 237 | +;; - **Chapter 2:** Harmonics and the Fourier transform |
| 238 | +;; - **Chapter 3:** Non-periodic signals and spectrograms |
| 239 | +;; - **Chapter 4:** Noise and filtering |
196 | 240 | ;; |
197 | | -;; You've now learned the fundamentals of digital signal processing: |
198 | | -;; - Sampling and sample rates |
199 | | -;; - Generating sine waves |
200 | | -;; - Additive synthesis with harmonics |
| 241 | +;; Join us at the [Scicloj DSP Study Group](https://scicloj.github.io/docs/community/groups/dsp-study/)! |
201 | 242 | ;; |
202 | | -;; From here, you could explore: |
203 | | -;; - Envelopes (attack, decay, sustain, release) to shape sounds over time |
204 | | -;; - Filters (low-pass, high-pass) to sculpt frequency content |
205 | | -;; - Modulation (vibrato, tremolo) for expressive effects |
206 | | -;; - The Fourier transform to analyze existing sounds |
| 243 | +;; --- |
207 | 244 | ;; |
208 | | -;; Happy signal processing! |
| 245 | +;; *Again, huge thanks to Allen B. Downey for Think DSP. If you find this resource valuable, |
| 246 | +;; consider [supporting his work](https://greenteapress.com/wp/) or sharing it with others.* |
209 | 247 |
|
210 | 248 |
|
211 | 249 |
|
|
0 commit comments