Skip to content

Instantly share code, notes, and snippets.

@amarvutha
amarvutha / twiddle-v7.py
Last active December 16, 2015 05:19
Microwave match tuner, with interactive Smith chart plot
# Interactive tuner for broadband coax-waveguide launcher
# Analytic formulae from Slater, / Microwave Transmission /
# Amar, version 7, 2013-04-09
# Changes:
# v2: S-parameters and Smith plot
# v3: polar smith plot
# v4: S and T matrices to get at S12 phase, objectized circuit description. Reverted to cartesian smith plot.
# v5: double launcher configuration, freed up 'a' as parameter
# v6: cleaned up code, parameters are general and swappable now, plotting and tuning is modular
# v7: phase and amplitude sensitivity plots
@amarvutha
amarvutha / eratosthenes.py
Last active December 17, 2015 14:59
Prime testing
def test2(x):
""" Sieve of Eratosthenes """
p = []
mask = range(2,x-1)
while len(mask)>0:
p.append(mask[0])
del mask[::p[-1]]
return p
@amarvutha
amarvutha / prime_density.py
Last active December 17, 2015 14:59
Calculate the density of prime numbers, using a couple of different methods, and compare them to "measured" values
import pylab as plt
import numpy as np
def primes(x):
p = []
mask = range(2,x-1)
while len(mask)>0:
p.append(mask[0])
del mask[::p[-1]]
@amarvutha
amarvutha / zeta.py
Last active December 21, 2015 15:39
Even-valued zeta functions evaluated using Parseval's theorem
# Evaluating zeta functions using Parseval sums
# Amar
# version 1, Aug 2013
from sympy import *
from sympy import init_printing
init_printing()
n = symbols('n',integer=True)
s = symbols('s',rational=True)
@amarvutha
amarvutha / camera.py
Last active December 21, 2015 15:59
# Display webcam image, plus plasma diagnostics
# version 2, 2013-09-25
# Amar
# Changelog:
# v2: Very slight modification of http://matplotlib.org/examples/animation/dynamic_image.html
import numpy as np
import cv2
import time
import matplotlib.animation as animation
@amarvutha
amarvutha / signalFilter.py
Created August 31, 2013 17:28
Signal filtering utility
# Filtering utilities
import numpy as np
from numpy import pi
from numpy import fft
from scipy import signal
import scipy.signal as sig
import pylab as plt
#### Functions #################
@amarvutha
amarvutha / blochSphere.py
Created September 3, 2013 15:20
Bloch sphere. Template for drawing sphere and labels. Just add points.
# 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')
@amarvutha
amarvutha / speakUp.py
Created September 20, 2013 15:48
Voice synthesis via Python
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`])
@amarvutha
amarvutha / mixnv.py
Last active December 24, 2015 02:19
Controlling the MixNV rf generator
# 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
@amarvutha
amarvutha / plotLogfile.py
Last active December 25, 2015 05:09
Data logger with animated plot using Matplotlib, with some bells and widgets.
# Plot log files
# version 3
# Amar
# Changes: v2: 2012/11/27: Date & time display using native matplotlib, instead of unix timestamp
# v3: 2013/10/10: Rewritten completely using matplotlib animation, and slider for selectable range
import numpy as np
import random
import os
os.chdir("c:/data/googledrive/logs")