{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Simple sound processing via `WCA1`\n",
"\n",
"Companion notebook to the paper [_A bio-inspired geometric model for sound reconstruction_](https://arxiv.org/abs/2004.02450) by Boscain U., Prandi D., Sacchelli L., and Turco G."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m environment at `~/git-repos/WCA1/Project.toml`\n"
]
}
],
"source": [
"import Pkg\n",
"Pkg.activate(\"../../WCA1\")\n",
"using WCA1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## STFT of a signal\n",
"\n",
"We construct an artificial signal, composed of two linearly varying frequencies."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using ImageFiltering\n",
"\n",
"# We just generate an STFT container, starting from a sound\n",
"rate = 16000.\n",
"duration = 2\n",
"samples = round(Int,duration*rate)\n",
"y = [ t <= 8*samples/14 ? sin(1000*2*Ï€*t/rate+1000*t/rate*2*Ï€*t/rate) : 0. for t in 1:samples ]\n",
"\n",
"S = stft(y, 500, 450, fs = rate);\n",
"\n",
"function two_bars(p1, p2, km1, km2, N1, N2; λ = 4)\n",
" # the bars\n",
" U0v1=10*[(((i+10)p1+km1-1\n",
"\n"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"show_istft(S)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Evolution in the contact space\n",
"\n",
"We first lift the signal."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1.330836 seconds (3.12 M allocations: 243.137 MiB, 4.96% gc time)\n"
]
},
{
"data": {
"text/plain": [
"(251, 631, 30)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@time L = lift(S, threshold = 10, N=30) ;\n",
"\n",
"size(L)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We then evolve it, according to the following Wilson-Cowan equation with delay:\n",
"$$\n",
" \\partial_\\tau a(\\tau, \\omega, \\nu) = -\\alpha a(\\tau,\\omega,\\nu)+\\beta L(\\tau,\\omega,\\nu) +\\gamma\\int_{\\mathbb R^2} w(\\omega,\\nu\\|\\omega',\\nu') \\sigma(a(\\tau-\\delta, \\omega', \\nu')) \\,d\\omega'\\,d\\nu'\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32mWC evolution...100%|███████████████████████████████████▉| ETA: 0:00:00\u001b[39m"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 10.350999 seconds (1.63 M allocations: 1.339 GiB, 2.71% gc time)\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# dry run for compilation purposes\n",
"wc_delay(L, 0., 0., 0.)\n",
"\n",
"α = 16\n",
"β = 1\n",
"γ = 18\n",
"\n",
"@time W = wc_delay(L, α, β, γ, b = 4)\n",
"\n",
"show_stft(W)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"show_istft(W)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.5.2",
"language": "julia",
"name": "julia-1.5"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}