# FFT - Has anyone ever used it?

**URL:** <https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476>\
**Category:** General\
**Created:** [24 September 2021 14:34 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476 "2021-09-24T14:34:38Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_ireland](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@chris\_ireland](https://discourse.nodered.org/u/chris_ireland)\
**Post date:** [24 September 2021 14:34 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/1 "2021-09-24T14:34:38Z")

</div>

Hi, I am hoping to use the FFT node - node-red-contrib-fft

It requires data in a certain format as follows:

```auto
{ "data" : [  
{"accelerometer_x" : 9 , "accelerometer_y":2, "accelerometer_z":2},
{"accelerometer_x" : 7 , "accelerometer_y":2, "accelerometer_z":2},
{"accelerometer_x" : 5 , "accelerometer_y":0, "accelerometer_z":0},
{"accelerometer_x" : 7 , "accelerometer_y":2, "accelerometer_z":2}
]}

```

I receive MQTT data from a 3-axis accelerometer in this format:

`{"axis":"g","x":-0.919,"y":0.209,"z":0.258}`

Ths gives a bad data inject error.

Can anyone recommend a course of action to correctly format the data?

Thanks.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 September 2021 14:49 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/2 "2021-09-24T14:49:53Z")

</div>

Do you mean you are sending in one sample at a time? According to the node docs you have to send it an array of samples.

---

<div class="post-metadata">

**Author:** ![chris\_ireland](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@chris\_ireland](https://discourse.nodered.org/u/chris_ireland)\
**Post date:** [24 September 2021 14:57 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/3 "2021-09-24T14:57:02Z")

</div>

Thanks Colin.

I can strip out the data and add it to an array but I still need to get it into the specific format required by the FFT block.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 September 2021 14:58 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/4 "2021-09-24T14:58:45Z")

</div>

Get it into an array and then show us what it looks like (in a debug node). Then we can help you with the last bit.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 September 2021 15:03 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/5 "2021-09-24T15:03:02Z")

</div>

Feed the samples from MQTT through a Change node set to Move msg.payload.x To msg.payload.accelerometer\_x, with similar lines in the Change node for the other two and another line to Delete msg.payload.axis. That should get the individual samples correct. Then you need to collect them into an array, then you can get it to the format required using another Change node to Move msg.payload To msg.payload.data.

---

<div class="post-metadata">

**Author:** ![chris\_ireland](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@chris\_ireland](https://discourse.nodered.org/u/chris_ireland)\
**Post date:** [24 September 2021 16:33 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/6 "2021-09-24T16:33:35Z")

</div>

The data is now in an array (5 samples of x, y and z) and changed to `msg.payload.data` format.

[-1.901,1.17,-0.352,-1.901,1.17,-0.352,-1.901,1.17,-0.352,-1.901,1.17,-0.352,-1.901,1.17,-0.352]

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 September 2021 20:56 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/7 "2021-09-24T20:56:26Z")

</div>

That doesn't look like the format the node says it needs.

---

<div class="post-metadata">

**Author:** ![chris\_ireland](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@chris\_ireland](https://discourse.nodered.org/u/chris_ireland)\
**Post date:** [27 September 2021 09:32 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/8 "2021-09-27T09:32:02Z")

</div>

With a few more tweaks it now looks like this:

`{"data":[{"accelerometer_x":-0.801,"accelerometer_y":0.527,"accelerometer_z":0.193},{"accelerometer_x":-0.801,"accelerometer_y":0.527,"accelerometer_z":0.193},{"accelerometer_x":-0.801,"accelerometer_y":0.527,"accelerometer_z":0.193},{"accelerometer_x":-0.801,"accelerometer_y":0.527,"accelerometer_z":0.193},{"accelerometer_x":-0.801,"accelerometer_y":0.527,"accelerometer_z":0.193}]}`

With a few modifications to the data (float to int) the output of the FFT block looks like this:  
`{"data":[{"accelerometer_x":1,"accelerometer_y":1,"accelerometer_z":1},{"accelerometer_x":1,"accelerometer_y":1,"accelerometer_z":1},{"accelerometer_x":1,"accelerometer_y":1,"accelerometer_z":1},{"accelerometer_x":1,"accelerometer_y":1,"accelerometer_z":1},{"accelerometer_x":1,"accelerometer_y":1,"accelerometer_z":1}],"fft_0":null,"fft_1":null,"fft_2":null,"fft_3":null,"fft_4":null}`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 September 2021 09:56 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/9 "2021-09-27T09:56:55Z")

</div>

Is it all working now?  
Why are you converting the floats to ints?

---

<div class="post-metadata">

**Author:** ![chris\_ireland](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@chris\_ireland](https://discourse.nodered.org/u/chris_ireland)\
**Post date:** [27 September 2021 09:59 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/10 "2021-09-27T09:59:01Z")

</div>

No, the FFT block is outputting NaN for the FFT values.

I convert the accel data using Math.ceil in a function block.

The FFT block gives an error if the input values are not integers equal to 1 or greater.

Right now I just want to see what the FFT data looks like, I can fix precision etc. later.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 September 2021 10:10 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/11 "2021-09-27T10:10:15Z")

</div>

Try it feeding in the data in the example in the node's readme. If that works then you know that if you provide good data then the node works.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [27 September 2021 10:23 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/12 "2021-09-27T10:23:58Z")

</div>

Just to let you know, `node-red-contrib-fft` hasn't been updated since August 2016 and the author doesn't seem to be active on GitHub anymore.

Plus there is an open issue in GitHub `[RangeError from Example Array](https://github.com/LeanBI/node-red-contrib-fft/issues/1)` that is still open.

Personally I'd be looking for another way to do what you want to do.

---

<div class="post-metadata">

**Author:** ![chris\_ireland](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@chris\_ireland](https://discourse.nodered.org/u/chris_ireland)\
**Post date:** [27 September 2021 10:24 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/13 "2021-09-27T10:24:53Z")

</div>

I am pretty certain this FFT finction does not work.

Thanks for all your help.

---

<div class="post-metadata">

**Author:** ![Fabrizzio](https://avatars.discourse-cdn.com/v4/letter/f/6f9a4e/32.png) [@Fabrizzio](https://discourse.nodered.org/u/Fabrizzio)\
**Post date:** [3 November 2021 17:00 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/14 "2021-11-03T17:00:44Z")

</div>

Hey, I am working with a similar project and I want to get the FFT of my accelerations. How did you solve it?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 January 2022 17:00 UTC](https://discourse.nodered.org/t/fft-has-anyone-ever-used-it/51476/15 "2022-01-02T17:00:53Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
