Processing math: 100%

Friday, September 27, 2013

rf synthesizer

This script is a wrapper around the serial interface to the MixNV rf synthesizer from Windfreak. It is a lovely little device.
# Controlling the MixNV (Windfreak Technologies) rf synthesizer
# Amar Vutha
# version 1
import serial
import numpy as np
import time
usbPort = "/dev/ttyACM0"
sleepTime = 0.01
class Synth:
def __init__(self,portname):
self.usbStream = serial.Serial(portname,timeout=1)
def status(self):
#time.sleep(sleepTime)
self.usbStream.write("f?")
print "Frequency: ",self.usbStream.readline()[:-2],"MHz"
self.usbStream.write("a?")
print "Amplitude: ",self.usbStream.readline()
def frequency(self,f):
self.usbStream.write("f"+`f`)
time.sleep(sleepTime)
#self.usbStream.write("f?")
#print self.usbStream.readline()[:-2]
def amplitude(self,n):
self.usbStream.write("a"+`n`)
time.sleep(sleepTime)
#self.usbStream.write("a?")
#print self.usbStream.readline()
def scan(self,start,stop,numsteps):
try:
while True:
for f in np.linspace(start,stop,numsteps):
self.frequency(f)
time.sleep(sleepTime)
except KeyboardInterrupt: return
view raw mixnv.py hosted with ❤ by GitHub

Friday, September 20, 2013

Talking Python

Python can speak back easily, thanks to the espeak package. Just call it from the command line using the subprocess module.

import os, subprocess
os.chdir("c:/Program Files (x86)/eSpeak/command_line/")
speakString = "This parrot is no more. It has ceased to be. It's expired and gone to meet its maker. This is a late parrot. It's a stiff. Bereft of life, it rests in peace. If you hadn't nailed it to the perch, it would be pushing up the daisies. It's rung down the curtain and joined the choir invisible. This is an ex-parrot."
subprocess.call(["espeak","-ven+f5",`speakString`])
view raw speakUp.py hosted with ❤ by GitHub

Tuesday, September 3, 2013

Bloch sphere utility

This is a generic Bloch sphere template. Get precessing!

 
# Bloch sphere
# Amar Vutha, 2013-08-31
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
# Basic Bloch sphere
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
phi = np.linspace(0, 2 * np.pi, 40)
theta = np.linspace(0, np.pi, 60)
x = 1 * np.outer(np.cos(phi), np.sin(theta))
y = 1 * np.outer(np.sin(phi), np.sin(theta))
z = 1 * np.outer(np.ones(np.size(phi)), np.cos(theta))
ax.plot_wireframe(x, y, z, rstride=10, cstride=30, color='gray', alpha=0.5)
ax.scatter([0],[0],[0],color='k',marker=r"\otimes",alpha=0.5)
# Annotate points
ax.text(0,0,1.2,r"|0\rangle")
ax.text(0,0,-1.2,r"|1\rangle")
ax.text(1.2,0,0,r"x")
ax.text(0,1.2,0,r"y")
# Set camera angle
ax.elev = 30
ax.azim = 35
# Plot points
theta0, phi0 = np.pi/2.3, 0
ax.scatter([np.sin(theta0)*np.cos(phi0)],[np.sin(theta0)*np.sin(phi0)],[np.cos(theta0)],'bo')
plt.show()
view raw blochSphere.py hosted with ❤ by GitHub