The script parses the sensor data and subsequently performs FFT to illustrate the temporal trends in the respiratory rates.
Fourier analysis converts a signal from its time domain to a representation in the frequency domain and vice versa. Fast Fourier transforms are widely used for applications in engineering, science, and mathematics. The basic ideas were popularized in 1965, but some algorithms had been derived as early as 1805.
To demonstrate the inner workings of our code, we will use a sample file (sample_sensor_data.txt).
In the above image, you could see that the entries within the variables are placed at regular intervals and their sampling frequency is ~50 samples/sec. The script will remove all the variables except respiratory ('rresp') and time ('timestamp') variables. Subsequently, it decodes the time variable to seconds with a starting entry at 0 seconds, to make it more meaningful. An arbitary plot illustrating time vs amplitude of the signal is saved (as Raw_signal_figure.pdf) in the working directory. The below is the plot generated by the script for our sample dataset.
Importantly, the sensor data is preprocessed to attenuate noise associated with the signals. A sliding window approach is used, where each window/batch comprises of 1500 samples (that corresponds to approx 30 seconds). The window is moved one sample at a time (i.e., the first sample of the previous window is discarded to include a new sample in the current window).
Each window of respiratory signals are rescaled using mean-centering. Therafter, Discrete Fourier Transform is applied on each window to identify the dominant frequency. The dominant frequencies across all windows are plotted against their corresponding times (in seconds). The resultant plot is again saved (as Dominant_Frequency_across_time_plot.pdf) in the working directory. The below plot represents the time in seconds vs frequencies (Hz) for our sample dataset.
$ git clone https://github.com/rcvenkata/Fast_Fourier_Transform.git
$ cd Fast_Fourier_Transform/
$ cat sample_sensor_data.txt | script.sh