from __future__ import division
from math import pi, sqrt, log10
#Given
Rf=0.5 #ohm
Rr=1 #ohm
Ls=0.3e-9 #H
Cj=0.1e-12 #F
f=3.18e9 #Hz
Z0=50 #ohm
Zf=Rf+(1J*round(2*pi*f*Ls))
Zr=Rr+(1J*(round(2*pi*f*Ls)-(1/(2*pi*f*Cj))))
#Series Configuration
print 'Series Configuration'
#Insertion Loss
x=(2*Z0)/((2*Z0)+Zf)
x1=sqrt(((x.real))**2+((x.imag))**2)
IN=-20*log10(x1)
print 'Insertion Loss: %0.3f'%IN,'dB'
#Isolation Loss
y=(2*Z0)/((2*Z0)+Zr)
y1=sqrt(((y.real))**2+((y.imag))**2)
IS=-20*log10(y1)
print 'Isolation Loss: %0.3f'%IS,'dB'
#Shunt Configuration
print 'Shunt Configuration'
#Insertion Loss
a=(2*Zr)/((2*Zr)+Z0)
a1=sqrt(((a.real))**2+((a.imag))**2)
INs=-20*log10(a1)
print 'Insertion Loss: %0.3f'%INs,'dB'
#Isolation Loss
b=(2*Zf)/((2*Zf)+Z0)
b1=sqrt(((b.real))**2+((b.imag))**2)
ISs=-20*log10(b1)
print 'Isolation Loss: %0.3f'%ISs,'dB'
#Answer for Series configuration insertion loss is 0.058 but is given as 0.58db
#Given
Rf=1 #ohm
Rr=4 #ohm
Ls=0.3e-9 #H
Cj=0.1e-12 #F
f=3.18e9 #Hz
Z0=50 #ohm
Zf=Rf+(1J*round(2*pi*f*Ls))
Zr=Rr+(1J*(round(2*pi*f*Ls)-(1/(2*pi*f*Cj))))
#Series Configuration
print 'Series Configuration'
#Insertion Loss
x=(2*Z0)/((2*Z0)+Zf)
x1=sqrt(((x.real))**2+((x.imag))**2)
IN=-20*log10(x1)
print 'Insertion Loss: %0.3f'%IN,'dB'
#Isolation Loss
y=(2*Z0)/((2*Z0)+Zr)
y1=sqrt(((y.real))**2+((y.imag))**2)
IS=-20*log10(y1)
print 'Isolation Loss: %0.3f'%IS,'dB'
#Shunt Configuration
print 'Shunt Configuration'
#Insertion Loss
a=(2*Zr)/((2*Zr)+Z0)
a1=sqrt(((a.real))**2+((a.imag))**2)
INs=-20*log10(a1)
print 'Insertion Loss: %0.3f'%INs,'dB'
#Isolation Loss
b=(2*Zf)/((2*Zf)+Z0)
b1=sqrt(((b.real))**2+((b.imag))**2)
ISs=-20*log10(b1)
print 'Isolation Loss: %0.3f'%ISs,'dB'
#Given
Vbd=1000 #V
f=30e9 #Hz
E=3e5 #V/cm
Cj=0.3e-12 #F
er=11.8
e0=8.854e-12
W=Vbd/E
Wpi=W/100 #mu
#Total series resistance
R=1/(2*pi*f*Cj)
print 'Total series resistance: %0.3f'%R, 'ohms'
#Junction Area
A=(Cj*Wpi)/(e0*er)
print 'Junction Area: %0.3f'%(A*10000), 'cm2'
#Given
MQ=10
M=0.4
r=20
Td=300 #K
T=290 #K
x=(MQ*MQ)/r
#Power Gain
Ap=(r*x)/((1+sqrt(1+x))**2)
Apdb=10*log10(Ap)
print 'Power gain: %0.3f'%Apdb,'dB'
#Noise figure
z=(Td/T)/sqrt(1+((MQ*MQ)/r))
F=1+z
Fdb=10*log10(F)
print 'Nosie figure: %0.3f'%F,'dB'
#Bandwidth
BW=2*M*sqrt(r)
print 'Bandwidth: %0.3f'%BW
#Given
MQ=10
r=10
x=(MQ*MQ)/r
#Gain
Ap=(r*x)/((1+sqrt(1+x))**2)
Apdb=10*log10(Ap)
print 'Gain: %0.3f'%Apdb,'dB'
#Given
Rs=1 #ohm
ws=5e9 #Hz
M=0.25
C0=2e-12 #F
#(i) Effective Q
Q=1/(Rs*ws*C0*(1-(M*M)))
print 'Effective Q: %0.3f'%Q
#Given
e=0.0001
s=330
#Charge transfer effciency
n=1-e
#Final charge pulse
#x=P/P0
x=(1-(e*s))
print 'Final charge pulse:' ,x
#Given
Qmax=0.05e-12 #C
f=10e6 #Hz
V=10 #V
n=3
#Power disspated per bit
P=n*f*V*Qmax
print 'Power disspated per bit:',P*10**6, 'muW'
#Given
e0=8.854e-12
er=3.9
d=0.15e-6 #m
e=1.6e-19 #J
Nmax=2.2e16 #m-2
A=0.6e-8 #m
P=0.67e-3 #W
n=3
#(i) Junction capacitance
Ci=(e0*er)/d
#Gate voltage
V=(Nmax*e)/Ci
print 'Gate voltage: %0.3f'%V,'V'
#(ii) Charge stored
Qmax=Nmax*e*A
#Clock frequency
f=P/(n*V*Qmax)
print 'Clock frequency: %0.3f'%(f/10**6),'MHz'
#Given
Qmax=0.06e-12 #C
f=20e6 #Hz
V=10 #V
n=3
#Power disspated per bit
P=n*f*V*Qmax
print 'Power disspated per bit:',P*10**6, 'muW'
#Given
e0=8.854e-12
er=4
d=0.1e-6 #m
si=0.85
e=1.6e-19 #J
Na=1e20
Ci=(e0*er)/d
print 'Junction capacitance: %0.5f'%Ci, 'F/m'
W=sqrt((2*e0*er*si)/(e*Na))
print 'Depletion layer width: %0.3e'%W,'m'