Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# INIT\n",
"%reset -s -f\n",
"# %matplotlib ipympl\n",
"# %matplotlib inline \n",
"# notebook\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"# standard libraries\n",
"import sys\n",
"import os\n",
" \n",
"# third-party libraries\n",
"import numpy as np\n",
"\n",
"print(\"Python version\", sys.version)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from utils_jgm.plotters import MOSFETOutputWidgetizer\n",
"\n",
"mosfet = MOSFETOutputWidgetizer()\n",
"mosfet.get_layout()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from utils_jgm.plotters import MOSFETTransferWidgetizer\n",
"\n",
"mosfet = MOSFETTransferWidgetizer()\n",
"mosfet.get_layout()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# standard libraries\n",
"import sys\n",
"import os\n",
" \n",
"# third-party libraries\n",
"import numpy as np\n",
"\n",
"print(\"Python version\", sys.version)\n",
"\n",
"from utils_jgm.plotters import MOSFETAmplifierWidgetizer\n",
"\n",
"mosfet = MOSFETAmplifierWidgetizer()\n",
"mosfet.get_layout()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# from scipy import signal\n",
"# import matplotlib.pyplot as plt\n",
"# import math\n",
"\n",
"# zeros = [-1]\n",
"# poles = [-1/100, -10]\n",
"# gain = 1\n",
"\n",
"# ZPG_model = signal.ZerosPolesGain(zeros, poles, gain)\n",
"# frequencies, magnitude, phase = signal.bode( #ZPG_model.bode()\n",
"# ZPG_model,\n",
"# #w=frequencies \n",
"# )\n",
"# figure, ax = plt.subplots(2,1,figsize=[5,10])\n",
"# ax[0].plot(frequencies, magnitude)\n",
"# ax[1].plot(frequencies, phase)\n",
"# for axis in ax:\n",
"# axis.set_xscale('log')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import matplotlib.pyplot as plt\n",
"\n",
"# t0 = -200\n",
"# T = 1200\n",
"\n",
"# T1 = (T+t0)//5\n",
"# x1 = np.zeros(T)\n",
"# x1[0:T1] = 1\n",
"\n",
"# T2 = (T+t0)//5\n",
"# x2 = np.zeros(T)\n",
"# x2[0:T2] = 1\n",
"\n",
"# plt.plot(x1,)\n",
"# plt.plot(x2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from utils_jgm.plotters import RLCWidgetizer\n",
"\n",
"\n",
"w = RLCWidgetizer()\n",
"w.get_layout()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from utils_jgm.plotters import EulersWidgetizer\n",
"\n",
"w = EulersWidgetizer()\n",
"w.get_layout()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from scipy import signal\n",
"\n",
"L1 = 5/4\n",
"L2 = 5\n",
"C = 1/25\n",
"\n",
"num = [L1*L2/(L1+L2), 0, L1/(L1+L2)/C, 0]\n",
"den = [1, 0, 1/(L1+L2)/C]\n",
"\n",
"frequencies, magnitude, phase = signal.bode(\n",
" [num, den] # , w=frequencies \n",
")\n",
"\n",
"import matplotlib.pyplot as plt\n",
"plt.plot(frequencies, magnitude)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# from ipywidgets import interact, fixed\n",
"\n",
"# import bokeh\n",
"# from bokeh.plotting import figure\n",
"# from bokeh.layouts import gridplot, column\n",
"\n",
"# #from bokeh.resources import CDN\n",
"# from bokeh.embed import file_html\n",
"\n",
"# from bokeh.plotting import figure # show, output_notebook\n",
"# from bokeh.models import ColumnDataSource, CustomJS, Slider, PointDrawTool\n",
"# from bokeh.core.properties import value\n",
"# from bokeh.io import show, output_notebook, push_notebook\n",
"\n",
"# from bokeh.events import ButtonClick\n",
"# from bokeh.models import Button\n",
"\n",
"# output_notebook() # output bokeh plots to jupyter notebook"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# def Bode_plot_plus_bokeh(zeros, gain=1, w0=100, Bw=200):\n",
" \n",
"# # ...\n",
"# poles = resonant_freq_bandwidth_to_poles(w0, Bw)\n",
"# ZPG_model = signal.ZerosPolesGain(zeros, poles, gain)\n",
"\n",
"# # ...\n",
"# Bode_data = ColumnDataSource({\n",
"# key: value for key, value in zip(('frequency', 'magnitude', 'phase'), ZPG_model.bode())\n",
"# })\n",
"\n",
"\n",
"# # magnitude \n",
"# p0 = figure(\n",
"# title='|H(j\\u03C9)|',\n",
"# x_axis_type='log',\n",
"# x_axis_label='\\u03C9 (rad/s)',\n",
"# y_axis_label='dB',\n",
"# plot_width=450,\n",
"# plot_height=250\n",
"# )\n",
"# r0 = p0.line(\"frequency\", \"magnitude\", source=Bode_data)\n",
"\n",
"# # phase\n",
"# p1 = figure(\n",
"# title='\\u2220 H(j\\u03C9)',\n",
"# x_axis_type='log',\n",
"# x_axis_label='\\u03C9 (rad/s)',\n",
"# y_axis_label='degrees',\n",
"# plot_width=450,\n",
"# plot_height=250\n",
"# )\n",
"# r1 = p1.line(\"frequency\", \"phase\", source=Bode_data)\n",
"\n",
"# # pole-zero plot\n",
"# xmin = min([*np.real(poles), -w0])*1.1\n",
"# xmax = max([*np.real(poles), w0])*1.1\n",
"# ymin = min([*np.imag(poles), -w0])*1.1\n",
"# ymax = max([*np.imag(poles), w0])*1.1\n",
"\n",
" \n",
"# tooltips = [\n",
"# (\"index\", \"$index\"),\n",
"# (\"(x,y)\", \"($x, $y)\"),\n",
"# ]\n",
"# p2 = figure(\n",
"# title='Pole-Zero plot',\n",
"# x_axis_label='Re',\n",
"# y_axis_label='Im',\n",
"# aspect_ratio=(xmax-xmin)/(ymax-ymin),\n",
"# plot_height=500,\n",
"# tooltips=tooltips,\n",
"# )\n",
"# circle_plot = p2.line(\n",
"# \"x\", \"y\",\n",
"# source=ColumnDataSource(get_circle_data(w0)),\n",
"# line_dash='dashed'\n",
"# )\n",
"\n",
"# zero_data = ColumnDataSource({\n",
"# 'real': np.real(zeros),\n",
"# 'imag': np.imag(zeros),\n",
"# 'size': [10 for pole in zeros]\n",
"# })\n",
"# glyph = bokeh.models.Circle(\n",
"# x='real', y='imag', size='size', line_color='green', fill_color=None\n",
"# )\n",
"# zeros_glyphs = p2.add_glyph(zero_data, glyph)\n",
"\n",
"# pole_data = ColumnDataSource({\n",
"# 'real': np.real(poles),\n",
"# 'imag': np.imag(poles),\n",
"# 'size': [10 for pole in poles]\n",
"# })\n",
"# glyph = bokeh.models.X(x='real', y='imag', size='size', line_color='red')\n",
"# poles_glyphs = p2.add_glyph(pole_data, glyph)\n",
"# # p2.add_tools(PointDrawTool(renderers=[poles_glyphs, zeros_glyphs]))\n",
"\n",
"# button = Button()\n",
"# def callback(event):\n",
"# print('Python:Click')\n",
"# button.on_event(ButtonClick, callback)\n",
"\n",
"\n",
"# # ...\n",
"# grid = gridplot(\n",
"# [[column(p0, p1), p2]], sizing_mode='scale_height'\n",
"# )\n",
"# show(grid, notebook_handle=True)\n",
" \n",
"# return Bode_data, circle_plot, poles_glyphs\n",
"\n",
"# def get_circle_data(w0):\n",
"# x = np.linspace(-w0, w0, 1000)\n",
"# y = (w0**2 - x**2)**(1/2)\n",
"# return {\n",
"# 'x': np.concatenate((x,np.flip(x))),\n",
"# 'y': np.concatenate((y,-np.flip(y)))\n",
"# }\n",
"\n",
"# def resonant_freq_bandwidth_to_poles(w0, Bw):\n",
"# '''\n",
"# Convert w0 and Bw into w1, w2 for second-order system.\n",
" \n",
"# Recall that \n",
"# w0 = (w1*w2)**(1/2),\n",
"# i.e., w0 fixes the geometric mean of the poles, and that\n",
"# Bw = 1/(R*C),\n",
"# so different bandwidths could be achieved with a constant w0 by,\n",
"# e.g., increasing the resistance.\n",
"# '''\n",
"\n",
"# gg = ((Bw/2)**2 - w0**2)**(1/2)\n",
"# w1 = +gg - Bw/2\n",
"# w2 = -gg - Bw/2\n",
"# return [w1, w2]\n",
" \n",
"# def update(gain=1, w0=100, Bw=250):\n",
" \n",
"# # get the new poles and update their locations\n",
"# poles = resonant_freq_bandwidth_to_poles(w0, Bw)\n",
"# poles_glyphs.data_source.data['real'] = np.real(poles)\n",
"# poles_glyphs.data_source.data['imag'] = np.imag(poles)\n",
"\n",
"# # ...\n",
"# circle_plot.data_source.data = get_circle_data(w0)\n",
" \n",
"# # set up the new transfer function by specifying its zero, poles, and gain\n",
"# ZPG_model = signal.ZerosPolesGain(zeros, poles, gain)\n",
"\n",
"# # copy the new Bode data into the old Bode data\n",
"# new_Bode_data = {key: value for key, value in zip(('frequency', 'magnitude', 'phase'), ZPG_model.bode())}\n",
"# for key in 'frequency', 'magnitude', 'phase':\n",
"# Bode_data.data[key] = new_Bode_data[key]\n",
"\n",
"# push_notebook()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
" \n",
"# def bokeh_plot_RLC(R=50, L=1.0, C=100e-6, x0=0, xdot0=0):\n",
"# # for this combo of R,L, and C, put data into ColumnDataSource data structure\n",
"# RLC_data = ColumnDataSource({\n",
"# key: value for key, value in zip(('time', 'current'), get_RLC_response(R,L,C,x0,xdot0))\n",
"# })\n",
"\n",
"# # create the figure\n",
"# #####\n",
"# # When there is no damping, the coefficients of the cosine and sine are\n",
"# # x0 and xdot0/w. In this circuit, w = sqrt(1/LC). Hence, the amplitude\n",
"# # of the combined sinusoidal response is (by the Pythagorean theorem):\n",
"# max_amplitude = (x0**2 + xdot0**2*L*C )**(1/2)\n",
"# tmin = -0.05\n",
"# tmax = 0.2*1.1\n",
"# imin = -max_amplitude*1.1\n",
"# imax = max_amplitude*1.1\n",
"# print(max_amplitude)\n",
"\n",
"# p0 = figure(\n",
"# title='(Unforced) current in RLC circuit',\n",
"# x_axis_label='t',\n",
"# y_axis_label='i (A)',\n",
"# y_range = [imin, imax],\n",
"# plot_width=450,\n",
"# plot_height=250\n",
"# # tooltips=tooltips,\n",
"# )\n",
" \n",
"# # plot\n",
"# r0 = p0.line(\"time\", \"current\", source=RLC_data)\n",
"# grid = gridplot([[p0]], sizing_mode='scale_height')\n",
"# show(grid, notebook_handle=True)\n",
" \n",
"\n",
"# return RLC_data\n",
"\n",
"# # ax.plot(t,x)\n",
"# # ax.legend(legend_str)\n",
"\n",
"# def update_RLC(R=50,L=1,C=100e-6,x0=0,xdot0=0):\n",
" \n",
"# # copy the new Bode data into the old Bode data\n",
"# new_RLC_data = {key: value for key, value in zip(('time', 'current'), get_RLC_response(R,L,C,x0,xdot0))}\n",
"# for key in 'time', 'current':\n",
"# RLC_data.data[key] = new_RLC_data[key]\n",
"# push_notebook()\n",
" \n",
"# x0 = 2; xdot0 = 1000\n",
"# RLC_data = bokeh_plot_RLC(C=100e-6, x0=x0, xdot0=xdot0)\n",
"# interact(\n",
"# update_RLC,\n",
"# R=(5,1000,5), L=(0.2,10,0.2),\n",
"# # C=fixed(100e-6),\n",
"# C=(10e-6,1000e-6,10e-6),\n",
"# x0=fixed(x0), xdot0=fixed(xdot0)\n",
"# )\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# zeros = [0] # Fix a single zero at 0 (perhaps change this later....)\n",
"# Bode_data, circle_plot, poles_glyphs = Bode_plot_plus_bokeh(zeros)\n",
"\n",
"# interact(update, gain=(1.0, 10.0), w0=(10,1000), Bw=(0.001, 300))"
]
}
],
"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.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}