WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
SimpleComAnalysisModel.h
/******************************************************************************
* Copyright (c) ATTX INC 2025. All Rights Reserved. 
*
* This software and associated documentation (the "Software") are the 
* proprietary and confidential information of ATTX, INC. The Software is 
* furnished under a license agreement between ATTX and the user organization 
* and may be used or copied only in accordance with the terms of the agreement.
* Refer to 'license/attx_license.adoc' for standard license terms.
*
* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION 
* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or 
* transmitted in any form or by any means, for any purpose, without the express 
* written permission of ATTX, INC.
******************************************************************************/

/*
Communications Data Model header file

Author: Daniel Krobath
*/
/*
Metadata for MS GUI:
imdata = {"displayname" : "Simple Communication Analysis Model",
          "exclude" : False,
          "category" : "Assemblies"
}
aliases = {"frequency" : "Frequency (Hz)",
           "bandwidth" : "Bandwidth (Hz)",
           "bit_rate" : "Bit Rate (bps)",
           "power_TX" : "Transmit Power (W)",
           "gain_TX" : "Transmit Gain (dBi)",
           "loss_TX" : "Transmit Loss (dB)",
           "gain_RX" : "Receive Gain (dBi)",
           "loss_RX" : "Receive Loss (dB)",
           "noise_temperature" : "System Noise Temperature (K)",
           "cross_pol_loss" : "Cross Polarization Loss (dB)",
           "ebno_required" : "Eb/N0 Required (dB)",
           "range" : "Range (meters)",
           "masked" : "Masked (false = visible)",
           "free_space_path_loss" : "EXCLUDE",
           "eff_isotropic_radiated_pwr" : "EXCLUDE",
           "power_RX" : "EXCLUDE",
           "system_noise_figure" : "EXCLUDE",
           "signal_to_noise_ratio" : "Signal to Noise Ratio (dB)",
           "ebno_received" : "Eb/N0 Received (dB)",
           "link_margin" : "Link Margin (dB)",
}
*/

#ifndef MODELS_COMMUNICATIONS_SIMPLE_COM_ANALYSIS_MODEL_H
#define MODELS_COMMUNICATIONS_SIMPLE_COM_ANALYSIS_MODEL_H

#include <string>
#include <vector>
#include <cmath>

#include "simulation/Model.h"

namespace warptwin {

    /**
     * @brief   Simulated model of spacecraft communications including losses and gains with comm links
     * 
     * This model is used to calculate and manage data related to communications
     * systems in a simulation. It provides a structure for handling various
     * parameters, inputs, and outputs related to communications, such as
     * the losses and gains associated with any communication link.
     * 
     * IMPORTANT: Though loss is generally expressed as a negative gain, this model assumes that loses
     * are positive and will subtract accordingly. For example, suppose your receiver system has poor
     * circuitry and you expect the power received to decrease by half. This would be a gain of -3 dB,
     * however this model expects the user to input a loss of positive 3 dB. In general, loss = -gain.
     * 
     * Author: Daniel Krobath
     * Email:  daniel.krobath@attx.tech
     * Revised: James Tabony <james.tabony@attx.tech>
    */
    MODEL(SimpleComAnalysisModel)
    public:
        // Model params
        //         NAME                             TYPE                        DEFAULT VALUE
        START_PARAMS
            /** The transmitter carrier frequency in hertz (Hz) */
            SIGNAL(frequency,                       double,                     0.0)
            /** The bandwidth of transmission (Hz) */
            SIGNAL(bandwidth,                       double,                     0.0)
            /** The bit rate in bits per second (bps) */
            SIGNAL(bit_rate,                        double,                     0.0)
            /** The transmit power in Watts (W) */
            SIGNAL(power_TX,                        double,                     0.0)
            /** Return loss of the transmitter, this value describes ratio of power
             *  that is reflected back into the system. Should be input as positive
             *  but is normally negative. (dB) */
            SIGNAL(return_loss,                     double,                     0.0)
            /** The transmit antenna gain in decibels relative to isotropic (dBi) */
            SIGNAL(gain_TX,                         double,                     0.0)
            /** The total transmit system loss in decibels (dB). This is the accumulation
             *  of transmitter pointing loss, and transmitter circuit loss. Inputting zero
             *  assumes that there is no return loss (despite this actually being 100% return
             *  loss). */
            SIGNAL(loss_TX,                         double,                     0.0)
            /** The receive antenna gain in decibels relative to isotropic (dBi) */
            SIGNAL(gain_RX,                         double,                     0.0)
            /** The noise temperature in Kelvin (K). This value is realted to the
             *  system noise density by Boltzmann*noise_temp and system noise power
             *  by the equation band_width*noise_density. */
            SIGNAL(noise_temperature,               double,                     0.0)
            /** The total receive system loss in decibels (dB). This is the accumulation
             *  of receiver side loss such as pointing loss, radome loss, polarization loss,
             *  and atmospheric loss. */
            SIGNAL(loss_RX,                         double,                     0.0)
            /** The cross polarization loss in decibels (dB). General rule of thumb,
             *  if both RX and TX have same-hand circular or linear (0dB), if there
             *  is a circular to linear match (3dB), but a right vs left circular
             *  mismatch can result in 20 to 30 dB loss. */
            SIGNAL(cross_pol_loss,                  double,                     0.0)
            /** The energy per bit to noise ratio required in dB. Based on various
             *  modulation schemes for a desired bit error rate. For BPSK an Eb/N0
             *  required of about 11 allows for a bit error rate around 1e-6. */
            SIGNAL(ebno_required,                   double,                     0.0)
        END_PARAMS

        // Model inputs
        //         NAME                             TYPE                        DEFAULT VALUE
        START_INPUTS
            /** This is the range of the input object to the frame in meters. Will be zero if masked.*/
            SIGNAL(range,                           double,                     0.0)
            /** This is the mask flag for the ground station. True for masked, False for visible */
            SIGNAL(masked,                          bool,                       true)
        END_INPUTS

        // Model outputs
        //         NAME                             TYPE                        DEFAULT VALUE
        START_OUTPUTS
            /** The free space path loss in decibels (FSPL) (dB) */
            SIGNAL(free_space_path_loss,            double,                     0.0)
            /** The effective isotropic radiated power (EIRP) in decibel-milliWatts (dBm) */
            SIGNAL(eff_isotropic_radiated_pwr,      double,                     0.0)
            /** The receive power in decibel-milliWatts (dBm) */
            SIGNAL(power_RX,                        double,                     0.0)
            /** The system noise figure (NF) in decibel-milliWatts/Hz (dBm/Hz) */
            SIGNAL(system_noise_figure,             double,                     0.0)
            /** The signal-to-noise density ratio (SNR) in decibel (dB) */
            SIGNAL(signal_to_noise_ratio,           double,                     0.0)
            /** The energy per bit to noise ratio in in decibels (dB) */
            SIGNAL(ebno_received,                   double,                     0.0)
            /** The link margin in decibels (dB) */
            SIGNAL(link_margin,                     double,                     0.0)
        END_OUTPUTS

        /// @brief Compute the receiver gain based based on system parameters
        /// @param antenna_diameter The receive antenna diameter in meters
        /// @param antenna_efficiency The receive antenna efficiency as a percentage (0 to 100)
        /// @param frequency The transmitter frequency in hertz (Hz)
        /// @return The receive antenna gain in decibels relative to isotropic (dBi) - Direct param of model
        double getGainRx(double antenna_diameter, double antenna_efficiency, double frequency) const;

    protected:
        int16 start() override;
        int16 execute() override;

        /// @brief Function to compute the free space path loss
        /// @param range Distance between TX and RX in meters
        /// @param frequency Frequency of the comminucation in Hz
        /// @return Free space path loss in dB
        double _computeFreeSpacePathLoss(double range, double frequency) const;

        /// @brief Power leaving the transmitter in decibel-milliWats
        double _power_TX_dBm;

        /// @brief Power reflected back into the system in Watts
        double _power_reflected_W;

    };
}

#endif