Ejemplo n.º 1
0
 public RealAntennaDigital(RealAntenna orig) : base(orig)
 {
     if (orig is RealAntennaDigital o)
     {
         modulator = new RAModulator(o.modulator);
     }
 }
Ejemplo n.º 2
0
        // Voyager ~= 14 bits (115,200 down to 10 bps)
        // NEAR:  5 bits (1.1kbps - 26.5kbps)
        // MRO: Symbol rates (80 - 6000000 s/s) 16 bits  although it actually is lots of different ranges for different encoders.
        // JUNO: Symbol rates 23 - 1.2M   ~= 16 bits
        // Given Bandwidth, DataRate and SpectralEfficiency, compute minimum C/I from Shannon-Hartley.
        // C = B log_2 (1 + SNR), where C=Channel Capacity and SNR is linear.  10*Log10(SNR) to convert to dB.
        // We will substitute C = (DateRate / SpectralEfficiency) to account for non-ideal performance
        // Actually, let's just skip to digital land, let the Encoder specify required Eb/N0, and derive
        // Derive:  Es/N0 as Eb/N0 + 3*bits
        //          bandwidth as a function of the symbol rate and the spectral efficiency.

        public virtual bool Compatible(RAModulator other)
        {
            if (MinSymbolRate > other.SymbolRate)
            {
                return(false);
            }
            if (other.MinSymbolRate > SymbolRate)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        private bool BestPeerModulator(RealAntenna rx, out double modRate, out double codeRate)
        {
            RealAntennaDigital tx = this;

            Antenna.Encoder encoder = Antenna.Encoder.BestMatching(tx.Encoder, rx.Encoder);
            codeRate = encoder.CodingRate;
            modRate  = 0;
            if (!(rx is RealAntennaDigital))
            {
                return(false);
            }
            if (!Compatible(rx))
            {
                return(false);
            }
            if ((tx.Parent is ModuleRealAntenna) && !tx.Parent.CanComm())
            {
                return(false);
            }
            if ((rx.Parent is ModuleRealAntenna) && !rx.Parent.CanComm())
            {
                return(false);
            }

            Vector3     toSource = rx.Position - tx.Position;
            double      distance = toSource.magnitude;
            RAModulator txMod = tx.modulator, rxMod = (rx as RealAntennaDigital).modulator;

            if ((distance < tx.MinimumDistance) || (distance < rx.MinimumDistance))
            {
                return(false);
            }
            if (!txMod.Compatible(rxMod))
            {
                return(false);
            }
            int    maxBits       = Math.Min(txMod.ModulationBits, rxMod.ModulationBits);
            double maxSymbolRate = Math.Min(txMod.SymbolRate, rxMod.SymbolRate);
            double minSymbolRate = Math.Max(txMod.MinSymbolRate, rxMod.MinSymbolRate);

            double RxPower       = Physics.ReceivedPower(tx, rx, distance, tx.Frequency);
            double temp          = Physics.NoiseTemperature(rx, tx.Position);
            double N0            = Physics.NoiseSpectralDensity(temp); // In dBm
            double minEb         = encoder.RequiredEbN0 + N0;          // in dBm
            double maxBitRateLog = RxPower - minEb;                    // in dB*Hz
            double maxBitRate    = RATools.LinearScale(maxBitRateLog);

            /*
             * Vessel tv = (tx.ParentNode as RACommNode).ParentVessel;
             * Vessel rv = (rx.ParentNode as RACommNode).ParentVessel;
             * if (tv != null && rv != null)
             * {
             *  string debugStr = $"{ModTag} {tx} to {rx} RxP {RxPower:F2} vs temp {temp:F2}. NSD {N0:F1}, ReqEb/N0 {encoder.RequiredEbN0:F1} -> minEb {minEb:F1} gives maxRate {RATools.PrettyPrint(maxBitRate)}bps vs symbol rates {RATools.PrettyPrint(minSymbolRate)}Sps-{RATools.PrettyPrint(maxSymbolRate)}Sps";
             *  Debug.Log(debugStr);
             * }
             */
            // We cannot slow our modulation enough to achieve the required Eb/N0, so fail.
            if (maxBitRate < minSymbolRate)
            {
                return(false);
            }
            double targetRate;
            int    negotiatedBits;

            if (maxBitRate <= maxSymbolRate)
            {
                // The required Eb/N0 occurs at a lower symbol rate than we are capable of at 1 bit/sec/Hz.
                // Step down the symbol rate and modulate at 1 bit/sec/Hz (BPSK).
                // (What if the modulator only supports schemes with >1 bits/symbol?)
                // (Then our minimum EbN0 is an underestimate.)
                float  ratio = Convert.ToSingle(maxBitRate / maxSymbolRate);
                double log2  = Math.Floor(Mathf.Log(ratio, 2));
                targetRate     = maxSymbolRate * Math.Pow(2, log2);
                negotiatedBits = 1;
                //debugStr += $" Selected rate {RATools.PrettyPrint(targetRate)}bps (MaxSymbolRate * log2 {log2})";
            }
            else
            {
                // We need to go to SNR here and rely a bit more on Shannon-Hartley
                double Noise  = N0 + RATools.LogScale(maxSymbolRate);
                double CI     = RxPower - Noise;
                double margin = CI - encoder.RequiredEbN0;
                targetRate     = maxSymbolRate;
                negotiatedBits = Math.Min(maxBits, Convert.ToInt32(1 + Math.Floor(margin / 3)));
                //debugStr += $" Noise {Noise:F2} CI {CI:F2} margin {margin:F1}";
            }
            modRate = targetRate * negotiatedBits;
            //Debug.LogFormat(debugStr);
            return(true);

            // Energy/bit (Eb) = Received Power / datarate
            // N0 = Noise Spectral Density = K*T
            // Noise = N0 * BW
            // SNR = RxPower / Noise = RxPower / (N0 * BW) = Eb*datarate / N0*BW  = (Eb/N0) * (datarate/BW)
            // I < B * log(1 + S/N)   where I = information rate, B=Bandwidth, S=Total Power, N=Total Noise Power = N0*B
            //
            // Es/N0 = (Total Power / Symbol Rate) / N0
            // = Eb/N0 * log(modulation order)
        }
Ejemplo n.º 4
0
 public RealAntennaDigital(string name) : base(name)
 {
     modulator = new RAModulator(this);
 }
Ejemplo n.º 5
0
 public void Copy(RAModulator orig)
 {
     ModulationBits = orig.ModulationBits;
 }
Ejemplo n.º 6
0
 public RAModulator(RAModulator orig) : this(orig.Parent, orig.ModulationBits)
 {
 }
Ejemplo n.º 7
0
 public void Copy(RAModulator orig)
 {
     SymbolRate     = orig.SymbolRate;
     ModulationBits = orig.ModulationBits;
     TechLevel      = orig.TechLevel;
 }
Ejemplo n.º 8
0
 public RAModulator(RAModulator orig) : this(orig.SymbolRate, orig.ModulationBits, orig.TechLevel)
 {
 }