pypho_lasmod.py 2.89 KB
Newer Older
hm-striegle's avatar
hm-striegle committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  pypho.py
#
#  Copyright 2018 Arne Striegler (arne.striegler@hm.edu)
#
#
#
#
#
# Simulations direct modulated laser source
# Without Chirp
#
########################################################################

import numpy as np
import sys
from pypho_functions import *
from pypho_constants import pypho_constants
cv = pypho_constants();

########################################################################

class pypho_lasmod(object):
    def __init__(self, glova = None, power = None, Df = None, teta = None):

        if glova == None:
            print "ERROR: You must define the global variables"
            sys.exit("PyPho stopped!")

        self.glova     = glova
        self.power     = None
        self.esig     = []
        self.Df         = None
        self.teta     = None

        self.set(power, Df, teta)

########################################################################
    def __call__(self, esig = [], power = None, Df = None, teta = None):

        if len(esig) == 0 :
            print ("Error: pypho_lasmod: No electrical signal defined!")        
            sys.exit("PyPho stopped!")
hm-striegle's avatar
hm-striegle committed
46
        
hm-striegle's avatar
hm-striegle committed
47
        self.set(power, Df, teta)
hm-striegle's avatar
hm-striegle committed
48
       
hm-striegle's avatar
hm-striegle committed
49 50 51
        if type(self.Df) != list:     
            self.Df = [self.Df]  

hm-striegle's avatar
hm-striegle committed
52
        E = [];
hm-striegle's avatar
hm-striegle committed
53
        esig =  esig + 0.0j
hm-striegle's avatar
hm-striegle committed
54
        for Dfi in self.Df:
hm-striegle's avatar
hm-striegle committed
55 56 57 58 59 60 61 62 63 64 65 66
            Etmp = dict()
                        
            esig *= np.sqrt( dbm2w( self.power ) / np.mean(esig) ) 
            omega = np.exp(1j*2.0*np.pi*Dfi*1.0e9*self.glova.timeax)          
            esig *=  omega
            del omega        
            Etmp['E'] = Etmp['E'] = np.zeros((2, self.glova.nos * self.glova.sps)) + 0.0j
            Etmp['E'][0][:] = esig * np.cos(self.teta) 
            Etmp['E'][1][:] = esig * np.sin(self.teta) 
            del esig
            Etmp['Df'] = Dfi
            Etmp['noise'] = np.zeros(self.glova.nos * self.glova.sps) + dbm2w( self.power ) / 10.0**(5.8) / 12.5e9 * self.glova.fres            
hm-striegle's avatar
hm-striegle committed
67
            E.append( Etmp )
hm-striegle's avatar
hm-striegle committed
68
            del Etmp
hm-striegle's avatar
hm-striegle committed
69

hm-striegle's avatar
hm-striegle committed
70
        return E
hm-striegle's avatar
hm-striegle committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95


########################################################################
    def set(self, power = None, Df = None, teta = None):
        """Set  properties"""
      
        if power == None and self.power == None:
            print ("WARNING: pypho_lasmod: No mean power value specified, so I use P = 0dBm")
            self.power = 0
        elif power != None:
            self.power = power


        if teta == None and self.teta == None:
            print ("WARNING: pypho_lasmod: No polarisation angle specified, so I use teta = 0")
            self.teta = 0
        elif teta != None:
            self.teta = teta


        if Df == None and self.Df == None:
            print ("WARNING: pypho_cwlaser: No variation from center frequency specified, so I use Df = 0")
            self.Df = np.array([0])
        elif Df != None:
            self.Df = Df