Manage Touchstone Objects

This example shows how to use Touchstone objects without opening AEDT.

To provide the advanced postprocessing features needed for this example, Matplotlib and NumPy must be installed on the machine.

This example runs only on Windows using CPython.

import os
import pathlib
import sys

local_path = os.path.abspath("")
module_path = pathlib.Path(local_path)
root_path = module_path.parent
root_path2 = root_path.parent
root_path3 = root_path2.parent
path1 = os.path.join(root_path2)
path2 = os.path.join(root_path3)
from pyaedt import examples

example_path = examples.download_touchstone()
import matplotlib.pyplot as plt
import numpy as np
from pyaedt.generic.TouchstoneParser import (
data = read_touchstone(example_path)

Get Curve Names

These methods identify the list of insertion losses, return losses, fext, and next based on a few inputs and port names.

rl_list = get_return_losses(data.ports)
il_list = get_insertion_losses_from_prefix(data.ports, "U1", "U7")
fext_list = get_fext_xtalk_from_prefix(data.ports, "U1", "U7")
next_list = get_next_xtalk(data.ports, "U1")

Get Curve Worst Cases

These example get the worst cases for the curve.

worst_rl, global_mean = get_worst_curve_from_solution_data(
    data, freq_min=1, freq_max=20, worst_is_higher=True, curve_list=rl_list
worst_il, mean2 = get_worst_curve_from_solution_data(
    data, freq_min=1, freq_max=20, worst_is_higher=False, curve_list=il_list
worst_fext, mean3 = get_worst_curve_from_solution_data(
    data, freq_min=1, freq_max=20, worst_is_higher=True, curve_list=fext_list
worst_next, mean4 = get_worst_curve_from_solution_data(
    data, freq_min=1, freq_max=20, worst_is_higher=True, curve_list=next_list

Use Matplotlib to Plot the Curves

This example uses Matplotlib to plot the curves.

fig, ax = plt.subplots(figsize=(20, 10))
ax.set(xlabel="Frequency (Hz)", ylabel="Return Loss (dB)", title="Return Loss")
mag_data = 20 * np.log10(np.array(data.solutions_data_mag[worst_rl]))
freq_data = np.array([i * 1e9 for i in data.sweeps["Freq"]])
ax.plot(freq_data, mag_data, label=worst_rl)
mag_data2 = 20 * np.log10(np.array(data.solutions_data_mag[worst_il]))
ax.plot(freq_data, mag_data2, label=worst_il)
mag_data3 = 20 * np.log10(np.array(data.solutions_data_mag[worst_fext]))
ax.plot(freq_data, mag_data3, label=worst_fext)
mag_data4 = 20 * np.log10(np.array(data.solutions_data_mag[worst_next]))
ax.plot(freq_data, mag_data4, label=worst_next)
    ["Worst RL = " + worst_rl, "Worst IL = " + worst_il, "Worst FEXT = " + worst_fext, "Worst NEXT = " + worst_next]
Return Loss

Total running time of the script: ( 0 minutes 0.391 seconds)

Gallery generated by Sphinx-Gallery