mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
LFSR
This commit is contained in:
parent
68d0ca1873
commit
9775b2a878
@ -1,5 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using Esiur.Analysis.DSP;
|
||||
using Esiur.Analysis.Signals.Codes;
|
||||
|
||||
namespace Esiur.Analysis.Test
|
||||
{
|
||||
@ -18,6 +19,9 @@ namespace Esiur.Analysis.Test
|
||||
var cor = signalA.CrossCorrelation(signalB, true);
|
||||
Debug.WriteLine(cor);
|
||||
|
||||
var seq = Generators.GenerateSequence(1, 7);
|
||||
|
||||
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Esiur.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Analysis.Signals.Codes
|
||||
@ -8,6 +9,57 @@ namespace Esiur.Analysis.Signals.Codes
|
||||
public static class Generators
|
||||
{
|
||||
|
||||
public static void SetBit(ref this int target, int index, bool value)
|
||||
{
|
||||
if (value)
|
||||
target |= 0x1 << index;
|
||||
else if ((target & (0x1 << index)) != 0)
|
||||
target ^= 0x1 << index;
|
||||
}
|
||||
|
||||
public static double[] GenerateSequence(int initialValue, uint octalPolynomialCoefficients)
|
||||
{
|
||||
// convert octal to uint
|
||||
var bits = Convert.ToUInt32(octalPolynomialCoefficients.ToString(), 8);
|
||||
var taps = new List<uint>();
|
||||
|
||||
// find maximum exponent
|
||||
var maxExponent = 0;
|
||||
for (var i = 31; i >= 0; i--)
|
||||
{
|
||||
var test = (uint)0x1 << i;
|
||||
if ((bits & test) != 0)
|
||||
{
|
||||
taps.Add(test);
|
||||
maxExponent = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var length = (int)(Math.Pow(2, maxExponent) - 1);
|
||||
|
||||
var rt = new double[length];
|
||||
|
||||
var state = initialValue;
|
||||
|
||||
for(var i = 0; i < length; i++)
|
||||
{
|
||||
//rt[i] = (state & 0x1) == 1 ? 1 : -1;
|
||||
|
||||
var b = 0;
|
||||
for (var j = 0; j < taps.Count; j++)
|
||||
b = (b + ((taps[j] & state) > 0 ? 1 : 0)) % 2;
|
||||
|
||||
state >>= 1;
|
||||
|
||||
state.SetBit(maxExponent, b > 0);
|
||||
|
||||
rt[i] = b == 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
//public double[][] GenerateMaximumLengthSequence(uint octalPolynomialCoefficients)
|
||||
//{
|
||||
// // convert octal to uint
|
||||
@ -38,7 +90,7 @@ namespace Esiur.Analysis.Signals.Codes
|
||||
|
||||
// while (true)
|
||||
// {
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// var rt = new double[length][];
|
||||
|
Loading…
x
Reference in New Issue
Block a user