Skip to content

Instantly share code, notes, and snippets.

@amarvutha
Last active January 3, 2016 22:39
Show Gist options
  • Save amarvutha/8530117 to your computer and use it in GitHub Desktop.
Save amarvutha/8530117 to your computer and use it in GitHub Desktop.
Spectrum analyzer, using an SR850 lock-in amplifier
# SR850 as a spectrum analyzer
# version 1, 2014-01-21
# Amar
import os
os.chdir("c:/data/googledrive/code")
import SR850
import numpy as np
import pylab as plt
lia= SR850.LIA("COM7")
lia.characterize()
lia.write("TRCD 1,5,0,0,0") # set trace 1 to Xn (rms noise in X quadrature, V/rt-Hz)
lia.write("TRCD 2,6,0,0,0") # set trace 2 to Yn (rms noise in Y quadrature, V/rt-Hz)
background = True
Navg = 1000
f = 10**np.arange(0,4,0.2)
Xn, Xn_err = np.array( lia.scanR(f,trace=1,N=Navg,std=True) )
if background:
print
foo = raw_input("Ready for background measurement?")
Xn_bg, Xn_bg_err = np.array( lia.scanR(f,trace=1,N=Navg,std=True) )
lia.close()
plt.figure(1)
plt.title("Current noise spectrum with lock-in \n G = 1e9 V/A, 10 mV FS, 0 dB reserve")
plt.xlabel("Frequency, f [Hz]")
plt.ylabel("Current noise, $\sqrt{W_I}$ [A/$\sqrt{\mathrm{Hz}}$]")
plt.xscale('log')
plt.yscale('log')
plt.errorbar(f,np.sqrt(2) * Xn/1e9,yerr = 20 * np.sqrt(2) * Xn_err/1e9,color='b',marker='o',lw=2,label="Beam on")
if background:
plt.errorbar(f,np.sqrt(2) * Xn_bg/1e9,yerr = 20 * np.sqrt(2) * Xn_bg_err/1e9,color='g',marker='^',lw=2,label="Background")
plt.plot(f,np.sqrt(2*1.6e-19*1.7e-9)*np.ones(len(f)),'b--',lw=4, alpha=0.5,label="Shot noise")
plt.legend(loc='upper right')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment