CgdataBase.Algorithm
1.9.6
dotnet add package CgdataBase.Algorithm --version 1.9.6
NuGet\Install-Package CgdataBase.Algorithm -Version 1.9.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CgdataBase.Algorithm" Version="1.9.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CgdataBase.Algorithm" Version="1.9.6" />
<PackageReference Include="CgdataBase.Algorithm" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CgdataBase.Algorithm --version 1.9.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CgdataBase.Algorithm, 1.9.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CgdataBase.Algorithm@1.9.6
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CgdataBase.Algorithm&version=1.9.6
#tool nuget:?package=CgdataBase.Algorithm&version=1.9.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CgdataBase.Algorithm
一组常用的算法/信号处理相关工具类,属于 CgdataBase 解决方案中的基础库之一。
目标框架
net6.0net8.0net10.0
目录结构
CrcHelper:CRC4/5/6/7/8/16/32 计算ConvolutionController:卷积编码(支持自定义约束长度与多项式)ConvolutionHelper:固定(2,1,7)卷积编码(基于环形寄存器)ScrambledRandomController:扰码序列生成与数据加扰NrzHelper:NRZ-L → NRZ-M 码型变换SpectrumCalcHelper:均值、峰值、RMS、峭度与常见窗函数(Hanning/Hamming/Blackman)DoubleEqualityComparer/FloatEqualityComparer:近似相等比较器(适用于测试断言、集合等场景)
快速开始
引用项目
在你的项目中引用:
- 项目引用:
CgdataBase.Algorithm - 依赖:该项目会引用
CgdataBase.Core
CRC
using CgdataBase;
byte[] data = { 0xAA, 0xBB, 0xCC, 0xDD };
byte crc8 = CrcHelper.CRC8(data);
byte[] crc16 = CrcHelper.CRC16_MODBUS(data);
byte[] crc32 = CrcHelper.CRC32(data);
说明:
CRC16_*/CRC32_*返回字节数组,字节序与具体实现一致;如需与其它库对齐,建议用测试向量进行验证。
卷积编码
ConvolutionController(可配置)
using CgdataBase;
var controller = new ConvolutionController(bitSize: 7, g1: 121, g2: 91);
byte[] encoded = controller.Encoding(sourceData);
ConvolutionHelper(固定 (2,1,7))
ConvolutionHelper 使用 IRingList<int> 作为寄存器缓存,需要传入容量为 7 的环形列表(CgdataBase.Core.Controllers.RingList<int>)。
using CgdataBase;
using CgdataBase.Core.Controllers;
var ring = new RingList<int>(7);
byte[] encoded = ConvolutionHelper.Encoding(sourceData, ring, reverse: true);
扰码(加扰/解扰)
using CgdataBase;
var controller = new ScrambledRandomController(initial: 0xFF, polynomial: 0x1D, byteCount: 128);
byte[] data = GetBytes();
controller.ScramblingData(data); // 加扰
controller.ScramblingData(data); // 再执行一次即可还原(同一随机序列下 XOR 往返)
也可以仅生成扰码序列:
byte[] random = ScrambledRandomController.GenerateRandomData(0xFF, 0x1D, 32);
NRZ-L → NRZ-M
using CgdataBase;
byte[] nrzm = NrzHelper.ConvertNrzlToNrzm(nrzl);
频谱/统计指标与窗函数
using CgdataBase;
double mean = SpectrumCalcHelper.Mean(values);
double peak = SpectrumCalcHelper.Peak(values);
double rms = SpectrumCalcHelper.RMS(values);
double kurtosis = SpectrumCalcHelper.Kurtosis(values);
double[] hanning = SpectrumCalcHelper.HanningWindow(1024);
double[] hamming = SpectrumCalcHelper.HammingWindow(1024);
double[] blackman = SpectrumCalcHelper.BlackmanWindow(1024);
边界行为:
Mean(empty)返回NaNRMS(empty)返回0Kurtosis要求数据长度>= 4Window(length<=0)返回空数组;Window(1)返回[1]
测试
本项目对应的测试工程为 CgdataBase.AlgorithmTests(MSTest)。
在解决方案根目录运行:
dotnet test .\CgdataBase.AlgorithmTests\CgdataBase.AlgorithmTests.csproj -c Release
版本与命名空间
- 命名空间:
CgdataBase - 包版本:跟随解决方案版本号(见
CgdataBase.Algorithm.csproj)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- CgdataBase.Core (>= 1.9.6)
-
net6.0
- CgdataBase.Core (>= 1.9.6)
-
net8.0
- CgdataBase.Core (>= 1.9.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.