Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R&S ZVL13 Vector Network Analyzer example notebook #140

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
392 changes: 392 additions & 0 deletions docs/examples/ZVL13.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,392 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "19466733",
"metadata": {},
"source": [
"# Rohde & Schwarz ZVL13 Vector Network Analyzer example"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7fcdd82a",
"metadata": {},
"outputs": [],
"source": [
"import qcodes as qc\n",
"from qcodes.logger.logger import start_all_logging\n",
"import datetime\n",
"import numpy as np\n",
"%matplotlib notebook\n",
"from datetime import date,datetime\n",
"import pyvisa\n",
"import sys\n",
"import json\n",
"from qcodes_contrib_drivers.drivers.RohdeSchwarz.ZVL13 import ZVL13"
]
},
{
"cell_type": "markdown",
"id": "22756a22",
"metadata": {},
"source": [
"## Instrument and station initialization"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8c02c1fd",
"metadata": {},
"outputs": [],
"source": [
"start_all_logging()\n",
"\n",
"\n",
"#Instruments\n",
"VNA = ZVL13('ZVL', 'TCPIP0::vnarstafuri.fisica.unina.it::inst0::INSTR')\n",
"\n",
"\n",
"#Station inizialization\n",
"station = qc.Station()\n",
"station.add_component(VNA)"
]
},
{
"cell_type": "markdown",
"id": "9b3407d4",
"metadata": {},
"source": [
"# Parameters definition"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10f15f4b",
"metadata": {},
"outputs": [],
"source": [
"#########################\n",
"##Parameters definition##\n",
"#########################\n",
"\n",
"parameter_snap={}\n",
"\n",
"S_parameter = 'S11'\n",
"meas_format = 'dbm'\n",
"start_freq = 4\n",
"end_freq = 8\n",
"#center_freq = 5\n",
"#span_freq = 1\n",
"VNA_power = -20\n",
"IF_bandwidth = 1000\n",
"Averages = 4\n",
"points_VNA = 101 #Max:4001\n",
"\n",
"\n",
"\n",
"VNA.npts(points_VNA)\n",
"VNA.S_parameter(S_parameter)\n",
"VNA.format(meas_format)\n",
"VNA.bandwidth(IF_bandwidth)\n",
"VNA.power(VNA_power)\n",
"VNA.avg(Averages)\n",
"VNA.start(start_freq*1e9)\n",
"VNA.stop(end_freq*1e9)\n",
"#VNA.center(center_freq*1e9)\n",
"#VNA.span(span_freq*1e9)\n"
]
},
{
"cell_type": "markdown",
"id": "281974ab",
"metadata": {},
"source": [
"## Trace acquisition in Network Analyzer Mode"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4dd622ff",
"metadata": {},
"outputs": [],
"source": [
"#########################\n",
"#######Mode setting######\n",
"#########################\n",
"\n",
"Mode = VNA.mode() \n",
"\n",
"if Mode == 'SAN':\n",
" VNA.mode('nwa')\n",
"\n",
"#########################\n",
"##Parameters definition##\n",
"#########################\n",
"\n",
"S_parameter = 'S11'\n",
"meas_format = 'dbm'\n",
"start_freq = 4 #GHz\n",
"end_freq = 8 #GHz\n",
"#center_freq = 5 #GHz\n",
"#span_freq = 1 #GHz\n",
"VNA_power = -20 #dBm\n",
"IF_bandwidth = 1000 #Hz\n",
"Averages = 4\n",
"points_VNA = 101 #Max:4001\n",
"\n",
"\n",
"#Parameters setting in the VNA\n",
"VNA.calibration() #Switches on the most recent calibration in the VNA \n",
"VNA.S_parameter(S_parameter)\n",
"VNA.npts(points_VNA)\n",
"VNA.format(meas_format)\n",
"VNA.bandwidth(IF_bandwidth)\n",
"VNA.power(VNA_power)\n",
"VNA.avg(Averages)\n",
"VNA.start(start_freq*1e9)\n",
"VNA.stop(end_freq*1e9)\n",
"#VNA.center(center_freq*1e9)\n",
"#VNA.span(span_freq*1e9)\n",
"\n",
"#VNA Timeout setting\n",
"original_timeout = VNA.timeout()\n",
"new_timeout = 10\n",
"VNA.timeout(new_timeout)\n",
"\n",
"#############################\n",
"##Experiment initialization##\n",
"#############################\n",
"\n",
"#Experiment definition\n",
"exp_name = 'exp_name'\n",
"sample = 'sample'\n",
"exp=qc.load_or_create_experiment(experiment_name=exp_name,\n",
" sample_name=sample)\n",
"\n",
"\n",
"\n",
"#Parameters registration\n",
"meas = qc.Measurement(exp=exp, station=station) \n",
"meas.register_parameter(VNA.trace) \n",
"meas.register_parameter(VNA.S_trace)\n",
"\n",
"#Start measurement\n",
"VNA.rf_power(1) #Switches on the power\n",
"VNA.cont_meas_on() #Switches on the sweep\n",
"VNA.electrical_delay_auto() #Removes the electrical delay automatically\n",
"\n",
"\n",
"with meas.run() as datasaver:\n",
" VNA.autoscale() #Autoscale the trace on the VNA display\n",
" get_v = VNA.trace.get() #Get the trace displayed on the VNA\n",
" get_v2 = VNA.S_trace.get() #Get the complex form of the scattering parameter under test\n",
" datasaver.add_result((VNA.trace, get_v))\n",
" datasaver.add_result((VNA.S_trace, get_v2))\n",
"\n",
"\n",
"#Shutdown devices\n",
"VNA.rf_power(0)\n",
"VNA.cont_meas_off()\n",
"\n",
"###############\n",
"##Data saving##\n",
"###############\n",
"\n",
"captured_run_id=datasaver.dataset.run_id\n",
"dataset = qc.load_by_run_spec(captured_run_id=captured_run_id)\n",
"freq = dataset.get_parameter_data('ZVL_ZVL_frequency')['ZVL_ZVL_frequency']['ZVL_ZVL_frequency']\n",
"save_trace = dataset.get_parameter_data('ZVL_trace')['ZVL_trace']['ZVL_trace']\n",
"S_trace = dataset.get_parameter_data('ZVL_S_trace')['ZVL_S_trace']['ZVL_S_trace']"
]
},
{
"cell_type": "markdown",
"id": "af854ac4",
"metadata": {},
"source": [
"### Plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "94e04c84",
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(14*0.8, 10*0.8), dpi= 80) #facecolor='w', edgecolor='k'\n",
"\n",
"plt.plot(freq[0]*1e-9,save_trace[0])\n",
"\n",
"plt.rc('axes', labelsize=12) # fontsize of the x and y labels\n",
"plt.rc('xtick', labelsize=12*1.2) # fontsize of the tick labels\n",
"plt.rc('ytick', labelsize=12*1.2) \n",
"\n",
"x_label=''\n",
"y_label=''\n",
"plt.xlabel(x_label, size=25)\n",
"plt.ylabel(y_label, size=25)\n",
"plt.title(plot_title, size=18)\n",
"plt.xticks(fontsize=20)\n",
"plt.yticks(fontsize=20)\n",
"plt.grid(True)"
]
},
{
"cell_type": "markdown",
"id": "376ff36b",
"metadata": {},
"source": [
"## Trace acquisition in Spectrum Analyzer Mode"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b34a1b13",
"metadata": {},
"outputs": [],
"source": [
"# #######Mode setting######\n",
"#########################\n",
"\n",
"Mode = VNA.mode() \n",
"\n",
"if Mode == 'NWA':\n",
" VNA.mode('sa')\n",
"\n",
"#########################\n",
"##Parameters definition##\n",
"#########################\n",
"\n",
"\n",
"start_freq = 4 #GHz\n",
"end_freq = 8 #GHz\n",
"#center_freq = 5 #GHz\n",
"#span_freq = 1 #GHz\n",
"Averages = 4\n",
"points_VNA = 101 #Max:4001\n",
"\n",
"\n",
"#Parameters setting in the VNA\n",
"VNA.calibration() #Switches on the most recent calibration in the VNA \n",
"VNA.S_parameter(S_parameter)\n",
"VNA.npts(points_VNA)\n",
"VNA.format(meas_format)\n",
"VNA.bandwidth(IF_bandwidth)\n",
"VNA.power(VNA_power)\n",
"VNA.avg(Averages)\n",
"VNA.start(start_freq*1e9)\n",
"VNA.stop(end_freq*1e9)\n",
"#VNA.center(center_freq*1e9)\n",
"#VNA.span(span_freq*1e9)\n",
"\n",
"#VNA Timeout setting\n",
"original_timeout = VNA.timeout()\n",
"new_timeout = 10\n",
"VNA.timeout(new_timeout)\n",
"\n",
"#############################\n",
"##Experiment initialization##\n",
"#############################\n",
"\n",
"#Experiment definition\n",
"exp_name = 'exp_name'\n",
"sample = 'sample'\n",
"exp=qc.load_or_create_experiment(experiment_name=exp_name,\n",
" sample_name=sample)\n",
"\n",
"\n",
"\n",
"#Parameters registration\n",
"meas = qc.Measurement(exp=exp, station=station) \n",
"meas.register_parameter(VNA.spectrum) \n",
"\n",
"#Start measurement\n",
"VNA.cont_meas_on() #Switches on the sweep\n",
"\n",
"\n",
"with meas.run() as datasaver:\n",
" VNA.autoscale() #Autoscale the trace on the VNA display\n",
" get_v = VNA.spectrum.get() #Get the spectrum seen by Port 2\n",
" datasaver.add_result((VNA.spectrum, get_v))\n",
"\n",
"\n",
"#Shutdown devices\n",
"VNA.cont_meas_off()\n",
"\n",
"###############\n",
"##Data saving##\n",
"###############\n",
"\n",
"captured_run_id=datasaver.dataset.run_id\n",
"dataset = qc.load_by_run_spec(captured_run_id=captured_run_id)\n",
"freq = dataset.get_parameter_data('ZVL_ZVL_frequency')['ZVL_ZVL_frequency']['ZVL_ZVL_frequency']\n",
"save_trace = dataset.get_parameter_data('ZVL_trace')['ZVL_trace']['ZVL_trace']\n",
"S_trace = dataset.get_parameter_data('ZVL_S_trace')['ZVL_S_trace']['ZVL_S_trace']"
]
},
{
"cell_type": "markdown",
"id": "537efff5",
"metadata": {},
"source": [
"### Plot "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2b08d86",
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(14*0.8, 10*0.8), dpi= 80) \n",
"\n",
"plt.plot(freq[0]*1e-9,spectrum[0])\n",
"\n",
"plt.rc('axes', labelsize=12) \n",
"plt.rc('xtick', labelsize=12*1.2) \n",
"plt.rc('ytick', labelsize=12*1.2) \n",
"\n",
"x_label=''\n",
"y_label=''\n",
"plt.xlabel(x_label, size=25)\n",
"plt.ylabel(y_label, size=25)\n",
"plt.title(plot_title, size=18)\n",
"plt.xticks(fontsize=20)\n",
"plt.yticks(fontsize=20)\n",
"plt.grid(True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
},
"nbsphinx": {
"execute": "never"
}
},
"nbformat": 4,
"nbformat_minor": 5
}