# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
## imports ##
import numpy as np
import matplotlib.pyplot as plt
import scipy
import os
####

## globals ##

nSample=8192
tSample=5e-9
frequency=np.fft.fftshift(np.fft.fftfreq(nSample,1/tSample))
samples=np.arange(0,nSample,1)
time=samples*tSample
noiseVar=1
fLO=25e9
doPlots=True

##


# +
## define signal ##

signalFreqs=np.array([30e6,10e6,50e6])
signalPhases=np.array([.0,0.1,-0.4])
signalAmps=[1,1,1]
signalTime=np.zeros(time.size,dtype=np.complex128)
for i in range(signalFreqs.size):
    signalTime+=signalAmps[i]*np.exp(-1j*2*np.pi*(signalFreqs[i]*time-signalPhases[i]))


if doPlots:
    fig,axs=plt.subplots()
    axs.plot(time,signalTime.real,'r')
    axs.set_xlim(time[0],time[200])
###

## add noise ##

noise=np.random.multivariate_normal(mean=[0,0],cov=np.eye(2)*noiseVar/2,size=nSample)
noise=noise[:,0]+1j*noise[:,1]

noisePower=np.mean(abs(noise)**2)
signalPower=np.mean(abs(signalTime)**2)
snr=signalPower/noisePower

print('SNR is: ',snr)
## fft ##

signalFreq=np.fft.fftshift(np.fft.fft(signalTime))

if doPlots:
    fig,axs=plt.subplots()
    axs.plot(frequency,signalFreq.imag/nSample,'r')
    axs.plot(frequency,signalFreq.real/nSample,'b')
    #axs.set_xlim(time[0],time[200])
    
    fig,axs=plt.subplots()
    axs.plot(frequency,abs(signalFreq/nSample),'r')
    #axs.set_xlim(time[0],time[200])
    
####

## calculate signal power ##
# -



StarcoderdataJupyterScriptsDedupFiltered