1 /*************************************************************************** 2 psdcalculator.cpp: Power Spectra Calculator for KST 3 ------------------- 4 begin : 2006 5 copyright : (C) 2006 by Kst 6 email : netterfield@astro.utoronto.ca 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 /** A utility class for calculating power spectra 19 */ 20 21 #ifndef PSDCALCULATOR_H 22 #define PSDCALCULATOR_H 23 24 #include "kstmath_export.h" 25 26 // the following should reflect the PSD type order in fftoptionswidget.ui 27 enum PSDType { 28 PSDUndefined = -1, 29 PSDAmplitudeSpectralDensity = 0, 30 PSDPowerSpectralDensity = 1, 31 PSDAmplitudeSpectrum = 2, 32 PSDPowerSpectrum = 3 33 }; 34 35 // the following should reflect the window type order in fftoptionswidget.ui 36 enum ApodizeFunction { 37 WindowUndefined = -1, 38 WindowOriginal = 0, 39 WindowBartlett = 1, 40 WindowBlackman = 2, 41 WindowConnes = 3, 42 WindowCosine = 4, 43 WindowGaussian = 5, 44 WindowHamming = 6, 45 WindowHann = 7, 46 WindowWelch = 8, 47 WindowUniform = 9 48 }; 49 50 51 class KSTMATH_EXPORT PSDCalculator { 52 public: 53 PSDCalculator(); 54 ~PSDCalculator(); 55 56 int calculatePowerSpectrum(double const *input, int input_len, double *output, int output_len, 57 bool remove_mean, bool average, int average_len, 58 bool apodize, ApodizeFunction apodize_function, double gaussian_sigma, 59 PSDType output_type, double sampling_freq, 60 double const *input2 = 0L, int input2_len = 0, double *output2 = 0L); 61 62 static int calculateOutputVectorLength(int input_len, bool average, int average_len); 63 64 private: 65 void updateWindowFxn(ApodizeFunction apodizeFxn, double gaussianSigma); 66 void adjustInternalLengths(); 67 double cabs2(double r, double i); 68 69 double *_a; 70 double *_b; 71 double *_w; 72 73 int _fft_len; //length of a and w. 74 75 // keep track of prevs to avoid redundant regenerations 76 ApodizeFunction _prev_apodize_function; 77 double _prev_gaussian_sigma; 78 79 int _prev_output_len; 80 bool _prev_cross_spec; 81 }; 82 83 #endif 84 // vim: ts=2 sw=2 et 85