{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "50b58d0f-e061-4397-a2ee-8b35d523bcf7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compiling library: SLiCAP.lib.\n",
      "Compiling library: SLiCAPmodels.lib.\n"
     ]
    }
   ],
   "source": [
    "from SLiCAP import trace, plot, float2rational, initProject\n",
    "from numpy import geomspace\n",
    "from sympy import Symbol, lambdify, sqrt\n",
    "initProject(\"specifications\", notebook = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9073712d-a433-4cf3-b6c5-2813cb197cda",
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [],
   "source": [
    "f            = Symbol(\"f\")\n",
    "DIN_A        = 12194**2*f**4/((f**2+20.6**2)*(f**2+12194**2)*sqrt((f**2+107.7**2)*(f**2+737.9**2)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d1305660-a6b1-497f-ac2e-227ea8dae02b",
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stored 'DIN_A' (Mul)\n"
     ]
    }
   ],
   "source": [
    "# normalized the weighting function w.r.t. 1kHz\n",
    "DIN_A        = float2rational(DIN_A/DIN_A.subs(f,1000))\n",
    "%store DIN_A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "15b7662f-67c1-49fd-b981-08faefe970b1",
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 47168 characters]",
      "text/plain": [
       "<Figure size 400x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot the DIN A weighting curve\n",
    "x            = geomspace(20, 20000, num=200)\n",
    "y            = lambdify(f,DIN_A)\n",
    "tr           = trace([x, y(x)])\n",
    "tr.label     = \"DIN A\"\n",
    "DINA_plot    = plot(\"DINA\", \"DIN A normalized at 1kHz\", 'log', {\"DINA\":tr}, xName='frequency', xUnits='Hz', yName='Weight', show=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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
