lasprs/examples_py/test_freqweighting.ipynb

111 lines
2.6 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"id": "bcd07c1e-6722-44c7-b162-267f1341c2fe",
"metadata": {},
"source": [
"# Frequency weighting plots"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f0c4d6ef-69b2-4b5c-92fd-d987a11f3cbd",
"metadata": {},
"outputs": [],
"source": [
"# Prerequisites, uncomment below in case of errors. Also for ipympl, restart Jupyter Lab if it was not installed\n",
"\n",
"!cd .. && maturin develop -F python-bindings\n",
"#!pip install ipympl scipy matplotlib"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23b45cf6-85bc-4eaa-8f27-77c5b354e772",
"metadata": {},
"outputs": [],
"source": [
"# If this does not work, install ipympl and reboot Jupyter Lab\n",
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "96090ac9-2033-411d-8e45-0c6b375a268b",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from numpy import log10\n",
"from lasprs import ZPKModel, FreqWeighting\n",
"def level(a):\n",
" return 20*np.log10(np.abs(a))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "52343e3d-63ef-4fc2-ad7e-85ca124efdac",
"metadata": {},
"outputs": [],
"source": [
"A = ZPKModel.freqWeightingFilter(FreqWeighting.A)\n",
"C = ZPKModel.freqWeightingFilter(FreqWeighting.C)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7d3cc799-4809-4ea4-8570-89ffbb751a5a",
"metadata": {},
"outputs": [],
"source": [
"freq = np.logspace(log10(2), log10(2e4), 200)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab22d9cc-03ae-4d58-b730-599b659f9dc0",
"metadata": {},
"outputs": [],
"source": [
"plt.figure()\n",
"plt.title('Frequency response of weighting filters - magnitude')\n",
"plt.semilogx(freq, level(A.tf(0, freq)))\n",
"plt.semilogx(freq, level(C.tf(0, freq)))\n",
"plt.legend(['A-weighting', 'Z-weighting'])\n",
"plt.ylabel('Magnitude [dB]')\n",
"plt.ylim(-50, 3)\n",
"plt.xlabel('Freq. [Hz]')"
]
}
],
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}