# Drawing a spectogram 2D (or 3D) from a recorded audio

**URL:** <https://discourse.processing.org/t/drawing-a-spectogram-2d-or-3d-from-a-recorded-audio/25708>\
**Category:** Libraries\
**Created:** [November 25, 2020, 5:59pm UTC](https://discourse.processing.org/t/drawing-a-spectogram-2d-or-3d-from-a-recorded-audio/25708 "2020-11-25T17:59:52Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![mcanet](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mcanet/32/11403_2.png) [@mcanet](https://discourse.processing.org/u/mcanet)\
**Post date:** [December 13, 2020, 3:01pm UTC](https://discourse.processing.org/t/drawing-a-spectogram-2d-or-3d-from-a-recorded-audio/25708/21 "2020-12-13T15:01:43Z")

</div>

Hello,

How color is generated in a spectrogram?  
I can observe in your image that green is higher amplitude, yellow middle and red low. It is an arbitrary decision or there is some standard formula for the color encoding.

Thanks,

Mar

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 13, 2020, 3:16pm UTC](https://discourse.processing.org/t/drawing-a-spectogram-2d-or-3d-from-a-recorded-audio/25708/22 "2020-12-13T15:16:30Z")

</div>

Hello,

> [@mcanet](#):
>
> How color is generated in a spectrogram?

I just threw this together quickly as a proof of concept and had fun going from the basic FFT example to the x, y and then the polar sweep.

I used HSB color mode and changed the hue for the colors proportional to amplitude; there is also saturation and brightness to have fun with!

My first effort was just shades of gray with stroke() from 0 to 255 in RGB mode.

I did set a threshold so it was black if under a certain amplitude otherwise the background was red in my example.

References:

- [Color / Processing.org](https://processing.org/tutorials/color/)
- [Spectrogram - Wikipedia](https://en.wikipedia.org/wiki/Spectrogram)
- [Spectrogram Color on Google](https://www.google.com/search?q=spectrogram&rlz=1C1CHBF_enCA822CA822&sxsrf=ALeKk02ziLNQ8kCzkX9rn79OtB0MaHRe4g:1607872152623&source=lnms&tbm=isch&sa=X&ved=2ahUKEwig-IDEnsvtAhXMXc0KHTLhDAQQ_AUoAXoECCAQAw&biw=1920&bih=1067)

`:)`

---

<div class="post-metadata">

**Author:** ![rsserc](https://avatars.discourse-cdn.com/v4/letter/r/7c8e57/32.png) [@rsserc](https://discourse.processing.org/u/rsserc)\
**Post date:** [January 28, 2021, 12:25pm UTC](https://discourse.processing.org/t/drawing-a-spectogram-2d-or-3d-from-a-recorded-audio/25708/23 "2021-01-28T12:25:05Z")

</div>

Hi,  
I’m also learning how to manage with a spectrogram on processing, is it possible to ask you for the code?  
It would be so useful!

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 10, 2021, 6:24pm UTC](https://discourse.processing.org/t/drawing-a-spectogram-2d-or-3d-from-a-recorded-audio/25708/25 "2021-05-10T18:24:45Z")

</div>

Have you tried my sketch, you should be able to alter it to produce a circular profile

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 11, 2021, 1:49pm UTC](https://discourse.processing.org/t/drawing-a-spectogram-2d-or-3d-from-a-recorded-audio/25708/27 "2021-05-11T13:49:24Z")

</div>

> [@macar](#):
>
> \*\*I am new at processing. For some reason the forum doesn’t show the multiplications at my sketch

Hello,

Please format your code:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

`:)`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 11, 2021, 2:39pm UTC](https://discourse.processing.org/t/drawing-a-spectogram-2d-or-3d-from-a-recorded-audio/25708/29 "2021-05-11T14:39:22Z")

</div>

Hello,

This is a _simple_ example to show how to plot points from data in an array and add color to the data.

These are the same concepts I used with my other examples in this topic using the FFT example that comes with the Processing Sound Library (not Minim library).

> **Example Click Here to Open!**
>
> ```auto
> // FFT Gradients
> // v1.0.0
> // GLV 2021-05-11
> 
> int bands = 256;
> float [] fft = new float [bands];
> 
> void setup() 
> {
> size(512, 512);
> background(0);
> }
> 
> int x1, y1;
> int x2, y2;
> float angle = -TAU/4;
> 
> void draw() 
> {
> //Some *fixed* sample data. This will be changing with each cycle of draw() in FFT example in Sound library.
> for (int i = 0; i<bands; i++)
> {
> float amp = 0.5;
> fft[i] = amp + amp*sin(i*TAU/256);
> println(fft[i]);
> }  
>   
> //XY Plot using fft[] value to add a gradient
> for (int x1 = 0; x1<bands; x1++)
> {
> stroke(fft[x1]*255, 0, 0);  
> point(x1, y1);
> }
>     
> //Rotating Plot fft[] value to add a gradient   
> push();
> translate(width/2, height/2);
> rotate(angle);
> for (int x2 = 0; x2<bands; x2++)
> {
> strokeWeight(2);
> stroke(0, fft[x2]*255, 0);  
> point(x2, y2);
> }    
> pop();    
>   
> angle += TAU/(256*4);  
>   
> y1++;
> if (y1 >= height) 
> {
> background(0);
> y1 = 0;
> angle = -TAU/4;
> }
> }
> 
> ```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/851b8fe10752fe9a30c0920adf26b5b77bbb5ad2.png)

I used HSB colorMode() and hue() for the gradients in this example:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4d2248d93ed09fae7b4ed9a9c296a39c51d478bd.jpeg)

`:)`

[Previous page](https://discourse.processing.org/t/drawing-a-spectogram-2d-or-3d-from-a-recorded-audio/25708.md?page=1)
