# How could be the best way of implementing an fft chart?

**URL:** <https://forum.babylonjs.com/t/how-could-be-the-best-way-of-implementing-an-fft-chart/21565>\
**Category:** Questions\
**Tags:** tutorial\
**Created:** [June 10, 2021, 1:48pm UTC](https://forum.babylonjs.com/t/how-could-be-the-best-way-of-implementing-an-fft-chart/21565 "2021-06-10T13:48:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MQDev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mqdev/32/16773_2.png) [@MQDev](https://forum.babylonjs.com/u/MQDev)\
**Post date:** [June 10, 2021, 1:48pm UTC](https://forum.babylonjs.com/t/how-could-be-the-best-way-of-implementing-an-fft-chart/21565/1 "2021-06-10T13:48:53Z")

</div>

Hello everyone,

I’m trying to set up an interactive cascading spectrum chart, but it hasn’t been such a trivial thing for me. Here’s a picture of the goal I’d like to achieve:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/4/243c76257871d1cc9a4a9f875d2a1c15da27d3a8.png)  
or also  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/c/ec463f7b8e1099a8e731ea03e0afbd866f8808cc.png)

It’s an [fft](https://en.wikipedia.org/wiki/Fast_Fourier_transform) graph, I have all these points already. Do you have any tips or any examples that I could follow?

I apologize that I don’t have any examples online yet to bring here, but as I go along I’ll add a fiddle here. I’ve tried using graphics-specific libraries, but mostly they work either with points only or with surface graphics.

Any help, guidance, examples will be a matter of great gratitude.

Best Regards,  
Matheus

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [June 10, 2021, 1:54pm UTC](https://forum.babylonjs.com/t/how-could-be-the-best-way-of-implementing-an-fft-chart/21565/2 "2021-06-10T13:54:16Z")

</div>

Hi @MQDev and welcome to the forum!

I’d do it with 1 plane per date and use a shader to display intensity. Let me try something …

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [June 10, 2021, 2:26pm UTC](https://forum.babylonjs.com/t/how-could-be-the-best-way-of-implementing-an-fft-chart/21565/3 "2021-06-10T14:26:30Z")

</div>

Here it is!  
[data viz | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#S7U8U8#1)  
You’ll get a new graph data each time you press play because of random.

The idea is to discard pixel in the fragment shader when it’s higher than data value. Then compute a color (a gradient texture might be a good choice here).

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/a/c/ac687353e99a1d65685a5210792885c954932383.jpeg)

Still a long way to go but at least it’s a start 🙂

---

<div class="post-metadata">

**Author:** ![MQDev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mqdev/32/16773_2.png) [@MQDev](https://forum.babylonjs.com/u/MQDev)\
**Post date:** [June 10, 2021, 2:27pm UTC](https://forum.babylonjs.com/t/how-could-be-the-best-way-of-implementing-an-fft-chart/21565/4 "2021-06-10T14:27:34Z")

</div>

Thank you @Cedric !

I tried something with vis.js, you can see [here](https://jsfiddle.net/mqdevWG/qwaxupsv/) but it’s not very customizable. I believe that here with Babylon the result can be better.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![MQDev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mqdev/32/16773_2.png) [@MQDev](https://forum.babylonjs.com/u/MQDev)\
**Post date:** [June 10, 2021, 2:29pm UTC](https://forum.babylonjs.com/t/how-could-be-the-best-way-of-implementing-an-fft-chart/21565/5 "2021-06-10T14:29:38Z")

</div>

Wowww, that was pretty quick.

Thanks, @Cedric for the help. Certainly starting from that will help me a lot. This forum here was the best thing I’ve known since I started with Babylon. Thank you so much again!

I will try to bring updates as I progress with this task.

Best regards! 😃

---

<div class="post-metadata">

**Author:** ![MQDev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mqdev/32/16773_2.png) [@MQDev](https://forum.babylonjs.com/u/MQDev)\
**Post date:** [June 14, 2021, 1:54pm UTC](https://forum.babylonjs.com/t/how-could-be-the-best-way-of-implementing-an-fft-chart/21565/8 "2021-06-14T13:54:41Z")

</div>

That’s a good point.

The three.js tutorials I found were related to fft functions from the sound analyzer.  
I’ll have a look at Babylon’s one.

The problem I still have I guess is related to shaders. Do you guys know a bit about it?

Would it be possible to color it in the other direction? For example, the coolest spots would be blue, and the hottest is a composite of all the other colors in a gradient. The base would always be blue on all bars, and on the larger ones, they would have more than one color.

Color it in this direction:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/7/17bc81288fc4e8c508d5e265f8b421166e51a051.png)

Playground (Babylon version)  
[https://playground.babylonjs.com/#S7U8U8#3](https://playground.babylonjs.com/#S7U8U8#3)

Codepen: (Three.JS version)  
https://codepen.io/matheus-wc/embed/preview/XWMxRby?default-tabs=js%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=XWMxRby

Thanks again!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 14, 2021, 3:06pm UTC](https://forum.babylonjs.com/t/how-could-be-the-best-way-of-implementing-an-fft-chart/21565/9 "2021-06-14T15:06:49Z")

</div>

The equivalent of `InstanceMesh` is [thin instances](https://doc.babylonjs.com/divingDeeper/mesh/copies/thinInstances) in Babylon.js:

[https://playground.babylonjs.com/#LI1SSJ#4](https://playground.babylonjs.com/#LI1SSJ#4)
