##// END OF EJS Templates
Merge pull request #8679 from ndunn219/patch-1...
Merge pull request #8679 from ndunn219/patch-1 Update JavaScript Notebook Extensions.ipynb

File last commit:

r20541:1e566dcc
r21560:db1266a5 merge
Show More
Beat Frequencies.ipynb
120 lines | 2.4 KiB | text/plain | TextLexer
Brian E. Granger
Refactoring interact examples.
r16092 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "cells": [
Brian E. Granger
Refactoring interact examples.
r16092 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "cell_type": "markdown",
"metadata": {},
"source": [
"# Exploring Beat Frequencies using the `Audio` Object"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example uses the `Audio` object and Matplotlib to explore the phenomenon of beat frequencies."
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from IPython.html.widgets import interactive\n",
"from IPython.display import Audio, display\n",
"import numpy as np"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def beat_freq(f1=220.0, f2=224.0):\n",
" max_time = 3\n",
" rate = 8000\n",
" times = np.linspace(0,max_time,rate*max_time)\n",
" signal = np.sin(2*np.pi*f1*times) + np.sin(2*np.pi*f2*times)\n",
" print(f1, f2, abs(f1-f2))\n",
" display(Audio(data=signal, rate=rate))\n",
" return signal"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "outputs": [],
Min RK
upate exmaple notebooks to nbformat v4
r18669 "source": [
"v = interactive(beat_freq, f1=(200.0,300.0), f2=(200.0,300.0))\n",
"display(v)"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "outputs": [],
Min RK
upate exmaple notebooks to nbformat v4
r18669 "source": [
"v.kwargs"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "outputs": [],
Min RK
upate exmaple notebooks to nbformat v4
r18669 "source": [
"f1, f2 = v.children\n",
"f1.value = 255\n",
"f2.value = 260\n",
"plt.plot(v.result[0:6000])"
]
Brian E. Granger
Refactoring interact examples.
r16092 }
Min RK
upate exmaple notebooks to nbformat v4
r18669 ],
Min RK
add kernel metadata to example notebooks
r20278 "metadata": {
"kernelspec": {
"display_name": "Python 3",
"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",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "version": "3.4.0"
Min RK
add kernel metadata to example notebooks
r20278 }
},
Min RK
upate exmaple notebooks to nbformat v4
r18669 "nbformat": 4,
"nbformat_minor": 0
Min RK
add kernel metadata to example notebooks
r20278 }