# Trellis M4 Audio Filter Visualizer

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/067/291/medium800thumb/neotrellis_fir_viz_trellism4.jpg?1544202415)

https://youtu.be/D_YGIDe1Ng4

Colored lights bouncing to the music is a must have for any party. Now you can bring the party to your NeoTrellis M4 Express with the Audio Visualizer and Filter! With realtime Fast Fourier Transform (FFT) frequency spectrum analysis, the music coming into your NeoTrellis STEMMA adapter (from a computer, phone, Walkman, turntable pre-amp, etc.) is converted into colors and lights on the buttons to display the magnitude of the sound in different frequency bands.

Your music then passes through to the TRRS headphone jack on the NeoTrellis so you can listen to it. But that's not all! We've also built in a low pass filter and band pass filter so you can trigger awesome sounding effects at the push of a button!

We'll also build a small circuit with capacitors and resistors to center the incoming audio around the proper voltage for the NeoTrellis M4's analog-to-digital (ADC) converter.

## Parts
### Adafruit NeoTrellis M4 with Enclosure and Buttons Kit Pack

[Adafruit NeoTrellis M4 with Enclosure and Buttons Kit Pack](https://www.adafruit.com/product/4020)
So you've got a cool/witty name for your band, a Soundcloud account,&nbsp;[a 3D-printed Daft Punk helmet](https://learn.adafruit.com/3d-printed-daft-punk-helmet-with-bluetooth)...&nbsp;so what could be missing from your road to stardom? The **NeoTrellis M4 Kit...**

Out of Stock
[Buy Now](https://www.adafruit.com/product/4020)
[Related Guides to the Product](https://learn.adafruit.com/products/4020/guides)
![Demo Video of Hands pressing buttons on lit up NeoTrellis M4.](https://cdn-shop.adafruit.com/product-videos/640x480/4020-00.jpg)

### Adafruit NeoTrellis M4 Mainboard - featuring SAMD51

[Adafruit NeoTrellis M4 Mainboard - featuring SAMD51](https://www.adafruit.com/product/3938)
We got a big ol' blender and tossed in an ItsyBitsy M4, two NeoTrellis boards and an electret mic amp - turned on the 'mix' button and out came the NeoTrellis M4 - a super fun dev board for anyone who likes to squish buttons, see pretty lights and maybe make a tune or...

In Stock
[Buy Now](https://www.adafruit.com/product/3938)
[Related Guides to the Product](https://learn.adafruit.com/products/3938/guides)
![Overhead shot of big, black, rectangle-shaped audio dev board.](https://cdn-shop.adafruit.com/640x480/3938-09.jpg)

### NeoTrellis M4 Acrylic Enclosure Kit

[NeoTrellis M4 Acrylic Enclosure Kit](https://www.adafruit.com/product/3963)
So you've got your&nbsp;[Adafruit NeoTrellis M4](https://www.adafruit.com/product/3938), a cool/witty name for your band, a Soundcloud account,&nbsp;[a 3D-printed Daft Punk helmet](https://learn.adafruit.com/3d-printed-daft-punk-helmet-with-bluetooth)...&nbsp;so what...

In Stock
[Buy Now](https://www.adafruit.com/product/3963)
[Related Guides to the Product](https://learn.adafruit.com/products/3963/guides)
![NeoTrellis M4 Acrylic Enclosure Kit with plastic pieces](https://cdn-shop.adafruit.com/640x480/3963-06.jpg)

### Silicone Elastomer 4x4 Button Keypad - for 3mm LEDs

[Silicone Elastomer 4x4 Button Keypad - for 3mm LEDs](https://www.adafruit.com/product/1611)
So squishy! These silicone elastomer keypads are just waiting for your fingers to press them. Go ahead, squish all you like! (They're durable and easy to clean, just wipe with mild soap and water) These are just like the light up rubber buttons you find on stuff like appliances and tools,...

In Stock
[Buy Now](https://www.adafruit.com/product/1611)
[Related Guides to the Product](https://learn.adafruit.com/products/1611/guides)
![Angled Shot of the Silicone Elastomer 4x4 Button Keypad - for 3mm LEDs.](https://cdn-shop.adafruit.com/640x480/1611-07.jpg)

### 3.5mm (1/8") Stereo Audio Jack Terminal Block

[3.5mm (1/8") Stereo Audio Jack Terminal Block](https://www.adafruit.com/product/2791)
One truth about working with audio is you always need the cable or adapter you _don't_ have in your toolbox. That's why we love these terminal-block audio connectors so much. **No soldering required!** Use stranded or solid core wire and a small screw driver to...

In Stock
[Buy Now](https://www.adafruit.com/product/2791)
[Related Guides to the Product](https://learn.adafruit.com/products/2791/guides)
![3.5mm (1/8) Stereo Audio Jack Terminal Block](https://cdn-shop.adafruit.com/640x480/2791-01.jpg)

### JST PH 2mm 4-Pin to Female Socket Cable - I2C STEMMA Cable

[JST PH 2mm 4-Pin to Female Socket Cable - I2C STEMMA Cable](https://www.adafruit.com/product/3950)
This cable will let you turn a JST PH 4-pin cable port into 4 individual wires with high-quality 0.1" female sockets on the end. We're carrying these to match up with any of our boards with 'STEMMA' connectors on them such as the <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3950)
[Related Guides to the Product](https://learn.adafruit.com/products/3950/guides)
![Angled shot of STEMMA JST PH 4-Pin to Female Header Cable - 200mm.](https://cdn-shop.adafruit.com/640x480/3950-02.jpg)

### Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25

[Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25](https://www.adafruit.com/product/2784)
ΩMG! You're not going to be able to resist these handy resistor packs!&nbsp;Well, axially, they&nbsp;do all of the resisting for you!

This is a **25 Pack of 10K Ω Resistors.** More specifically, they are **carbon film** , through-hole...

In Stock
[Buy Now](https://www.adafruit.com/product/2784)
[Related Guides to the Product](https://learn.adafruit.com/products/2784/guides)
![Angled shot of 25 Through-Hole Resistors - 10K ohm 5% 1/4W.](https://cdn-shop.adafruit.com/640x480/2784-00.jpg)

### 10uF 50V Electrolytic Capacitors - Pack of 10

[10uF 50V Electrolytic Capacitors - Pack of 10](https://www.adafruit.com/product/2195)
We like capacitors so much we made a&nbsp;[kids' show about them.](https://www.youtube.com/watch?v=sy_G1oYRQmM)&nbsp; &nbsp;They're super handy and it's really helpful to have a variety lying around to pick and choose from.

<p...></p...>In Stock
[Buy Now](https://www.adafruit.com/product/2195)
[Related Guides to the Product](https://learn.adafruit.com/products/2195/guides)
![Pack of 10 through hole 10uF 50V Electrolytic Capacitors](https://cdn-shop.adafruit.com/640x480/2195-00.jpg)

### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

In Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)
![USB cable - USB A to Micro-B - 3 foot long](https://cdn-shop.adafruit.com/640x480/592-01.jpg)

### 3.5mm Male/Male Stereo Cable

[3.5mm Male/Male Stereo Cable](https://www.adafruit.com/product/2698)
Seamlessly transmit high-quality stereo audio with this&nbsp; **3.5mm Male/Male Stereo Cable.&nbsp;**

Ideal for "passing the AUX cord," or&nbsp;connecting audio devices&nbsp;such as&nbsp;smartphones, tablets, MP3 players, car stereos, portable speakers or any other...

In Stock
[Buy Now](https://www.adafruit.com/product/2698)
[Related Guides to the Product](https://learn.adafruit.com/products/2698/guides)
![Black audio cable with 3.5mm audio jacks wrapped like a bow tie.](https://cdn-shop.adafruit.com/640x480/2698-01.jpg)

In addition to the parts above&nbsp; you'll need some powered speakers or headphones to listen to the fly tunes.

### USB Powered Speakers

[USB Powered Speakers](https://www.adafruit.com/product/1363)
Add some extra boom to your audio project with these powered loudspeakers. We sampled half a dozen different models to find ones with a good frequency response, so you'll get quality audio output for music playback. Simply connect the standard 3.5mm stereo plug into your Raspberry Pi model...

In Stock
[Buy Now](https://www.adafruit.com/product/1363)
[Related Guides to the Product](https://learn.adafruit.com/products/1363/guides)
![Two square-ish USB Powered Speakers](https://cdn-shop.adafruit.com/640x480/1363-07.jpg)

### Cell-phone TRRS Headset - Earbud Headphones w/ Microphone

[Cell-phone TRRS Headset - Earbud Headphones w/ Microphone](https://www.adafruit.com/product/1966)
These earbud headphones are the perfect accessory for your FONA - they've been tested to work with our modules - but can be used with any iOS or Android device that uses a TRRS pinout.&nbsp; The buds themselves are&nbsp;16mm in diameter with a nice 40" long. &nbsp;They come with a...

In Stock
[Buy Now](https://www.adafruit.com/product/1966)
[Related Guides to the Product](https://learn.adafruit.com/products/1966/guides)
![Cell-phone TRRS Headset - Earbud Headphones with Microphone](https://cdn-shop.adafruit.com/640x480/1966-03.jpg)

# Trellis M4 Audio Filter Visualizer

## Filters and Visualisation

## Audio Library

This project leverages the excellent [Audio library](https://github.com/adafruit/Audio) for Arduino which has been forked for the NeoTrellis M4 Express from the [original Teensy Audio Library by Paul Stroffregen at pjrc](https://www.pjrc.com/teensy/td_libs_Audio.html). The Audio library is described this way: "A toolkit for building streaming audio projects, featuring Polyphonic Playback, Recording, Synthesis, Analysis, Effects, Filtering, Mixing, Multiple Simultaneous Inputs & Outputs, and Flexible Internal Signal Routing. "

The two key things we're doing with code from the Audio library are filtering audio and analyzing it for visualization.

![](https://cdn-learn.adafruit.com/assets/assets/000/067/296/medium800/led_matrices_filters.png?1544208882)

## FIR Filter

The Finite Impulse Response (FIR) Filter code filters the audio based on frequency bands we specify. [Wikipedia](https://en.wikipedia.org/wiki/Electronic_filter) describes electronic filters this way:

> ...circuits which perform [signal processing](https://en.wikipedia.org/wiki/Signal_processing "Signal processing") functions, specifically to remove unwanted frequency components from the signal, to enhance wanted ones, or both.

The frequency range of a song can span from 20 Hz to 20,000 Hz (the audio spectrum of human hearing) but we can use an FIR filter to selectively pass through only certain bands (ranges) of those frequencies. You can drop out all of the mid and upper bands, only allowing the low end to remain by using a **low pass** filter. This gives us a type of calm, muffled sound that's great for queuing a build-up in dance music, for example. Our example allows frequencies below 1000 Hz to pass through.

We also have a **band pass** filter that allows only mid-range to pass through (a band pass can be any band of frequencies you like, we just happen to have chosen a mid-range here). Our example allows frequencies from 1200 Hz to 1700 Hz to pass.

## FFT Spectrum Visualization

To turn the Trellis M4's button LEDs into a spectrum analyzer, we need to measure the incoming audio's signal strength in the full frequency range.

The Fast Fourier Transform code computes a 1024 point audio frequency analysis that we can use for visualization of the magnitude of the sound in various frequency range "bins". These values are then used to determine in real time which NeoPixel's to light up in the Trellis M4 buttons.

# Trellis M4 Audio Filter Visualizer

## Audio Input Circuit

![](https://cdn-learn.adafruit.com/assets/assets/000/067/280/medium800/neotrellis_IMG_6389.jpg?1544199508)

![](https://cdn-learn.adafruit.com/assets/assets/000/067/106/medium800/neotrellis_trellisfilter02.png?1544049909)

The audio signal coming from your music player needs a bit of massaging before it can be read by the analog inputs on the NeoTrellis M4. We'll build a small circuit using two capacitors and two resistors to remove the DC bias and center the incoming audio around the correct voltage for the NeoTrellis M4's analog-to-digital converter (ADC).

![](https://cdn-learn.adafruit.com/assets/assets/000/067/276/medium800/neotrellis_IMG_6384_2k.jpg?1544196645)

If you haven't already put together your NeoTrellis M4, [follow these instructions on assembly](https://learn.adafruit.com/adafruit-neotrellis-m4/assembly).

![](https://cdn-learn.adafruit.com/assets/assets/000/067/277/medium800/neotrellis_trellisfilter01.png?1544196903)

![](https://cdn-learn.adafruit.com/assets/assets/000/067/278/medium800/neotrellis_audioStemma.jpg?1544199267)

This can be done on a breadboard if you like, but if you want to keep it small and mobile, you can do without, and go for a "dead bug" style of construction. These are the connections:

- NeoTrellis M4 STEMMA connector **green** to first 10uF **capacitor**  **negative** leg (the shorter leg, and the one with the white stripe on the body of the cap)
- First **capacitor positive** (longer leg) to audio jack terminal block **'L' terminal**
- **STEMMA** connector **green** to first **10k resistor** (either leg)
- First **resistor** to audio jack terminal block **GND**

&nbsp;

- **STEMMA** connector **white** to second **capacitor negative**
- Second **capacitor positive** to audio jack terminal block **'R' terminal**
- **STEMMA** connector **white** to second **10k resistor**
- Second **resistor** to audio jack terminal block **GND**

&nbsp;

- **STEMMA** connector **black** to audio jack terminal block **GND**

You'll find it easiest if you twist the legs of some components before inserting them into the STEMMA wire connectors as shown in this video. Just be sure that there are no accidental connections being made from the leads touching where not intended.

https://youtu.be/f9HtinYiyk8

![](https://cdn-learn.adafruit.com/assets/assets/000/067/279/medium800/neotrellis_IMG_6362_2k.jpg?1544199374)

Plug the JST PH 4-pin cable into the STEMMA connector on your NeoTrellis M4 and you'll be able to read the incoming audio signal.

Next, let's flash the NeoTrellis M4 firmware with the filter/visualizer code.

# Trellis M4 Audio Filter Visualizer

## Use the Audio Filter Visualizer

![](https://cdn-learn.adafruit.com/assets/assets/000/067/283/medium800/neotrellis_IMG_6396.jpg?1544200498)

## Firmware

All you need to do to use the visualizer and filters on your NeoTrellis M4 is to plug it into USB, download the firmware .uf2 file below, place your NeoTrellis into bootloader mode. Bootloader mode is entered by double-clicking the reset button on the back, and drag the firmware file onto the **TRELSM4BOOT** drive that shows up.

If you plug your NeoTrellis in and the drive shows up as **CIRCUITPY** , that means it is in CircuitPython mode. No Worries, press the reset button until you see **TRELSM4BOOT** which is the flash drive to place your .uf2 on. If you were to copy the .uf2 to **CIRCUITPY** , it would not run, hence ensuring the drive is **TRELM4BOOT**.

[Download the Filter FIR NeoTrellis Firmware](https://cdn-learn.adafruit.com/assets/assets/000/067/107/original/Filter_FIR_trellis.uf2?1544050083)
Warning: 

Once you've flashed the firmware, here's how to use it:

&nbsp;

Plug the output of a music player, such as a phone, computer, mp3 player, or Walkman, into the audio jack terminal block adapter

&nbsp;

Then, connect headphones or powered speakers to the NeoTrellis M4's built in TRRS 3.5mm jack

&nbsp;

Power the NeoTrellis M4 over USB

&nbsp;

Play music on your player

&nbsp;

The NeoTrellis M4 will automatically apply the low pass filter, and start visualizing the music in the lower section of the NeoPixel lit buttons -- it should have a muffled sound since the mid and upper frequencies are being filtered out

&nbsp;

Press and hold the bottom left button (NeoTrellis M4 in vertical orientation, USB jack facing left) to hear the pure, unfiltered audio, and note how the visualization changes

&nbsp;

Let go of the bottom left button and press the one above it to switch to a band pass filter

![neotrellis_IMG_6394.jpg](https://cdn-learn.adafruit.com/assets/assets/000/067/284/medium640/neotrellis_IMG_6394.jpg?1544200618)

![neotrellis_IMG_6395.jpg](https://cdn-learn.adafruit.com/assets/assets/000/067/285/medium640/neotrellis_IMG_6395.jpg?1544200632)

![neotrellis_IMG_6396.jpg](https://cdn-learn.adafruit.com/assets/assets/000/067/286/medium640/neotrellis_IMG_6396.jpg?1544200644)

![neotrellis_IMG_6397.jpg](https://cdn-learn.adafruit.com/assets/assets/000/067/287/medium640/neotrellis_IMG_6397.jpg?1544200658)

![neotrellis_IMG_6401.jpg](https://cdn-learn.adafruit.com/assets/assets/000/067/288/medium640/neotrellis_IMG_6401.jpg?1544200670)

https://youtu.be/D_YGIDe1Ng4

## Deeper Modification

For more advanced hacking, if you want to tweak the Arduino code, you can [head to the GitHub repo](https://github.com/adafruit/Adafruit_NeoTrellisM4/tree/master/examples/Filter_FIR_trellis) to have a look!


## Featured Products

### Adafruit NeoTrellis M4 with Enclosure and Buttons Kit Pack

[Adafruit NeoTrellis M4 with Enclosure and Buttons Kit Pack](https://www.adafruit.com/product/4020)
So you've got a cool/witty name for your band, a Soundcloud account,&nbsp;[a 3D-printed Daft Punk helmet](https://learn.adafruit.com/3d-printed-daft-punk-helmet-with-bluetooth)...&nbsp;so what could be missing from your road to stardom? The **NeoTrellis M4 Kit...**

Out of Stock
[Buy Now](https://www.adafruit.com/product/4020)
[Related Guides to the Product](https://learn.adafruit.com/products/4020/guides)
### Adafruit NeoTrellis M4 Mainboard - featuring SAMD51

[Adafruit NeoTrellis M4 Mainboard - featuring SAMD51](https://www.adafruit.com/product/3938)
We got a big ol' blender and tossed in an ItsyBitsy M4, two NeoTrellis boards and an electret mic amp - turned on the 'mix' button and out came the NeoTrellis M4 - a super fun dev board for anyone who likes to squish buttons, see pretty lights and maybe make a tune or...

In Stock
[Buy Now](https://www.adafruit.com/product/3938)
[Related Guides to the Product](https://learn.adafruit.com/products/3938/guides)
### NeoTrellis M4 Acrylic Enclosure Kit

[NeoTrellis M4 Acrylic Enclosure Kit](https://www.adafruit.com/product/3963)
So you've got your&nbsp;[Adafruit NeoTrellis M4](https://www.adafruit.com/product/3938), a cool/witty name for your band, a Soundcloud account,&nbsp;[a 3D-printed Daft Punk helmet](https://learn.adafruit.com/3d-printed-daft-punk-helmet-with-bluetooth)...&nbsp;so what...

In Stock
[Buy Now](https://www.adafruit.com/product/3963)
[Related Guides to the Product](https://learn.adafruit.com/products/3963/guides)
### Silicone Elastomer 4x4 Button Keypad - for 3mm LEDs

[Silicone Elastomer 4x4 Button Keypad - for 3mm LEDs](https://www.adafruit.com/product/1611)
So squishy! These silicone elastomer keypads are just waiting for your fingers to press them. Go ahead, squish all you like! (They're durable and easy to clean, just wipe with mild soap and water) These are just like the light up rubber buttons you find on stuff like appliances and tools,...

In Stock
[Buy Now](https://www.adafruit.com/product/1611)
[Related Guides to the Product](https://learn.adafruit.com/products/1611/guides)
### 3.5mm (1/8") Stereo Audio Jack Terminal Block

[3.5mm (1/8") Stereo Audio Jack Terminal Block](https://www.adafruit.com/product/2791)
One truth about working with audio is you always need the cable or adapter you _don't_ have in your toolbox. That's why we love these terminal-block audio connectors so much. **No soldering required!** Use stranded or solid core wire and a small screw driver to...

In Stock
[Buy Now](https://www.adafruit.com/product/2791)
[Related Guides to the Product](https://learn.adafruit.com/products/2791/guides)
### JST PH 2mm 4-Pin to Female Socket Cable - I2C STEMMA Cable

[JST PH 2mm 4-Pin to Female Socket Cable - I2C STEMMA Cable](https://www.adafruit.com/product/3950)
This cable will let you turn a JST PH 4-pin cable port into 4 individual wires with high-quality 0.1" female sockets on the end. We're carrying these to match up with any of our boards with 'STEMMA' connectors on them such as the <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3950)
[Related Guides to the Product](https://learn.adafruit.com/products/3950/guides)
### Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25

[Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25](https://www.adafruit.com/product/2784)
ΩMG! You're not going to be able to resist these handy resistor packs!&nbsp;Well, axially, they&nbsp;do all of the resisting for you!

This is a **25 Pack of 10K Ω Resistors.** More specifically, they are **carbon film** , through-hole...

In Stock
[Buy Now](https://www.adafruit.com/product/2784)
[Related Guides to the Product](https://learn.adafruit.com/products/2784/guides)
### 10uF 50V Electrolytic Capacitors - Pack of 10

[10uF 50V Electrolytic Capacitors - Pack of 10](https://www.adafruit.com/product/2195)
We like capacitors so much we made a&nbsp;[kids' show about them.](https://www.youtube.com/watch?v=sy_G1oYRQmM)&nbsp; &nbsp;They're super handy and it's really helpful to have a variety lying around to pick and choose from.

<p...></p...>In Stock
[Buy Now](https://www.adafruit.com/product/2195)
[Related Guides to the Product](https://learn.adafruit.com/products/2195/guides)

## Related Guides

- [Adafruit NeoTrellis M4 Express](https://learn.adafruit.com/adafruit-neotrellis-m4.md)
- [NeoTrellis Game](https://learn.adafruit.com/neotrellis-box-game.md)
- [Star Trek Soundboard with NeoTrellis](https://learn.adafruit.com/star-trek-sound-board-with-neotrellism4.md)
- [NeoTrellis Tabletop RPG Soundboard](https://learn.adafruit.com/neotrellis-dungeon-crawl-soundboard.md)
- [What is Web MIDI & BLE MIDI?](https://learn.adafruit.com/web-ble-midi.md)
- [Neotrellis M4 Live Launcher](https://learn.adafruit.com/neotrellis-live-launcher.md)
- [UNTZtrument: a Trellis MIDI Instrument](https://learn.adafruit.com/untztrument-trellis-midi-instrument.md)
- [Launch Deck Trellis M4](https://learn.adafruit.com/launch-deck-trellis-m4.md)
- [Adafruit NeoTrellis](https://learn.adafruit.com/adafruit-neotrellis.md)
- [Keypad and Matrix Scanning in CircuitPython](https://learn.adafruit.com/key-pad-matrix-scanning-in-circuitpython.md)
- [NeoTrellis M4 Arpeggiator Synth](https://learn.adafruit.com/neotrellis-arpeggiator-synth.md)
- [Christmas Soundboard with NeoTrellis M4](https://learn.adafruit.com/xmas-sound-board.md)
- [iPad Pro Bumper](https://learn.adafruit.com/ipad-pro-bumper.md)
- [Portable Trellis Sound Board](https://learn.adafruit.com/portable-trellis-sound-board.md)
- [Adafruit IS31FL3741](https://learn.adafruit.com/adafruit-is31fl3741.md)
