forked from swharden/Spectrogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReports.cs
More file actions
50 lines (46 loc) · 1.88 KB
/
Reports.cs
File metadata and controls
50 lines (46 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Text;
namespace Spectrogram
{
public static class Reports
{
public static void plot(float[] values, string saveFilePath, double sampleRateHz = 1, string title = null, string yLabel = null, string xLabel = null)
{
double[] values2 = new double[values.Length];
for (int i = 0; i < values.Length; i++)
values2[i] = values[i];
var plt = new ScottPlot.Plot();
plt.PlotSignal(values2, sampleRateHz, markerSize: 0);
plt.Title(title);
plt.YLabel(yLabel);
plt.XLabel(xLabel);
plt.AxisAuto(0);
plt.SaveFig(saveFilePath);
Console.WriteLine($"Saved: {System.IO.Path.GetFullPath(saveFilePath)}");
}
public static void plotValues(double[] values, string saveFilePath = "values.png", int sampleRateHz = 8000)
{
var plt = new ScottPlot.Plot();
plt.PlotSignal(values, sampleRateHz, markerSize: 0, lineWidth: 2);
plt.Title("Signal");
plt.YLabel("Value");
plt.XLabel("Time (sec)");
plt.AxisAuto(0);
plt.SaveFig(saveFilePath);
Console.WriteLine($"Saved: {System.IO.Path.GetFullPath(saveFilePath)}");
}
public static void plotFFT(double[] fft, string saveFilePath = "fft.png", int sampleRateHz = 8000)
{
var plt = new ScottPlot.Plot();
double fftSampleRate = (double)fft.Length / sampleRateHz * 2;
plt.PlotSignal(fft, fftSampleRate, markerSize: 0, lineWidth: 2);
plt.Title("FFT");
plt.YLabel("Power");
plt.XLabel("Frequency (Hz)");
plt.AxisAuto(0);
plt.SaveFig(saveFilePath);
Console.WriteLine($"Saved: {System.IO.Path.GetFullPath(saveFilePath)}");
}
}
}