MK Dynamics

Current Projects - Discretized Fourier Transform of Arbitrary Signal Using FFTW3



The plan here is to write a Fortran 2003 program that utilizes the FFTW3 library to generate a Discretized Fast Fourier Transforms of arbitrary waveforms. To test the code we start with a function whose DFFT is easily identifiable by inspection, and then increase in complexity. SciLAB and Python+Numpy on Jupyter Notebook are used to generate the the time domain functions, time domain and frequency domain plots and discretized time domain data. The Fortran 2003 code is then run on the discretized time domain data and the results plotted with GNUPlot. A comparison is made to check the veracity of the Fortran 2003 code output.

Performance of Fortran 2003 DFFT Program for:
Sine Wave at 10Hz

Square Wave at 1Hz

Exponential Pulse of Time Constant 10 seconds

Sine Wave at 50Hz Generated with Python+Numpy on Jupyter Notebook

Two Sine Waves at 50Hz and 100Hz Generated with Python+Numpy on Jupyter Notebook

For the time domain data that is generated with SciLAB, the following datapath is utilized:

Discretized Fourier Transform of Arbitrary Signal Using FFTW3 Datapath

Python Script

Since the output of SciLAB is a comma separated value (CSV) file, a method is needed that will process
that file into another file, where the commas are removed and each data element is on a separate line.
This is most easily done using a Python script, with its powerful object-oriented file techniques and
its included CSV library. Additionaly, each data element is reformatted so that it is in fixed floating-point
format, with a decimal precision of 20 places. This is done so that the Fortran DFFT code can process
the data error-free. The Python script is shown below:

Processing of CSV file by Python script to strip commas and produce one data element per line

Python script that removes commas and produced one data element per line
Run by typing: ./ infile.csv outfile.dat
where infile.csv is the data file in CSV format, and outfile.dat is the processed file
Obtain the line count of the processed file by typing: wc -l outfile.dat

After the CSV file is processed into a suitable format, the following Fortran 2003 code is executed on it.
The Fortran 2003 code reads in the processed data and outputs the DFFT magnitude and phase, using the FFTW3

Fortran 2003 Code

Fortran 2003 Code to Perform Discretized Fast Fourier Transform on Processed File
Version 5

Fortran 2003 code that takes in parameters and performs DFFT to generate output file
Compile by typing: gfortran -o a.out data_file_FFTW_ver6.F03 -lfftw3
Run by typing: ./a.out outfile.dat DFFT_mag_file.dat DFFT_phase_file.dat sample_rate num_periods
where outfile.dat is the output of the Python script, DFFT_mag_file.dat is the DFFT magnitude file,
DFFT_phase_file.dat is the DFFT phase file,sample_rate is the rate of sampling of the input data file, and num_periods
is the number of periods of data in the input data file.
The line count can be obtained by typing: wc -l outfile.dat

Link to Archival Stuff