MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / perform_fft

Function perform_fft

src/data_handler/data_handler.cpp:780–831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

778}
779
780int perform_fft (
781 double *data, int data_len, int window_function, double *output_re, double *output_im)
782{
783 if ((!data) || (!output_re) || (!output_im) || (data_len <= 0) || (data_len % 2 == 1))
784 {
785 data_logger->error (
786 "Please check to make sure all arguments aren't empty and data_len is even.");
787 return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
788 }
789
790 double *windowed_data = new double[data_len];
791 get_window (window_function, data_len, windowed_data);
792 for (int i = 0; i < data_len; i++)
793 {
794 windowed_data[i] *= data[i];
795 }
796 kiss_fft_cpx *sout = new kiss_fft_cpx[data_len];
797 kiss_fftr_cfg cfg = NULL;
798 try
799 {
800 cfg = kiss_fftr_alloc (data_len, 0, 0, 0);
801 kiss_fftr (cfg, windowed_data, sout);
802 for (int i = 0; i < data_len / 2 + 1; i++)
803 {
804 output_re[i] = sout[i].r;
805 output_im[i] = sout[i].i;
806 }
807 delete[] sout;
808 delete[] windowed_data;
809 windowed_data = NULL;
810 sout = NULL;
811 kiss_fftr_free (cfg);
812 }
813 catch (...)
814 {
815 if (sout)
816 {
817 delete[] sout;
818 }
819 if (windowed_data)
820 {
821 delete[] windowed_data;
822 }
823 if (cfg)
824 {
825 kiss_fftr_free (cfg);
826 }
827 data_logger->error ("Error with doing FFT processing.");
828 return (int)BrainFlowExitCodes::GENERAL_ERROR;
829 }
830 return (int)BrainFlowExitCodes::STATUS_OK;
831}
832
833// data_len here is an original size, not len of input_re input_im
834int perform_ifft (double *input_re, double *input_im, int data_len, double *restored_data)

Callers 3

get_psdFunction · 0.70
perform_fftMethod · 0.50
mainFunction · 0.50

Calls 1

get_windowFunction · 0.70

Tested by

no test coverage detected