private static void WriteDFTResultToCells(FourierResult fourierResult, Worksheet worksheet, int realIndex, int imagIndex, int realAndImagSummed)
        {
            if (realIndex != 0)
            {
                for (int i = 0; i < fourierResult.RealComponents.Count; i++)
                {
                    int currentRow = i + RowsOffset;
                    var sample     = fourierResult.RealComponents[i];
                    worksheet.Cells[currentRow, realIndex].NumberFormat = "@";
                    worksheet.Cells[currentRow, realIndex].Value        = sample.Value;
                }
            }

            if (imagIndex != 0)
            {
                for (int i = 0; i < fourierResult.ImaginaryComponents.Count; i++)
                {
                    int currentRow = i + RowsOffset;
                    var sample     = fourierResult.ImaginaryComponents[i];
                    worksheet.Cells[currentRow, imagIndex].NumberFormat = "@";
                    worksheet.Cells[currentRow, imagIndex].Value        = sample.Value;
                }
            }

            if (realAndImagSummed != 0)
            {
                for (int i = 0; i < fourierResult.RealAndImagSummed.Count; i++)
                {
                    int currentRow = i + RowsOffset;
                    var sample     = fourierResult.RealAndImagSummed[i];
                    worksheet.Cells[currentRow, realAndImagSummed].NumberFormat = "@";
                    worksheet.Cells[currentRow, realAndImagSummed].Value        = sample.Value;
                }
            }
        }
Пример #2
0
        public static void DiscreteTransform(List <Sample> signalDataInTimeDomain, out FourierResult fourier)
        {
            int nSamples = signalDataInTimeDomain.Count();

            fourier = new FourierResult();

            for (int k = 0; k < nSamples; k++)
            {
                double sumReal      = 0;
                double sumImaginary = 0;
                for (int j = 0; j < nSamples; j++)
                {
                    double angle = 2 * Math.PI * j * k / nSamples;
                    sumReal      += signalDataInTimeDomain[j].Value * Math.Cos(angle) + signalDataInTimeDomain[j].Value * Math.Sin(angle);
                    sumImaginary += signalDataInTimeDomain[j].Value * Math.Cos(angle) - signalDataInTimeDomain[j].Value * Math.Sin(angle);
                }
                fourier.RealComponents.Add(new Sample(sumReal, 0));
                fourier.ImaginaryComponents.Add(new Sample(sumImaginary, 0));

                var module = Math.Sqrt(Math.Pow(sumReal, 2) + Math.Pow(sumImaginary, 2));
                fourier.RealAndImagSummed.Add(new Sample(module, 0));
            }
        }
        public static void WriteSignalDataAndDFTResult(string path, string excelFileName, FourierResult dftResult, SignalData inputData1 = null, SignalData inputData2 = null)
        {
            Application app        = null;
            Workbooks   workBooks  = null;
            Workbook    workbook1  = null;
            Sheets      worksheets = null;
            Worksheet   worksheet  = null;

            CreateExcelComponents(out app, out workBooks, out workbook1, out worksheets, out worksheet);

            WriteDFTResultToCells(dftResult, worksheet, DFTRealColumnIndex, DFTImaginaryColumnIndex, DFTRealAndImaginarySummedColumnIndex);

            WriteSignalDataToCells(inputData1, worksheet, Signal1ColumnDataIndex);
            WriteSignalDataToCells(inputData2, worksheet, Signal2ColumnDataIndex);

            SaveAndRelease(path, excelFileName, app, workBooks, workbook1, worksheets, worksheet);
        }