File indexing completed on 2024-05-12 15:27:06

0001 /***************************************************************************
0002     File                 : nsl_dft.h
0003     Project              : LabPlot
0004     Description          : NSL discrete Fourier transform functions
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2016 by Stefan Gerlach (stefan.gerlach@uni.kn)
0007 
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *  This program is free software; you can redistribute it and/or modify   *
0013  *  it under the terms of the GNU General Public License as published by   *
0014  *  the Free Software Foundation; either version 2 of the License, or      *
0015  *  (at your option) any later version.                                    *
0016  *                                                                         *
0017  *  This program is distributed in the hope that it will be useful,        *
0018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0020  *  GNU General Public License for more details.                           *
0021  *                                                                         *
0022  *   You should have received a copy of the GNU General Public License     *
0023  *   along with this program; if not, write to the Free Software           *
0024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0025  *   Boston, MA  02110-1301  USA                                           *
0026  *                                                                         *
0027  ***************************************************************************/
0028 
0029 #ifndef NSL_DFT_H
0030 #define NSL_DFT_H
0031 
0032 #include <stdlib.h>
0033 #include "nsl_sf_window.h"
0034 
0035 /* DFT result type:
0036     real = x
0037     imag = y
0038     magnitude = sqrt(x^2+y^2)
0039     amplitude = magnitude/n
0040     power = (x^2+y^2)/n aka periodigram, SSA
0041     phase = atan(y/x)
0042     dB = 20.*log_10(amplitude)
0043     normdB = dB - max(dB)
0044     squaremagnitude = magnitude^2
0045     squareamplitude = amplitude^2 aka MSA
0046     raw = halfcomplex GSL output (TODO: FFTW)
0047     TODO: PSD (aka TISA), normdB
0048  */
0049 #define NSL_DFT_RESULT_TYPE_COUNT 11
0050 typedef enum {nsl_dft_result_magnitude, nsl_dft_result_amplitude, nsl_dft_result_real, nsl_dft_result_imag, nsl_dft_result_power, 
0051     nsl_dft_result_phase, nsl_dft_result_dB, nsl_dft_result_normdB, nsl_dft_result_squaremagnitude, nsl_dft_result_squareamplitude, 
0052     nsl_dft_result_raw} nsl_dft_result_type;
0053 extern const char* nsl_dft_result_type_name[];
0054 /* x axis scaling */
0055 #define NSL_DFT_XSCALE_COUNT 3
0056 typedef enum {nsl_dft_xscale_frequency, nsl_dft_xscale_index, nsl_dft_xscale_period} nsl_dft_xscale; 
0057 extern const char* nsl_dft_xscale_name[];
0058 
0059 /* transform data of size n. result in data 
0060     calculates the two-sided DFT
0061 */
0062 int nsl_dft_transform(double data[], size_t stride, size_t n, int two_sided, nsl_dft_result_type type);
0063 /* windowed version */
0064 int nsl_dft_transform_window(double data[], size_t stride, size_t n, int two_sided, nsl_dft_result_type type, nsl_sf_window_type window);
0065 
0066 #endif /* NSL_DFT_H */