Skip to content

Commit

Permalink
example cookbooks
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Jun 18, 2024
1 parent 42c60b4 commit 0a0224f
Show file tree
Hide file tree
Showing 6 changed files with 1,262 additions and 93 deletions.
2 changes: 2 additions & 0 deletions _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ parts:
- caption: Example Workflows
chapters:
- file: notebooks/example-workflows/jingle-bells
- file: notebooks/example-workflows/spy-sounds
- file: notebooks/example-workflows/nino3
159 changes: 112 additions & 47 deletions notebooks/example-workflows/jingle-bells.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Audio Processing and Jingle Bells\n",
"# PyWavelets and Jingle Bells\n",
"\n",
"Next, title your notebook appropriately with a top-level Markdown header, `#`. Do not use this level header anywhere else in the notebook. Our book build process will use this title in the navbar, table of contents, etc. Keep it short, keep it descriptive. Follow this with a `---` cell to visually distinguish the transition to the prerequisites section."
"Wavelet analysis is accomplished in Python via external package. PyWavelets is an open source Python package for applying wavelet analysis. \n",
"\n",
"[PyWavelets: pywt.cwt](https://pywavelets.readthedocs.io/en/latest/ref/cwt.html#pywt.cwt)"
]
},
{
Expand All @@ -36,11 +38,11 @@
"## Overview\n",
"If you have an introductory paragraph, lead with it here! Keep it short and tied to your material, then be sure to continue into the required list of topics below,\n",
"\n",
"1. This is a numbered list of the specific topics\n",
"1. These should map approximately to your main sections of content\n",
"1. Or each second-level, `##`, header in your notebook\n",
"1. Keep the size and scope of your notebook in check\n",
"1. And be sure to let the reader know up front the important concepts they'll be leaving with"
"1. Prerequisites\n",
"2. Background\n",
"3. PyWavelets Overview\n",
"4. Wavelet Power Spectrum\n",
"5. Wavelet Phase Spectrum"
]
},
{
Expand Down Expand Up @@ -95,91 +97,154 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Your first content section"
"## PyWavelets Overview\n",
"\n",
"[PyWavelets: pywt.cwt](https://pywavelets.readthedocs.io/en/latest/ref/cwt.html#pywt.cwt)\n",
"\n",
"Wavelet analysis is accomplished in Python via external package. PyWavelets is an open source Python package for applying wavelet analysis. \n",
"\n",
"```\n",
"coeffs, freqs = pywt.cwt(data, scales, wavelet, sampling_period)\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is where you begin your first section of material, loosely tied to your objectives stated up front. Tie together your notebook as a narrative, with interspersed Markdown text, images, and more as necessary,"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# as well as any and all of your code cells\n",
"print(\"Hello world!\")"
"### Input Values\n",
"- data: inpt data as a array_like\n",
"- scales: array_like collection of the scales to use (np.arange(s0, jtot, dj))\n",
"- wavelet: name of Mother wavelet\n",
"- sampling_period: optional sampling period for frequencies output"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### A content subsection\n",
"Divide and conquer your objectives with Markdown subsections, which will populate the helpful navbar in Jupyter Lab and here on the Jupyter Book!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# some subsection code\n",
"new = \"helpful information\""
"### Return Values\n",
"- coefs: array_like collection of complex number output for wavelet coefficients\n",
"- freqs: array_like collection of frequencies"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Another content subsection\n",
"Keep up the good work! A note, *try to avoid using code comments as narrative*, and instead let them only exist as brief clarifications where necessary."
"### Choosing a Scale\n",
"### Scales vs. Frequency\n",
"\n",
"The range of scales are a combination of s0, dj, and jtot. The musical range of frequenceis range from 261 - 494 Hz\n",
"\n",
"| Note | Freq |\n",
"|--------|--------|\n",
"| A note | 440 hz |\n",
"| B note | 494 hz |\n",
"| C note | 261 hz |\n",
"| D note | 293 hz |\n",
"| E note | 330 hz |\n",
"| F note | 350 hz |\n",
"| G note | 392 hz |\n",
"\n",
"It is good to include a range greater than needed to make clear bands for each frequency\n",
"\n",
"For example, scales from 1 to 40 represent a frequency (Hz) range from 8125 - 208.33 Hz\n",
"\n",
"| Scale | Freq (Hz) |\n",
"|--------|--------|\n",
"| 1 | 8125.00 |\n",
"| 2 | 4062.50 |\n",
"| 3 | 2708.33 |\n",
"| 4 | 2031.25 |\n",
"| 5 | 1625.00 |\n",
"| 6 | 1354.17 |\n",
"| 7 | 1160.71 |\n",
"| 8 | 1015.62 |\n",
"| 9 | 902.78 |\n",
"| 10 | 812.50 |\n",
"| 11 | 738.64 |\n",
"| 12 | 677.08 |\n",
"| 13 | 625.00 |\n",
"| 14 | 580.36 |\n",
"| 15 | 541.67 |\n",
"| 16 | 507.81 |\n",
"| 17 | 477.94 |\n",
"| 18 | 451.39 |\n",
"| 19 | 427.63 |\n",
"| 20 | 406.25 |\n",
"| 21 | 386.90 |\n",
"| 22 | 369.32 |\n",
"| 23 | 353.26 |\n",
"| 24 | 338.54 |\n",
"| 25 | 325.00 |\n",
"| 26 | 312.50 |\n",
"| 27 | 300.93 |\n",
"| 28 | 290.18 |\n",
"| 29 | 280.17 |\n",
"| 30 | 270.83 |\n",
"| 31 | 262.10 |\n",
"| 32 | 253.91 |\n",
"| 33 | 246.21 |\n",
"| 34 | 238.97 |\n",
"| 35 | 232.14 |\n",
"| 36 | 225.69 |\n",
"| 37 | 219.59 |\n",
"| 38 | 213.82 |\n",
"| 39 | 208.33 |\n",
"\n",
"```\n",
"sample_rate, signal_data = wavfile.read('jingle_bells.wav')\n",
"scales = np.arange(1, 40)\n",
"wavelet_coeffs, freqs = pywt.cwt(signal_data, scales, wavelet = \"morl\")\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Your second content section\n",
"Here we can move on to our second objective, and we can demonstrate"
"## Power Spectrum"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Subsection to the second section\n",
"`wavelet_coeffs` is a complex number with a real and an imaginary number (1 + 2i). The power spectrum plots the real component of the complex number. The real component represents the magntiude of the wavelet coefficient displayed as the absolute value of the coefficients squared\n",
"\n",
"#### a quick demonstration\n",
"Wavelet_coeff is a complex number with a real and an imaginary number (1 + 2i). The power spectrum plots the real component of the complex number\n",
"\n",
"##### of further and further\n",
"```\n",
"import numpy as np\n",
"real_component = np.log2(np.square(abs(wavelet_coeffs)))\n",
"```\n",
"\n",
"###### header levels"
"The real component represents the magntiude of the wavelet coefficient"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"as well $m = a * t / h$ text! Similarly, you have access to other $\\LaTeX$ equation [**functionality**](https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Typesetting%20Equations.html) via MathJax (demo below from link),\n",
"\n",
"\\begin{align}\n",
"\\dot{x} & = \\sigma(y-x) \\\\\n",
"\\dot{y} & = \\rho x - y - xz \\\\\n",
"\\dot{z} & = -\\beta z + xy\n",
"\\end{align}"
"## Phase Spectrum"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check out [**any number of helpful Markdown resources**](https://www.markdownguide.org/basic-syntax/) for further customizing your notebooks and the [**Jupyter docs**](https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Working%20With%20Markdown%20Cells.html) for Jupyter-specific formatting information. Don't hesitate to ask questions if you have problems getting it to look *just right*."
"Wavelet_coeff is a complex numbre with a real and an imaginary number (1 + 2i). The less common phase plot uses the imaginary component of the complex number\n",
"\n",
"```\n",
"import numpy as np\n",
"\n",
"# note: np.angle() returns the angle of a complex argument\n",
"\n",
"imaginary_component = np.angle(wavelet_coeffs)\n",
"```\n",
"\n",
"The imaginary component represents the direction of the wavelet coefficient"
]
},
{
Expand Down
Loading

0 comments on commit 0a0224f

Please sign in to comment.