private static void WriteSignalDataToCells(SignalData inputData, Worksheet worksheet, int columnIndex) { if (inputData != null) { worksheet.Cells[0 + RowsOffset, columnIndex].Value = "freq: " + inputData.Frequency.ToString(); worksheet.Cells[1 + RowsOffset, columnIndex].Value = "puls: " + inputData.Pulsation.ToString(); worksheet.Cells[2 + RowsOffset, columnIndex].Value = "samplingRate: " + inputData.SamplingRate.ToString(); worksheet.Cells[3 + RowsOffset, columnIndex].Value = "simulationTime: " + inputData.SimulationTime.ToString(); worksheet.Cells[4 + RowsOffset, columnIndex].Value = "phase: " + inputData.Phase.ToString(); worksheet.Cells[5 + RowsOffset, columnIndex].Value = "ampl: " + inputData.Amplitude.ToString(); worksheet.Cells[6 + RowsOffset, columnIndex].Value = "period: " + inputData.Period.ToString(); } }
public static void WriteSamples(string path, string excelFileName, List <Sample> samples, SignalData inputData1, SignalData inputData2 = null, SignalData inputData3 = null, AdditionalSignalData inputData4 = null, List <Sample> samples1 = null, List <Sample> samples2 = null) { Application app = null; Workbooks workBooks = null; Workbook workbook = null; Sheets worksheets = null; Worksheet worksheet = null; CreateExcelComponents(out app, out workBooks, out workbook, out worksheets, out worksheet); WriteSampleValuesToCells(samples, worksheet, FinalSampleValueColumnIndex, SampleDeltaTimeColumnIndex); WriteSignalDataToCells(inputData1, worksheet, Signal1ColumnDataIndex); WriteSignalDataToCells(inputData2, worksheet, Signal2ColumnDataIndex); WriteSignalDataToCells(inputData3, worksheet, Signal3ColumnDataIndex); WriteAdditionalDataToCells(inputData4, worksheet, AdditionalDataColumnIndex); WriteSampleValuesToCells(samples1, worksheet, Sample1ValueColumnIndex, 0); WriteSampleValuesToCells(samples2, worksheet, Sample2ValueColumnIndex, 0); SaveAndRelease(path, excelFileName, app, workBooks, workbook, worksheets, worksheet); }
/// <summary> /// Generator wartosci liczbowych, dla zadanych parametrow. /// Realizuje funkcje: x(t) = A * sin(omega + fi), gdzie: omega = 2 * PI * f. /// /// </summary> /// <param name="ampl">Amplituda (najwieksze wychylenie).</param> /// <param name="frequency">Czestotliwosc (czestosc) probkowania. Wyrazana w [Hz]. Czestotliwosc 1 herca odpowiada wystepowaniu jednego cyklu (zdarzenia) w ciagu 1s.</param> /// <param name="period">Okres T. Czas, w ktorym zachodzi jeden cykl drgañ. </param> /// <param name="phase"> Faza poczatkowa. </param> /// <returns>Zwraca ciag liczbowy. Kazda wartosc ciagu nazywa sie probka.</returns> public static List <Sample> GenerateSamples(double ampl, double frequency, out SignalData input, double phase = 0) { if (GlobalSamplingRate < frequency * 2) { throw new Exception($"Czestotliwosc probkowania musi byc co najmniej 2x wieksza niz dwukrotnosc czestotliwosci sygnalu. Zadana nieprawidlowa czestotliwosc: {frequency}"); } List <Sample> samples = new List <Sample>(); //this is unsused, just for the output data double period = 1 / frequency; double pulsation = 2 * Math.PI * frequency; double deltaTime = GlobalSimulationTimeSeconds / GlobalSamplingRate; double time = deltaTime; for (int sample = 1; sample <= GlobalSamplingRate; sample++) { var sampleValue = ampl * Math.Sin(pulsation * time + phase); samples.Add(new Sample(sampleValue, time)); time += deltaTime; } input = new SignalData() { Frequency = frequency, Pulsation = pulsation, SimulationTime = GlobalSimulationTimeSeconds, SamplingRate = GlobalSamplingRate, Phase = phase, Amplitude = ampl, Period = period }; return(samples); }
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); }