84 lines
2.3 KiB
C#
84 lines
2.3 KiB
C#
using ScottPlot;
|
|
using Sunny.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Accord.Controls;
|
|
using Accord.MachineLearning.VectorMachines.Learning;
|
|
using Accord.Math;
|
|
using MathNet.Numerics.IntegralTransforms;
|
|
using Accord.Statistics.Kernels;
|
|
using Accord.Statistics.Models.Regression.Linear;
|
|
using HslCommunication.Algorithms.Fourier;
|
|
using HslCommunication.Profinet.Melsec;
|
|
using HslCommunication.Core;
|
|
using CenterSpace.NMath.Core;
|
|
|
|
namespace 测试Scottplot
|
|
{
|
|
public partial class Form1 : UIForm
|
|
{
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
// 生成测试信号 - 200KHz采样率下的1kHz正弦波(带噪声)
|
|
double sampleRate = 2000; // 200 kHz
|
|
double frequency = 2000; // 1 kHz
|
|
int numberOfSamples = 2000; // 100ms的数据
|
|
Random rand = new Random();
|
|
|
|
List<double> sampledData = new List<double>();
|
|
for (int i = 0; i < numberOfSamples; i++)
|
|
{
|
|
double time = i / sampleRate;
|
|
double noise = 0.1 * (rand.NextDouble() - 0.5); // 添加一些噪声
|
|
// double noise = 0;
|
|
sampledData.Add(Math.Sin(2 * Math.PI * frequency * time) + noise);
|
|
}
|
|
|
|
|
|
// 转换为周期RMS值
|
|
var rmsValues = SignalProcessor.ConvertToRmsPerPeriod(sampledData, sampleRate, frequency);
|
|
Console.WriteLine($"Calculated {rmsValues.Count} RMS values:");
|
|
Console.WriteLine(string.Join(", ", rmsValues.Take(5)) + "..."); // 显示前5个值
|
|
|
|
// 生成直流拟合信号
|
|
var dcSignal = SignalProcessor.GenerateDcSignal(rmsValues, sampleRate, frequency);
|
|
Console.WriteLine($"Generated DC signal with {dcSignal.Count} points");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void button2_Click_1(object sender, EventArgs e)
|
|
{
|
|
MelsecFxSerial melsecFxSerial = new MelsecFxSerial();
|
|
}
|
|
}
|
|
}
|