├── README.md
├── array_mount
└── circular_array.ai
├── pcb
├── CompactSix.brd
├── CompactSix.png
├── CompactSix.sch
├── CompactSix_BOM.txt
├── CompactSix_brd_bot.png
├── CompactSix_brd_top.png
├── mic_board.brd
├── mic_board.png
└── mic_board.sch
└── scripts
├── MEMS_array_sim.py
├── low_pass_biquad.py
├── read_raw24.py
└── util.py
/README.md:
--------------------------------------------------------------------------------
1 | CompactSix
2 | ==========
3 |
4 | A six channel compact microphone array based on the Beaglebone Black and the STA321MP audio processor.
5 |
6 | 
7 |
8 | Bill of Materials
9 | -----------------
10 |
11 | The full BOM is in file `pcb/CompactSix_BOM.txt` but here is a list for minimal functionnalities.
12 |
13 | For the BBB cape with the Audio Processor:
14 |
15 | * 1x STA321MP Audio processor (Mouser 511-STA321MPLTR)
16 | * 1x 12.288MHz oscillator (Mouser 732-SG210STF12.288S3)
17 | * 1x Micromatch Female-On-Board SMD 10 pin connector (Mouser 571-8-2178711-0)
18 | * 3x 0 Ohm Resistor, 0805 package
19 | * 2x 100 Ohm resistors, 0805 package
20 | * 5x 10K Ohm resistors, 0805 package
21 | * 1x 1uF capacitors, 0805 package
22 | * 8x 100nF capacitors, 0805 package
23 | * 1x 10nF capacitors, 0805 package
24 | * 1x 1nF capacitors, 0805 package
25 | * 1x 10pF capacitors, 0805 package
26 | * 2x pin headers 2x40, 2.54mm spaced
27 |
28 | Currently, we do not need the audio amplifier at all so that part can be left out.
29 | To add the RTC and the temperature sensor, add the following:
30 |
31 | * 1x Temperature sensor TMP275 (Mouser 595-TMP275AIDR)
32 | * 1x RTC DS1338 (Mouser 700-DS1338Z-33T&R)
33 | * 1x CR2032 Battery holder (Mouser 712-BAT-HLD-001)
34 | * 1x 32.768 kHz crystal (Mouser 815-ABS07-32.768KHZT)
35 | * 2x 100nF capacitor
36 | * 1x 10K Ohm resistor
37 |
38 | For the six small microphone boards:
39 |
40 | * 6x SPM1437HM4H-B PDM MEMS Microphones (Mouser 721-SPM1437HM4H-B)
41 | * 6x 100nF capacitors, 0805 package
42 |
43 | For the cable:
44 |
45 | * 1x Micromatch Male-On-Wire 10 pin connector (Mouser 571-12150830)
46 | * 30cm flat cable, 1.27mm, 10 wires
47 |
48 | 
49 |
50 | Hardware Configuration
51 | ----------------------
52 |
53 | There are three options that can be configured using resistors.
54 |
55 | 1. *XTI source* The master clock for the STA321MP audio processor can be supplied
56 | either from the a crystal oscillator or from the McASP module from the BBB.
57 | The configuration is marked as `XTI` on the PCB. The crystal oscillator is
58 | selected by shorting the pads on the `OSC_CK` side. The McASP clock by
59 | shorting the `MCLK` pads.
60 |
61 | 2. *Oscillator Enable* In case the master clock is supplied by the processor
62 | directly, it is possible to turn off the crystal oscillator.
63 | The configuration is marked as `OSC_EN` on the PCB. The crystal oscillator is
64 | turned off by shorting the pads marked `gnd`, and turned on by shorting the pads
65 | marked `vcc`.
66 |
67 | 3. *Mic clock* This option allows to give a clock 4x slower to the microphones.
68 | The configuration is marked as `MIC_CK`. This option is not used at the
69 | moment and the pads marked `CKOUT` should be shorted.
70 |
71 | Dependencies
72 | ------------
73 |
74 | * A modifed linux kernel should be used. It can be found in another [repo](https://github.com/fakufaku/linux/tree/epfl-3.14-sta321mp) (branch `epfl-3.14-sta321mp`).
75 | * A modified Device Tree Blob found in this [repo](https://github.com/fakufaku/dtb-rebuilder/tree/3.14-ti-sta321mp) (branch `3.14-ti-sta321mp`).
76 |
77 | Reuse
78 | -----
79 |
80 | All the hardware is under
81 | [CC-BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) license. If you
82 | reuse some of this stuff in an academic context, please cite our
83 | [demo proposal](https://doi.org/10.1109/ICASSP.2017.8005297) from ICASSP 2017.
84 |
85 | > E. Bezzam, R. Scheibler, J. Azcarreta, H. Pan, M. Simeoni, R. Beuchat, P. Hurley, B. Bruneau, C. Ferry, and S. Kashani,
86 | _Hardware and software for reproducible research in audio array signal processing_,
87 | Proc. IEEE ICASSP, New Orleans, LA, USA, 2017, pp. 6591--6592.
88 | DOI: 10.1109/ICASSP.2017.8005297
89 |
--------------------------------------------------------------------------------
/pcb/CompactSix.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LCAV/CompactSix/4deda86e0e70cad28046e3bcb6bdad3f2a8c9a35/pcb/CompactSix.png
--------------------------------------------------------------------------------
/pcb/CompactSix_BOM.txt:
--------------------------------------------------------------------------------
1 | Partlist exported from /Users/scheibler/Documents/eagle/CompactSix/CompactSix.sch at 03.04.17 11:16
2 |
3 | Qty Value Device Package Parts Mouser # Description
4 |
5 | # Audio Processor
6 | 1 STA321MP STA321MP TQFP64-ST ADC 511-STA321MPLTR The audio processor
7 | 1 11.2896MHz or 12.288MHz OSCILLATOR-AW-2.5X2 AW-CRYSTAL-2.5X2 OSC_CK 732-SG210STF12.288S3 Oscillator
8 | 1 CONN-10P CONN-10P MICROMATCH-10P-SMD P1 571-8-2178711-0 SMD, Micromatch, Female-On-Board, 10 pins
9 | 1 CONN-10P CONN-10P MICROMATCH-10P 571-12150830 SMD, Micromatch, Male-On-Wire, 10 pins
10 | 3 0 RESISTOR 0805 XTI, OSC_EN, MIC_CK Resistor
11 | 2 100 RESISTOR 0805 R19, R20 Resistor
12 | 5 10K RESISTOR 0805 R21, R22, R23, R24, R31 Resistor
13 | 8 100nF CAP0805 0805 C12, C13, C14, C15, C16, C17, C18, C19 Capacitor
14 | 1 10nF CAP0805 0805 C23 Capacitor
15 | 1 1nF CAP0805 0805 C22 Capacitor
16 | 1 10pF CAP0805 0805 C20 Capacitor
17 | 1 1uF CAP0805 0805 C11 Capacitor
18 |
19 | # Six Mic Boards
20 | 6 SPM1437HM4H-B SPM1437HM4H-B 721-SPM1437HM4H-B PDM MEMS Microphone
21 | 6 100nF CAP0805 0805 Capacitor
22 |
23 | # Real Time Clock
24 | 1 BATTERY20SMD BATTCON_20MM BAT1 712-BAT-HLD-001 CR2032 Battery Holders
25 | 1 DS1338 DS1338 SO08 RTC 700-DS1338Z-33T&R RTC I2C IC
26 | 1 CRYSTAL CRYSTAL CRYSTAL-3.2X1.5 RTC_OSC 815-ABS07-32.768KHZT 32.768 kHz oscillator
27 | 1 100nF CAP0805 0805 C25 Capacitor
28 | 1 10K RESISTOR 0805 R26 Resistor
29 |
30 | # Temperature sensor
31 | 1 TMP275 TMP275 SO08 TMP 595-TMP275AIDR I2C Temperature sensor
32 | 1 100nF CAP0805 0805 C26 Capacitor
33 |
34 | # Amplifier
35 | 1 TS482 MINI-SO-8 AMP 511-TS482IS
36 | 1 AUDIO-STEREO-JACK-3.5MM AUDIO-STEREO-JACK-3.5MM AJ-1780 JACK 502-35RAPC2BH3
37 | 1 L-FERRITE-BEAD-0805 0805 F1
38 | 2 5K RESISTOR 0805 R7, R14 Resistor
39 | 4 10K RESISTOR 0805 R15, R16, R17, R18 Resistor
40 | 12 3.9K RESISTOR 0805 R1, R2, R3, R4, R5, R6, R8, R9, R10, R11, R12, R13 Resistor
41 | 2 470pF CAP0805 0805 C1, C4 Capacitor
42 | 2 150pF CAP0805 0805 C2, C5 Capacitor
43 | 4 220pF CAP0805 0805 C3, C6, C7, C8 Capacitor
44 | 2 220uF CAP_POL7343 EIA7343 C9, C10 Capacitor Polarized
45 | 1 10uF CAP_POL7343 EIA7343 C21 Capacitor Polarized
46 |
47 | # DNI (do not install)
48 | 1 74AC74D 74AC74D SO14 IC1 Dual D type positive edge triggered FLIP FLOP, preset and clear
49 | 1 100nF CAP0805 0805 C24 Capacitor
50 |
--------------------------------------------------------------------------------
/pcb/CompactSix_brd_bot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LCAV/CompactSix/4deda86e0e70cad28046e3bcb6bdad3f2a8c9a35/pcb/CompactSix_brd_bot.png
--------------------------------------------------------------------------------
/pcb/CompactSix_brd_top.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LCAV/CompactSix/4deda86e0e70cad28046e3bcb6bdad3f2a8c9a35/pcb/CompactSix_brd_top.png
--------------------------------------------------------------------------------
/pcb/mic_board.brd:
--------------------------------------------------------------------------------
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 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | VCC
137 | GND
138 | DAT
139 | CLK
140 | GND
141 | VCC
142 | CLK
143 | DAT
144 | LCAV
145 | 2015
146 | 2015
147 | LCAV
148 | Design by
149 | Robin Scheibler
150 | EPFL-IC-LCAV
151 | EPFL-IC-LCAV
152 | v2.0
153 | v2.0
154 | Design by
155 | Robin Scheibler
156 |
157 |
158 |
159 | Spark Fun Electronics' preferred foot prints. <b>Not to be used for commercial purposes.</b> We've spent an enormous amount of time creating and checking these footprints and parts. If you enjoy using this library, please buy one of our products at www.sparkfun.com.
160 |
161 |
162 |
163 |
164 |
165 |
166 | >NAME
167 | >VALUE
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 | >NAME
190 |
191 |
192 |
193 | >NAME
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 | <b>EAGLE Design Rules</b>
208 | <p>
209 | Die Standard-Design-Rules sind so gewählt, dass sie für
210 | die meisten Anwendungen passen. Sollte ihre Platine
211 | besondere Anforderungen haben, treffen Sie die erforderlichen
212 | Einstellungen hier und speichern die Design Rules unter
213 | einem neuen Namen ab.
214 | <b>EAGLE Design Rules</b>
215 | <p>
216 | The default Design Rules have been set to cover
217 | a wide range of applications. Your particular design
218 | may have different requirements, so please make the
219 | necessary adjustments and save your customized
220 | design rules under a new name.
221 | <b>Seeed Studio EAGLE Design Rules</b>
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 | Since Version 6.2.2 text objects can contain more than one line,
518 | which will not be processed correctly with this version.
519 |
520 |
521 |
522 |
--------------------------------------------------------------------------------
/pcb/mic_board.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LCAV/CompactSix/4deda86e0e70cad28046e3bcb6bdad3f2a8c9a35/pcb/mic_board.png
--------------------------------------------------------------------------------
/pcb/mic_board.sch:
--------------------------------------------------------------------------------
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 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 | >NAME
146 |
147 |
148 |
149 | >NAME
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 | >NAME
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 | >NAME
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 | <b>Supply Symbols</b><p>
219 | GND, VCC, 0V, +5V, -5V, etc.<p>
220 | Please keep in mind, that these devices are necessary for the
221 | automatic wiring of the supply signals.<p>
222 | The pin name defined in the symbol is identical to the net which is to be wired automatically.<p>
223 | In this library the device names are the same as the pin names of the symbols, therefore the correct signal names appear next to the supply symbols in the schematic.<p>
224 | <author>Created by librarian@cadsoft.de</author>
225 |
226 |
227 |
228 |
229 |
230 |
231 | >VALUE
232 |
233 |
234 |
235 |
236 | >VALUE
237 |
238 |
239 |
240 |
241 |
242 | <b>SUPPLY SYMBOL</b>
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 | <b>SUPPLY SYMBOL</b>
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 | Spark Fun Electronics' preferred foot prints. <b>Not to be used for commercial purposes.</b> We've spent an enormous amount of time creating and checking these footprints and parts. If you enjoy using this library, please buy one of our products at www.sparkfun.com.
271 |
272 |
273 |
274 |
275 |
276 | >Name
277 | >Value
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 | >Name
288 | >Value
289 |
290 |
291 |
292 |
293 |
294 |
295 | >NAME
296 | >VALUE
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 | >Name
306 | >Value
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 | >NAME
324 | >VALUE
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 | >NAME
339 | >VALUE
340 |
341 |
342 |
343 |
344 |
345 | <b>CAPACITOR</b><p>
346 | chip
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 | >NAME
357 | >VALUE
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 | >Name
367 | >Value
368 |
369 |
370 |
371 |
372 |
373 |
374 | >NAME
375 | >VALUE
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 | <b>Capacitor</b>
385 | Standard 0603 ceramic capacitor, and 0.1" leaded capacitor.
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
--------------------------------------------------------------------------------
/scripts/MEMS_array_sim.py:
--------------------------------------------------------------------------------
1 |
2 | import numpy as np
3 | import matplotlib
4 | import matplotlib.pyplot as plt
5 | from scipy.linalg import toeplitz
6 | from scipy.io import wavfile
7 | from scipy.signal import resample,fftconvolve
8 |
9 | import pyroomacoustics as pra
10 | #import TDBeamformers as tdb
11 |
12 | # Beam pattern figure properties
13 | freq=[800, 1600]
14 | figsize=(1.88,2.24)
15 | xlim=[-4,8]
16 | ylim=[-4.9,9.4]
17 |
18 | # Some simulation parameters
19 | Fs = 8000
20 | t0 = 1./(Fs*np.pi*1e-2) # starting time function of sinc decay in RIR response
21 | absorption = 0.90
22 | max_order_sim = 10
23 | sigma2_n = 1e-7
24 |
25 | # Room 1 : Shoe box
26 | room_dim = [4, 6]
27 |
28 | # the good source is fixed for all
29 | good_source = [1, 4.5] # good source
30 | normal_interferer = [2.8, 4.3] # interferer
31 | hard_interferer = [1.5, 3] # interferer in direct path
32 | #normal_interferer = hard_interferer
33 |
34 | # microphone array design parameters
35 | mic1 = [2, 1.5] # position
36 | M = 8 # number of microphones
37 | d = 0.08 # distance between microphones
38 | phi = 0. # angle from horizontal
39 | max_order_design = 2 # maximum image generation used in design
40 | shape = 'Linear' # array shape
41 | Lg_t = 0.050 # Filter size in seconds
42 | Lg = np.ceil(Lg_t*Fs) # Filter size in samples
43 | delay = 0.02
44 |
45 | # define the FFT length
46 | N = 1024
47 |
48 | # create a microphone array
49 | R = np.array([[25.146, 51.816, 24.13, 44.45, 64.516, 84.582],
50 | [33.528, 36.068, 16.002, 10.414, 10.668, 16.764]])*1e-3
51 | R -= R.mean(axis=1, keepdims=True) - np.array([mic1]).T
52 | mics = pra.Beamformer(R, Fs, N, Lg=Lg)
53 |
54 |
55 | # The first signal (of interest) is singing
56 | rate1, signal1 = wavfile.read('samples/singing_'+str(Fs)+'.wav')
57 | signal1 = np.array(signal1, dtype=float)
58 | signal1 = pra.normalize(signal1)
59 | signal1 = pra.highpass(signal1, Fs)
60 | delay1 = 0.
61 |
62 | # the second signal (interferer) is some german speech
63 | rate2, signal2 = wavfile.read('samples/german_speech_'+str(Fs)+'.wav')
64 | signal2 = np.array(signal2, dtype=float)
65 | signal2 = pra.normalize(signal2)
66 | signal2 = pra.highpass(signal2, Fs)
67 | delay2 = 1.
68 |
69 | # create the room with sources and mics
70 | room1 = pra.Room.shoeBox2D(
71 | [0,0],
72 | room_dim,
73 | fs=Fs,
74 | t0 = t0,
75 | max_order=max_order_sim,
76 | absorption=absorption,
77 | sigma2_awgn=sigma2_n)
78 |
79 | # add mic and good source to room
80 | room1.addSource(good_source, signal=signal1, delay=delay1)
81 | room1.addMicrophoneArray(mics)
82 |
83 | # add interferer
84 | room1.addSource(normal_interferer, signal=signal2, delay=delay2)
85 |
86 | # simulate the acoustic
87 | room1.compute_RIR()
88 | room1.simulate()
89 |
90 | # compute beamforming filters
91 | good_sources = room1.sources[0][:max_order_design+1]
92 | bad_sources = room1.sources[1][:max_order_design+1]
93 | mics.rakePerceptualFilters(good_sources, bad_sources, sigma2_n*np.eye(mics.Lg*mics.M), delay=delay)
94 |
95 | # process the signal
96 | output = mics.process()
97 |
98 | # save to output file
99 | inp = pra.normalize(pra.highpass(mics.signals[mics.M/2], Fs))
100 | out = pra.normalize(pra.highpass(output, Fs))
101 |
102 | wavfile.write('output_samples/input.wav', Fs, inp)
103 | wavfile.write('output_samples/output.wav', Fs, out)
104 |
105 | '''
106 | Plot Stuff
107 | '''
108 | f_size = (3.93, 1.57)
109 |
110 | # plot the room and beamformer
111 | room1.plot(img_order=np.minimum(room1.max_order, max_order_design),
112 | freq=freq)
113 |
114 | # plot the beamforming weights
115 | plt.figure()
116 | mics.plot(FD=False)
117 |
118 | # plot before/after processing
119 | plt.figure()
120 | pra.comparePlot(inp, out, Fs)
121 |
122 | # plot angle/frequency plot
123 | plt.figure()
124 | mics.plot_beam_response()
125 |
126 | plt.show()
127 |
--------------------------------------------------------------------------------
/scripts/low_pass_biquad.py:
--------------------------------------------------------------------------------
1 | from __future__ import division
2 | import numpy as np
3 | from scipy import signal
4 | import matplotlib.pyplot as plt
5 |
6 | def f2u(x):
7 | '''
8 | Quantization on 24 bits in signed fractionnal form
9 | min: 0x800000 == -1
10 | max: 0x7FFFFF is about 0.9999999988 or the like
11 | '''
12 |
13 | if x >= 0:
14 | return int(x*2.**23)
15 | else:
16 | return 2**24 + int(x*2**23)
17 |
18 | Fs_in = 192000
19 | Fs_cut = 44000
20 | Fs_out = 48000
21 | n_butter = 0
22 | n_cheby = 0
23 | n_ellip = 6
24 | stages = n_butter + n_cheby + n_ellip
25 |
26 | if stages > 9:
27 | raise ValueError('Only 9 stages max.')
28 |
29 | ripple = 0.1
30 | stop = 100
31 |
32 | sos = np.zeros((0,6))
33 |
34 | if n_butter > 0:
35 | sos_b = signal.butter(2*n_butter, Fs_cut/Fs_in, btype='low', output='sos')
36 | if n_butter > 1:
37 | k = np.sqrt(np.sum(sos_b[0,:3]**2))
38 | k_n = k**(1/(n_butter-1))
39 | sos_b[0,:3] /= k
40 | sos_b[1:,:3] *= k_n
41 | sos = np.vstack((sos, sos_b))
42 | if n_cheby > 0:
43 | sos_c = signal.cheby2(2*n_cheby, stop, Fs_out/Fs_in, btype='low', output='sos')
44 | if n_cheby > 1:
45 | k = np.sqrt(np.sum(sos_c[0,:3]**2))
46 | k_n = k**(1/(n_cheby-1))
47 | sos_c[0,:3] /= k
48 | sos_c[1:,:3] *= k_n
49 | sos = np.vstack((sos, sos_c))
50 | if n_ellip > 0:
51 | sos_e = signal.ellip(2*n_ellip, ripple, stop, Fs_cut/Fs_in, btype='low', output='sos')
52 | if n_ellip > 1:
53 | k = np.sqrt(np.sum(sos_e[0,:3]**2))
54 | k_n = k**(1/(n_ellip-1))
55 | sos_e[0,:3] /= k
56 | sos_e[1:,:3] *= k_n
57 | sos = np.vstack((sos, sos_e))
58 |
59 | sos_q = np.around((sos-1e-9)*2**23)/2**23
60 |
61 | z,p,k = signal.sos2zpk(sos)
62 | zq,pq,kq = signal.sos2zpk(sos_q)
63 | plt.figure()
64 | plt.plot(np.real(z), np.imag(z), 'o')
65 | plt.plot(np.real(p), np.imag(p), 'x')
66 | plt.plot(np.real(zq), np.imag(z), 'ro')
67 | plt.plot(np.real(pq), np.imag(p), 'rx')
68 | ucx = np.cos(np.linspace(0,2*np.pi,1000))
69 | ucy = np.sin(np.linspace(0,2*np.pi,1000))
70 | plt.plot(ucx, ucy, 'k-')
71 | plt.axis('equal')
72 |
73 | # Plot response
74 | b,a = signal.sos2tf(sos)
75 | bq,aq = signal.sos2tf(sos_q)
76 | w,h = signal.freqz(b,a=a)
77 | wq,hq = signal.freqz(bq,a=aq)
78 | plt.figure()
79 | ax1 = plt.subplot(1,1,1)
80 | plt.plot(w/np.pi*Fs_in/2, 20 * np.log10(abs(h)),'b')
81 | plt.plot(wq/np.pi*Fs_in/2, 20 * np.log10(abs(hq)),'r')
82 | plt.title('Filter frequency response')
83 | plt.xlabel('Frequency [radians / second]')
84 | plt.ylabel('Amplitude [dB]')
85 | plt.margins(0, 0.1)
86 | plt.grid(which='both', axis='both')
87 | plt.axvline(Fs_cut/2, color='green') # cutoff frequency
88 | plt.axvline(Fs_out/2, color='red') # cutoff frequency
89 |
90 | ax2 = ax1.twinx()
91 | #angles = np.unwrap(np.angle(h))
92 | #plt.plot(w/np.pi*Fs_in/2, angles, 'g')
93 |
94 | w,gd = signal.group_delay((b,a))
95 | plt.plot(w/np.pi*Fs_in/2, gd*Fs_out/Fs_in)
96 |
97 | plt.ylabel('Angle (radians)', color='g')
98 | plt.grid()
99 | plt.axis('tight')
100 |
101 | vb = np.zeros((3,stages))
102 | va = np.zeros((3,stages))
103 |
104 | k2 = k**(1/stages)
105 | for i in xrange(stages):
106 |
107 | if np.max(np.abs(sos_q[i,:])/[2, 2, 1, 1, 2, 1]) > 1:
108 |
109 | print 'Warning: one of the coefficient is larger than 1'
110 | print sos[i,:]
111 |
112 | b1 = sos[i,1]
113 | b2 = sos[i,2]
114 | a1 = sos[i,4]
115 | a2 = sos[i,5]
116 | b0 = sos[i,0]
117 |
118 | print("sta321mp_biquad(codec, 1, %d, 0x%x, 0x%x, 0x%x, 0x%x,0x%x);"
119 | % (i+2, f2u(b1/2), f2u(b2), f2u(-a1/2), f2u(-a2), f2u(b0/2)))
120 |
121 |
122 | n = 5000
123 | x = np.zeros(n)
124 | x[0] = 1
125 | x = np.random.randn(n)
126 |
127 | # method 1
128 | y1 = signal.sosfilt(sos,x)
129 |
130 | # method 2
131 | y2 = signal.sosfilt(sos_q, x)
132 |
133 | plt.figure()
134 | plt.subplot(2,1,1)
135 | plt.plot(y1)
136 | plt.plot(y2, 'r')
137 | plt.subplot(2,1,2)
138 | f = np.fft.rfftfreq(y2.shape[0])*Fs_in
139 | plt.plot(f, 20*np.log10(np.abs(np.fft.rfft(y2)/np.sqrt(y2.shape[0]))))
140 | plt.axvline(Fs_cut/2, color='green') # cutoff frequency
141 | plt.axvline(Fs_out/2, color='red') # cutoff frequency
142 | print('Max error:', np.max(y1-y2))
143 |
144 |
145 | plt.show()
146 |
--------------------------------------------------------------------------------
/scripts/read_raw24.py:
--------------------------------------------------------------------------------
1 |
2 | from numpy import dtype , fromfile
3 | import numpy as np
4 |
5 | def load_raw24(filename):
6 |
7 | d = fromfile(filename,dtype='>u1')
8 |
9 | d = np.reshape(d, (-1,3))
10 |
11 | d = np.concatenate((np.zeros((d.shape[0],1), dtype='>u1'), d), axis=1)
12 |
13 | d.dtype = '>u4'
14 |
15 | return d
16 |
--------------------------------------------------------------------------------
/scripts/util.py:
--------------------------------------------------------------------------------
1 | from __future__ import division
2 | import numpy as np
3 | from scipy import signal
4 | import matplotlib.pyplot as plt
5 | from scikits.audiolab import Sndfile
6 |
7 | def read_wav(name):
8 |
9 | from scikits.audiolab import Sndfile
10 |
11 | sf = Sndfile(name)
12 | return sf.read_frames(sf.nframes)
13 |
14 | def spectrum(x):
15 | f = np.fft.rfftfreq(x.shape[0])
16 | X = 20*np.log10(np.abs(np.fft.rfft(x)/np.sqrt(x.shape[0])))
17 | plt.plot(f, X)
18 |
19 |
--------------------------------------------------------------------------------