Exemple #1
0
        public ActionResult <FrequencyDomain> FFT([FromBody] List <Double> value)
        {
            ComplexFastFourierTransform fft       = new ComplexFastFourierTransform();
            FrequencyDomain             transform = fft.Transform(value);

            return(Ok(transform));
        }
Exemple #2
0
        public IList <Complex> FrequencyResponse()
        {
            ComplexFastFourierTransform transform = new ComplexFastFourierTransform();
            List <Complex> coefficients           = transform.Transform(new List <double>(ImpulseResponse()), FilterLength).FourierCoefficients;

            return(coefficients);
        }
Exemple #3
0
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = $"{Properties.Resources.FILTER_IMPORT_EXPORT_FILE_EXTENSION} (*{Properties.Resources.FILTER_IMPORT_EXPORT_FILE_EXTENSION})|*{Properties.Resources.FILTER_IMPORT_EXPORT_FILE_EXTENSION}|{Properties.Resources.ALL_FILES} (*.*)|*.*";
            if (saveFileDialog.ShowDialog() == true)
            {
                try
                {
                    using (StreamWriter fileWriter = File.CreateText(saveFileDialog.FileName))
                    {
                        fileWriter.WriteLine(Properties.Resources.FILTER_CSV_HEADER);
                        List <double> summedFilterData              = manager.ActiveWorkBook().CombinedFilterImpulseResponse(true);
                        ComplexFastFourierTransform cmplxFFT        = new ComplexFastFourierTransform();
                        FrequencyDomain             frequencyDomain = cmplxFFT.Transform(summedFilterData, manager.ActiveWorkBook().WindowedSyncFilters.Values.First().FilterLength);

                        var magPhaseList = ComplexFastFourierTransform.ToMagnitudePhaseList(frequencyDomain);

                        foreach (Tuple <double, double> coefficientMagPhase in magPhaseList)
                        {
                            fileWriter.WriteLine($"{coefficientMagPhase.Item1},{coefficientMagPhase.Item2}");
                        }
                    }
                } catch (Exception ex)
                {
                    Log.Warning(ex, ex.Message);
                    // TODO warn user
                }
            }
        }
Exemple #4
0
        public void TestLoadFromFrequencyAmplitudes()
        {
            // low pass amplitude array
            double[] amplitudes = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                                    1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                    0.0, 0.0 };

            List <double> frequencyDomain = new List <double>(amplitudes);
            //FrequencyDomain frequencyDomain = ComplexFastFourierTransform.LoadFourierCoefficients(new List<double>(amplitudes));

            ComplexFastFourierTransform synth      = new ComplexFastFourierTransform();
            FrequencyDomain             timeDomain = synth.Transform(frequencyDomain, 2 * frequencyDomain.Count());

            foreach (var value in timeDomain.FrequencyAmplitudes)
            {
                Console.WriteLine(value);
            }
        }
Exemple #5
0
        // 64 channel sample with padCount zeros padded right
        public List <double> GetPaddedChannelSample(int sampleCount, int padCount)
        {
            int numSamplesToGet = (sampleCount - padCount);
            int curIDX          = _sampleIDX;

            if (curIDX + numSamplesToGet >= _samples.Count)
            {
                numSamplesToGet = _samples.Count - curIDX;
                if (numSamplesToGet <= 0)
                {
                    // Roll over to the beginning
                    _sampleIDX = 0;
                    return(GetPaddedChannelSample(sampleCount, padCount));
                }
            }

            _sampleIDX  += numSamplesToGet;
            _sliceSignal = _samples.GetRange(curIDX, numSamplesToGet);

            List <double> paddedSignal = new List <double>(sampleCount);

            paddedSignal.AddRange(_sliceSignal);
            // Pad
            int padLen = (sampleCount - numSamplesToGet);

            for (int cnt = 0; cnt < padLen; cnt++)
            {
                paddedSignal.Add(0.0);
            }

            IDFT ff_transform = new ComplexFastFourierTransform();
            IDFT cdf_tranform = new CorrelationFourierTransform();

            //_frequencyDomain = DFT.CorrelationTransform(paddedSignal);
            _frequencyDomain = ff_transform.Transform(paddedSignal);
            return(_sliceSignal);
        }