Ejemplo n.º 1
0
def GetHamK3(N=1000):
    """GetHamK3: Get modulation and demodulation functions for the coding scheme
		HamK3 - Sq16Sq50.	
	Args:
		N (int): N
	Returns:
		modFs: NxK matrix
		demodFs: NxK matrix
	"""
    #### Set some parameters
    K = 3
    maxInstantPowerFactor = 6.
    dt = float(TauDefault) / float(N)
    #### Allocate modulation and demodulation vectors
    modFs = np.zeros((N, K))
    demodFs = np.zeros((N, K))
    #### Prepare modulation functions
    modDuty = 1. / maxInstantPowerFactor
    for i in range(0, K):
        modFs[0:math.floor(modDuty * N),
              i] = maxInstantPowerFactor * AveragePowerDefault
    #### Prepare demodulation functions
    ## Make shape of function
    demodDuty = 1. / 2.
    for i in range(0, K):
        demodFs[0:math.floor(demodDuty * N), i] = 1.
    ## Apply necessary phase shift
    shifts = [0, (1. / 3.) * N, (2. / 3.) * N]
    demodFs = Utils.ApplyKPhaseShifts(demodFs, shifts)

    return (modFs, demodFs)
Ejemplo n.º 2
0
def GetSquare(N=1000, K=3, tau=TauDefault, totalEnergy=TotalEnergyDefault):
    """GetCosCos: Get modulation and demodulation functions for sinusoid coding scheme. The shift
	between each demod function is 2*pi/k where k can be [3,4,5...]
	
	Args:
		N (int): N - Number of Samples
		k (int): k - Number of coding function
		freqFactor (float): Multiplicative factor to the fundamental frequency we want to use.

	Returns:
		np.array: modFs 
		np.array: demodFs 
	"""
    #### Allocate modulation and demodulation vectors
    modFs = np.zeros((N, K))
    demodFs = np.zeros((N, K))
    t = np.linspace(0, 2 * np.pi, N)
    dt = float(tau) / float(N)
    #### Declare base square function
    squareF = (np.cos(t)) >= 0
    #### Set each mod/demod pair to its base function and scale modulations
    for i in range(0, K):
        ## No need to apply phase shift to modF
        modFs[:, i] = squareF
        ## Scale  modF so that area matches the total energy
        modFs[:, i] = Utils.ScaleAreaUnderCurve(modFs[:, i],
                                                dx=dt,
                                                desiredArea=totalEnergy)
        ## Apply phase shift to demodF
        demodFs[:, i] = squareF
    #### Apply phase shifts to demodF
    shifts = np.arange(0, K) * (float(N) / float(K))
    demodFs = Utils.ApplyKPhaseShifts(demodFs, shifts)
    #### Return coding scheme
    return (modFs, demodFs)
Ejemplo n.º 3
0
def GetSqSq(N=1000, K=4):
    """GetSqSq: Get modulation and demodulation functions for square coding scheme. The shift
	between each demod function is 2*pi/k where k can be [3,4,5...]. 
	
	Args:
	    N (int): Number of discrete points in the scheme
	    k (int): Number of mod/demod function pairs
	    0.5
	
	Returns:
	    np.array: modFs 
	    np.array: demodFs 
	"""
    #### Allocate modulation and demodulation vectors
    modFs = np.zeros((N, K))
    demodFs = np.zeros((N, K))
    t = np.linspace(0, 2 * np.pi, N)
    dt = float(TauDefault) / float(N)
    #### Declare base sin function
    sqF = (0.5 * signal.square(t, duty=0.5)) + 0.5
    #### Set each mod/demod pair to its base function and scale modulations
    for i in range(0, K):
        ## No need to apply phase shift to modF
        modFs[:, i] = sqF
        ## Scale  modF so that area matches the total energy
        modFs[:, i] = Utils.ScaleAreaUnderCurve(modFs[:, i],
                                                dx=dt,
                                                desiredArea=TotalEnergyDefault)
        ## Apply phase shift to demodF
        demodFs[:, i] = sqF
    #### Apply phase shifts to demodF
    shifts = np.arange(0, K) * (float(N) / float(K))
    demodFs = Utils.ApplyKPhaseShifts(demodFs, shifts)
    #### Return coding scheme
    return (modFs, demodFs)
Ejemplo n.º 4
0
def GetHamK5(N=1000):
    """GetHamK5: Get modulation and demodulation functions for the coding scheme HamK5.	
	Args:
		N (int): N
	Returns:
		modFs: NxK matrix
		demodFs: NxK matrix
	"""
    #### Set some parameters
    K = 5
    maxInstantPowerFactor = 30.
    dt = float(TauDefault) / float(N)
    #### Allocate modulation and demodulation vectors
    modFs = np.zeros((N, K))
    demodFs = np.zeros((N, K))
    #### Prepare modulation functions
    modDuty = 1. / maxInstantPowerFactor
    for i in range(0, K):
        modFs[0:math.floor(modDuty * N),
              i] = maxInstantPowerFactor * AveragePowerDefault
    #### Prepare demodulation functions
    ## Make shape of function
    demodDuty1 = np.array([15. / 30., 15. / 30.])
    shift1 = 15. / 30.
    demodDuty2 = np.array([15. / 30., 15. / 30.])
    shift2 = 7. / 30.
    demodDuty3 = np.array([8. / 30., 8. / 30., 7. / 30., 7. / 30.])
    shift3 = 3. / 30.
    demodDuty4 = np.array([
        4. / 30., 4. / 30., 4. / 30., 4. / 30., 3. / 30., 4. / 30., 4. / 30.,
        3. / 30.
    ])
    shift4 = 1. / 30.
    demodDuty5 = np.array([
        2. / 30., 2. / 30., 2. / 30., 2. / 30., 2. / 30., 2. / 30., 2. / 30.,
        3. / 30., 2. / 30., 2. / 30., 2. / 30., 2. / 30., 3. / 30., 2. / 30
    ])
    shift5 = 4. / 30.
    shifts = [shift1 * N, shift2 * N, shift3 * N, shift4 * N, shift5 * N]
    demodDutys = [demodDuty1, demodDuty2, demodDuty3, demodDuty4, demodDuty5]
    for i in range(0, K):
        demodDuty = demodDutys[i]
        startIndeces = np.floor((np.cumsum(demodDuty) - demodDuty) * N)
        endIndeces = startIndeces + np.floor(demodDuty * N) - 1
        for j in range(len(demodDuty)):
            if ((j % 2) == 0):
                demodFs[int(startIndeces[j]):int(endIndeces[j]), i] = 1.

    ## Apply necessary phase shift
    demodFs = Utils.ApplyKPhaseShifts(demodFs, shifts)

    return (modFs, demodFs)