Why the Fourier transform?
The Fourier transform is applied to convert a signal in the time domain to a signal in the frequency spectrum characterized by sin or cosine functions. With that in mind, the Fourier transform can be used to analyze and decompose the waveforms (this decomposition depends on the phase and magnitude). There’s a large variety of applications for this in the engineering field, such as signal processing, signal analysis, predictive maintenance, etc.
You could plot the Fast Fourier Transform. Thus, you can obtain relevant information on the spectrum. For instance, this is the graph obtained by the NCD triaxial vibration sensor for the X-axis.
In this article, we’ll introduce the use of the Fourier transform plugin in Ubidots for your NCD predictive maintenance sensor.
Requirements:
An NCD PR55-61PM sensor connected to an IoT Edge Computer or equivalent NCD gateway.
An active Ubidots account (Industrial license and above).
1. NCD plugin installation on your Ubidots account
Step two: Click on the "+" button located at the upper right corner of the screen.
Step three: Look for the NCD plugin as seen below, once you click on it you will see a description of the plugin and its current version, then click on continue.
Step four: Configure the plugin by selecting the device token of the account.
Step five: Input the sampling frequency (it should match the Output rate configured in the sensor).
Step six: Enter a name and description for your plugin, then click on continue.
Step seven: Go to Decoder. Notice that you will be provided with an endpoint URL used to execute the decoding function (the plugin).
NOTE: It’ll calculate the Fast Fourier transform, then it returns the magnitudes and frequencies.
2. Program your decoding function.
You will be given a development environment where you can program and decode Sensor data using Python 3.7 and return a Ubidots compatible JSON.
This programming environment is divided into 2 sections
Test Payload: There you enter a sample payload that simulates the incoming Sensor data in JSON format, by clicking on "Test run", the decoding function will be executed using the test Payload as input. The output will be shown on the console.
Code Editor: Contains a prefilled code that can be edited at will. Click on "SAVE & MAKE LIVE" button to save and deploy the code.
3. Configure the NCD gateway to send the data to the FFT plugin.
At this point you should've already setup the IoT Edge Computer. If you haven't setup your IoT Edge Computer yet, please refer to this guide first, then setup your Predictive Maintenance sensor so that it sends Raw data by following this article.
To configure the gateway to send the device data to the plugin. To do so, we'll create a custom flow that will look like this:
Step one: Open NCD's User Interface (UI) by typing in any browser the default IP address 192.168.3.1 or the IP address shown in the IoT Edge Computer's screen.
Step two: Go to the Node Red tab, then locate the Flow where the Sensor Node was configured.
Step three: Import the following nodes onto the current flow.
[{"id":"3ac4cea9.817802","type":"function","z":"aa57ceec.2a8708","name":"Setup Request","func":"var data = msg.payload.data;\nvar payload = {};\n\npayload[\"data\"] = data\npayload[\"deviceLabel\"] = msg.data.addr\nmsg.payload = payload;\nmsg.headers = {};\nmsg.headers[\"Content-Type\"] = \"application/json\";\nmsg.headers[\"X-Auth-Token\"] = \"<YOUR_UBIDOTS_TOKEN>\";\nmsg.method = \"POST\";\n\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":260,"wires":[["343e37bb.5bf6d8"]]},{"id":"d3b29713.930378","type":"debug","z":"aa57ceec.2a8708","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":340,"wires":[]},{"id":"343e37bb.5bf6d8","type":"http request","z":"aa57ceec.2a8708","name":"Function Call","method":"use","ret":"obj","paytoqs":"ignore","url":"<YOUR_PLUGIN_URL>","tls":"","persist":false,"proxy":"","authType":"","x":710,"y":260,"wires":[["d3b29713.930378"]]}]
Step four: Connect the Wireless Sensor node with the Setup Request node.
Step five: Open the "Setup request" node
Step six: Assign your Ubidots Token in the "
X-Auth-Token
" headerStep seven: Finally, edit the HTTP request node and change the URL to the endpoint URL provided in the Decoder tab of your plugin.
NOTE: The complete flow would be something like this:
[{"id":"5fd5ef48.5b593","type":"ncd-gateway-node","z":"aa57ceec.2a8708","name":"","connection":"837142ce.132b28","unknown_devices":false,"outputs":1,"x":170,"y":140,"wires":[["d31847c3.cbcb88"]]},{"id":"d31847c3.cbcb88","type":"debug","z":"aa57ceec.2a8708","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":390,"y":140,"wires":[]},{"id":"d3d7fe08.c95e1","type":"ncd-wireless-node","z":"aa57ceec.2a8708","name":"Predictive Maintenance Sensor","connection":"837142ce.132b28","config_comm":"837142ce.132b28","addr":"00:13:a2:00:41:ee:32:a8","sensor_type":"82","auto_config":true,"node_id_delay_active":"","node_id":0,"delay":300,"destination":"0000FFFF","power_active":"","power":4,"retries_active":"","retries":10,"pan_id_active":"","pan_id":"7FFF","change_enabled":"","change_pr":"0","change_interval":"0","cm_calibration":"60.6","bp_altitude":"0","bp_pressure":"0","bp_temp_prec":"0","bp_press_prec":"0","amgt_accel":"0","amgt_mag":"0","amgt_gyro":"0","impact_accel":"0","impact_data_rate":"4","impact_threshold":25,"impact_duration":1,"activ_interr_x":1,"activ_interr_y":2,"activ_interr_z":4,"activ_interr_op":8,"force_calibration_co2_auto_config":"","force_calibration_co2":400,"filtering":0,"data_rate":5,"time_series":0,"reading_type":1,"mode_80_active":"","mode_80":"1","measurement_mode_80_active":"","measurement_mode_80":0,"on_request_timeout_80_active":"","on_request_timeout_80":0,"deadband_80_active":"","deadband_80":0,"filter_80_active":"","filter_80":0,"output_data_rate_p1_81_active":"","output_data_rate_p1_81":0,"output_data_rate_p2_81_active":"","output_data_rate_p2_81":0,"sampling_duration_p1_81_active":"","sampling_duration_p1_81":0,"sampling_duration_p2_81_active":"","sampling_duration_p2_81":0,"current_calibration_82":"","current_calibration_82_active":false,"output_data_rate_101_active":"","output_data_rate_101":0,"sampling_duration_101_active":"","sampling_duration_101":1,"sampling_interval_101_active":true,"sampling_interval_101":"4","full_scale_range_101_active":"","full_scale_range_101":1,"x_axis_101":"","y_axis_101":"","z_axis_101":"","x":190,"y":260,"wires":[["13a982fb.2b80cd","3ac4cea9.817802"]]},{"id":"13a982fb.2b80cd","type":"debug","z":"aa57ceec.2a8708","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":160,"y":340,"wires":[]},{"id":"3ac4cea9.817802","type":"function","z":"aa57ceec.2a8708","name":"Setup Request","func":"var data = msg.payload.data;\nvar payload = {};\n\npayload[\"data\"] = data\npayload[\"deviceLabel\"] = msg.data.addr\nmsg.payload = payload;\nmsg.headers = {};\nmsg.headers[\"Content-Type\"] = \"application/json\";\nmsg.headers[\"X-Auth-Token\"] = \"BBFF-2f34RG8mr78GW1T68jR8Ui5R4xx8iT0\";\nmsg.method = \"POST\";\n\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":260,"wires":[["343e37bb.5bf6d8"]]},{"id":"d3b29713.930378","type":"debug","z":"aa57ceec.2a8708","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":340,"wires":[]},{"id":"343e37bb.5bf6d8","type":"http request","z":"aa57ceec.2a8708","name":"Function Call","method":"use","ret":"obj","paytoqs":"ignore","url":"http://dataplugin.ubidots.com/api/web-hook/hhytyDUIL-C_k!5U7Y85F88CFJw=","tls":"","persist":false,"proxy":"","authType":"","x":690,"y":260,"wires":[["d3b29713.930378"]]},{"id":"837142ce.132b28","type":"ncd-gateway-config","name":"","comm_type":"serial","ip_address":"","tcp_port":"2101","port":"/dev/ttyS1","baudRate":"115200","pan_id":"7FFF","rssi":true}]
4. Start receiving the amplitude and frequency of your signal
In this case, the NCD accelerometer device is a triaxial device because it’s measuring vibration on the X, Y, and Z-axis. The JSON incoming payload from the NCD gateway is sent as follows:
{
"deviceLabel":"machine_one",
"data":{
"dot1": {
"X":"value_of_axis_x",
"Y":"value_of_axis_y",
"Z":"value_of_axis_z"
},
"dot2":{
"X":"value_of_axis_x",
"Y":"value_of_axis_y",
"Z":"value_of_axis_z"
}
}
}
If everything is correctly set, the function must return a dictionary that contains three NumPy arrays of dots composed of N samples, for example:
{
{"axis_X":"[X1,X2,X3,X4...Xn]"},
{"axis_Y":"[Y1,Y2,Y3,Y4...Yn]"},
{"axis_Z":"[Z1,Z2,Z3,Z4...Zn]"}
}
At last, the function calculates the Fast Fourier Transform for each vector in the dictionary to give the N amplitudes and frequencies which will be stored as NumPy vectors in the context of a new variable. In addition, the max values of amplitude and frequency are set by default in the "value" field.
{
{"amplitude":{"value":"amplitudeMax","context":"amplitude":" [a1,a2,a3...an]"},
{"frequency":{"value":"frequencyMax","context":"frequency":"[f1,f2,f3...fn]"}
}
At this point, the data is going to be transformed to the frequency specter with the Fast Fourier Transform. In addition, the user will have the possibility to analyze the specter with the amplitude and frequencies generated by Ubidots. Thus, once a correct incoming payload has been received by Ubidots, it’s going to create these variables in the device created: frequency-x, frequency-y, frequency-z, max-amplitude-x, max-amplitude-y, and max-amplitude-z, on these variables it’s possible to visualize the data transformed by the Fast Fourier Transform (FFT).
Then, the respective variables will be created and the user will be able to see the data in the UI. This data shows the maximum value for all the axis, and in the context will store the amplitude or frequency, that depends on the variable chosen, the variables will be set as follows:
Frequency variable for the Y-axis:
Amplitude variable for the Y-axis:
4. Check the results.
From now, you’re able to plot your data transformed with the FFT in Ubidots. You could use a High Frequency Widget to represent the data for all the axis.
Related articles: