2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 13:33:13 +00:00
This commit is contained in:
2022-10-16 22:16:00 +03:00
parent 8e17a5b677
commit 6537913b11
14 changed files with 516 additions and 1 deletions

View File

@ -0,0 +1,69 @@
using Esiur.Analysis.Statistics;
using Esiur.Analysis.Units;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace Esiur.Analysis.Signals
{
public static class Capacity
{
public struct CSI
{
public double SNR;
public Probability Probability;
public CSI(double snr, double probability)
{
SNR = snr;
Probability = probability;
}
}
public struct OutageCapacity
{
public BitRate Capacity;
public double MinSNR;
public Probability Outage;
public double Bandwidth;
public OutageCapacity(Probability outage, double minSNR, double bandwidth)
{
MinSNR = minSNR;
Outage = outage;
Bandwidth = bandwidth;
Capacity = (1 - Outage) * bandwidth * Math.Log(1 + minSNR, 2);
}
public override string ToString() => $" {MinSNR.ToString("F")} <{Outage}> => {Capacity}";
}
public static double Compute(double bandwidth, double snr)
=> bandwidth * Math.Log(1 + snr, 2);
public static double ComputeErgodic(double bandwidth, CSI[] receiverCSI)
{
return bandwidth * receiverCSI.Sum(x => Math.Log(1 + x.SNR, 2) * x.Probability);
}
public static OutageCapacity[] ComputeOutage(double bandwidth, CSI[] receiverCSI)
{
var sorted = receiverCSI.OrderBy(x => x.SNR);
var rt = sorted.Select(x => {
var pOut = receiverCSI.Where(csi => csi.SNR < x.SNR).Sum(x => x.Probability);
return new OutageCapacity()
{
Outage = pOut,
MinSNR = x.SNR,
Capacity = (1 - pOut) * bandwidth * Math.Log(1 + x.SNR, 2)
};
});
return rt.ToArray();
}
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Analysis.Signals
{
public static class DSP
{
public static double[] ConvolveMany(params double[][] signals)
{
var rt = signals[0];
for (var i = 1; i < signals.Length; i++)
rt = rt.Convolve(signals[i]);
return rt;
}
public static double[] Convolve(this double[] signal, double[] filter)
{
var length = signal.Length + filter.Length - 1;
var rt = new double[length];
//for (var i = 0; i < signal.Length; i++)
// for (var j = 0; j < filter.Length; j++)
// rt[i + j] += signal[i] * filter[j];
for (var i = 0; i < length; i++)
{
for (var j = 0; j < signal.Length && i - j >= 0 && i - j < filter.Length; j++)
{
rt[i] = signal[j] * filter[i - j];
}
}
return rt;
}
public static double[] CrossCorrelate(this double[] signal, double[] filter)
{
var length = signal.Length + filter.Length - 1;
var rt = new double[length];
for (var i = 0; i < length; i++)
{
for (var j = 0; j < signal.Length && j + i < filter.Length; j++)
{
rt[i] = signal[j] * filter[i + j];
}
}
return rt;
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Analysis.Signals
{
public static class Propagation
{
public static readonly double LightSpeed = 2.99792458e8;
public static double FindReceivedPower(double transmittedPower, double distance,
double transmitterGain, double receiverGain, double pathLoss)
{
throw new NotImplementedException();
}
}
}