Skip to content

Commit f786cc9

Browse files
committed
update waterfall demo
1 parent 43f860b commit f786cc9

7 files changed

Lines changed: 72 additions & 21 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ spec.SaveImage("qrss.jpg");
5050
## Waterfall
5151
This demo program was created to demonstrate Spectrogram and ScottPlot working together.
5252

53-
![](data/screenshot6.gif)
53+
![](data/screenshot7.gif)
5454

5555
## Developer Notes
5656

data/screenshot7.gif

12.9 MB
Loading

src/SpectrographStuff.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Demos", "Demos", "{9B6B9DCD
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaterfallDemo", "WaterfallDemo\WaterfallDemo.csproj", "{3264BE41-10B0-4121-B837-D7B134BD1A9B}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScottPlot", "..\..\ScottPlot\src\ScottPlot\ScottPlot.csproj", "{EE9215C6-01C1-4835-8514-3A708F9291F1}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -35,6 +37,10 @@ Global
3537
{3264BE41-10B0-4121-B837-D7B134BD1A9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
3638
{3264BE41-10B0-4121-B837-D7B134BD1A9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
3739
{3264BE41-10B0-4121-B837-D7B134BD1A9B}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{EE9215C6-01C1-4835-8514-3A708F9291F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{EE9215C6-01C1-4835-8514-3A708F9291F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{EE9215C6-01C1-4835-8514-3A708F9291F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{EE9215C6-01C1-4835-8514-3A708F9291F1}.Release|Any CPU.Build.0 = Release|Any CPU
3844
EndGlobalSection
3945
GlobalSection(SolutionProperties) = preSolution
4046
HideSolutionNode = FALSE

src/WaterfallDemo/Form1.Designer.cs

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WaterfallDemo/Form1.cs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,65 @@ public Form1()
1717
InitializeComponent();
1818

1919
waterfall1.intensity = 10;
20-
21-
scottPlotUC1.plt.Ticks(displayTicksY: false);
22-
scottPlotUC1.plt.TightenLayout(0);
23-
scottPlotUC1.plt.Grid(false);
2420
}
2521

2622
private void Form1_Load(object sender, EventArgs e)
2723
{
2824
waterfall1.StartListening(deviceIndex: 0);
2925
}
3026

31-
private void Timer1_Tick(object sender, EventArgs e)
27+
private void UpdateWaterfallPlot()
3228
{
33-
if ((waterfall1.spec.fftList == null) || (waterfall1.spec.fftList.Count == 0))
34-
return;
35-
3629
scottPlotUC1.plt.Clear();
3730

3831
var fft = waterfall1.spec.fftList[waterfall1.spec.fftList.Count - 1];
3932
double[] fft2 = new double[fft.Length];
4033
for (int i = 0; i < fft.Length; i++)
4134
fft2[i] = fft[i];
4235

43-
scottPlotUC1.plt.PlotSignal(fft2, 1.0/waterfall1.spec.fftSettings.fftResolution, markerSize: 0);
44-
scottPlotUC1.plt.AxisAuto();
36+
scottPlotUC1.plt.PlotSignal(fft2, 1.0 / waterfall1.spec.fftSettings.fftResolution,
37+
markerSize: 0, color: Color.Black);
38+
scottPlotUC1.plt.AxisAuto(0, .01, xExpandOnly: false, yExpandOnly: true);
39+
40+
scottPlotUC1.plt.Grid(false);
41+
scottPlotUC1.plt.Style(dataBg: SystemColors.Control);
42+
scottPlotUC1.plt.Frame(drawFrame: false);
43+
scottPlotUC1.plt.TightenLayout(padding: 0);
44+
4545
scottPlotUC1.Render();
4646
}
47+
48+
private void UpdateSignalPlot()
49+
{
50+
scottPlotUC2.plt.Clear();
51+
52+
int pointCount = 1000;
53+
var sigList = waterfall1.spec.signal;
54+
var lastSamples = sigList.GetRange(sigList.Count - pointCount, pointCount);
55+
56+
double[] pcm = new double[pointCount];
57+
for (int i = 0; i < pointCount; i++)
58+
pcm[i] = lastSamples[i];
59+
60+
scottPlotUC2.plt.PlotSignal(pcm, 1.0 / waterfall1.spec.fftSettings.fftResolution,
61+
markerSize: 0, color: Color.Black);
62+
scottPlotUC1.plt.AxisAuto(0, .01, xExpandOnly: false, yExpandOnly: true);
63+
64+
scottPlotUC2.plt.Grid(false);
65+
scottPlotUC2.plt.Style(dataBg: SystemColors.Control);
66+
scottPlotUC2.plt.Frame(drawFrame: false);
67+
scottPlotUC2.plt.TightenLayout(padding: 0);
68+
69+
scottPlotUC2.Render();
70+
}
71+
72+
private void Timer1_Tick(object sender, EventArgs e)
73+
{
74+
if ((waterfall1.spec.fftList == null) || (waterfall1.spec.fftList.Count == 0))
75+
return;
76+
77+
UpdateSignalPlot();
78+
UpdateWaterfallPlot();
79+
}
4780
}
4881
}

src/WaterfallDemo/WaterfallDemo.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
<Reference Include="NAudio, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
3636
<HintPath>..\packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
3737
</Reference>
38-
<Reference Include="ScottPlot, Version=3.0.8.0, Culture=neutral, processorArchitecture=MSIL">
39-
<HintPath>..\packages\ScottPlot.3.0.9\lib\net45\ScottPlot.dll</HintPath>
40-
</Reference>
4138
<Reference Include="System" />
4239
<Reference Include="System.Core" />
4340
<Reference Include="System.Xml.Linq" />
@@ -95,6 +92,10 @@
9592
<None Include="App.config" />
9693
</ItemGroup>
9794
<ItemGroup>
95+
<ProjectReference Include="..\..\..\ScottPlot\src\ScottPlot\ScottPlot.csproj">
96+
<Project>{ee9215c6-01c1-4835-8514-3a708f9291f1}</Project>
97+
<Name>ScottPlot</Name>
98+
</ProjectReference>
9899
<ProjectReference Include="..\Spectrogram\Spectrogram.csproj">
99100
<Project>{8717f4ce-4497-4eaa-b95d-0f7a04fb397d}</Project>
100101
<Name>Spectrogram</Name>

src/WaterfallDemo/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="NAudio" version="1.9.0" targetFramework="net45" />
4-
<package id="ScottPlot" version="3.0.9" targetFramework="net45" />
54
</packages>

0 commit comments

Comments
 (0)