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" />
                    
Directory.Packages.props
<PackageReference Include="CgdataBase.Algorithm" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=CgdataBase.Algorithm&version=1.9.6
                    
Install as a Cake Tool

CgdataBase.Algorithm

一组常用的算法/信号处理相关工具类,属于 CgdataBase 解决方案中的基础库之一。

目标框架

  • net6.0
  • net8.0
  • net10.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) 返回 NaN
  • RMS(empty) 返回 0
  • Kurtosis 要求数据长度 >= 4
  • Window(length<=0) 返回空数组;Window(1) 返回 [1]

测试

本项目对应的测试工程为 CgdataBase.AlgorithmTests(MSTest)。

在解决方案根目录运行:

dotnet test .\CgdataBase.AlgorithmTests\CgdataBase.AlgorithmTests.csproj -c Release

版本与命名空间

  • 命名空间:CgdataBase
  • 包版本:跟随解决方案版本号(见 CgdataBase.Algorithm.csproj
Product 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.9.6 83 3/20/2026
1.6.23 226 12/31/2024
1.5.0 345 11/17/2023
1.4.23 208 11/15/2023
1.4.19 227 9/16/2023
1.4.18 232 9/1/2023