{
"cells": [
{
"cell_type": "markdown",
"id": "0044a926-67cc-4850-8a9f-e802a1957603",
"metadata": {},
"source": [
"# Semi-Constant-Q Dyadic Filter Bank"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1a6861f9-f13e-4f7d-95e9-2d1503d590ac",
"metadata": {},
"outputs": [],
"source": [
"using NBInclude\n",
"using Plots\n",
"@nbinclude(\"GPUFilterBanks.ipynb\");\n",
"@nbinclude(\"AudioTools.ipynb\");"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fcaa5091-1765-463d-8159-8b1305eabcf9",
"metadata": {},
"outputs": [],
"source": [
"tetris = load(\"korobeiniki.wav\");\n",
"fs = round(Int,tetris.samplerate);\n",
"original = audio_to_float( truncate_audio(tetris.data,nextpow(2,10*fs)) );"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "9791a47d-45aa-45dc-ae54-a8666933d2b5",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n"
],
"text/plain": [
"524288-frame, 1-channel SampleBuf{Q0f15, 1}\n",
"11.888616780045352s sampled at 44100.0Hz\n",
"▁▁▆▆▆▅▇▆▆▆▆▆▆▆▆▆▆▆▆▆▆▅▆▆▆▆▆▆▆▅▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▅▆▆▆▅▆▆▆▆▆▆▆▆▆▆▆▆▆▅▆▆▆▆▆▆▆▅▆▆▆▆▆▆▆▆"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"float_to_audio(original,fs)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d1c318d5-f742-4f8f-82c5-130d5bfd91d5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1-element Vector{NTuple{4, Int64}}:\n",
" (524288, 1, 1, 1)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"num_octaves = 10;\n",
"\n",
"filters = [\n",
" WT.makeqmfpair(wavelet(WT.haar)),\n",
" WT.makereverseqmfpair(wavelet(WT.haar))\n",
"];\n",
"LA = tensor(Float32.(filters[1][1]));\n",
"HA = tensor(Float32.(filters[1][2]));\n",
"LS = tensor(Float32.(filters[2][1]));\n",
"HS = tensor(Float32.(filters[2][2]));\n",
"\n",
"x = [tensor(original)];\n",
"\n",
"size.(x)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "fe4eb85f-bda2-4015-8c8b-b8f0f9fa026e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11-element Vector{NTuple{4, Int64}}:\n",
" (8192, 32, 1, 1)\n",
" (4096, 32, 1, 1)\n",
" (2048, 32, 1, 1)\n",
" (1024, 32, 1, 1)\n",
" (512, 32, 1, 1)\n",
" (256, 32, 1, 1)\n",
" (128, 32, 1, 1)\n",
" (64, 32, 1, 1)\n",
" (32, 32, 1, 1)\n",
" (16, 32, 1, 1)\n",
" (16, 32, 1, 1)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y = analysis_filterbank(x, LA, HA)\n",
"size.(y)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0ecce0e8-38fe-4357-b4ee-a2986a163d3e",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"S1 = [];\n",
"for octave ∈ 1:(num_octaves+1)\n",
" y_i = collect(y[octave]);\n",
" h = heatmap(abs.(y_i[:,:]'), \n",
" axis=nothing, colorbar=nothing, size=(1000,2000));\n",
" append!(S1,[h]);\n",
"end\n",
"l = @layout [p1;p2;p3;p4;p5;p6;p7;p8;p9;p10;p11];\n",
"plot(S1..., layout=l)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f11709fe-1ed2-489a-8d6c-541f1316f7c7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1-element Vector{NTuple{4, Int64}}:\n",
" (524288, 1, 1, 1)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = synthesis_filterbank(y, LS, HS)\n",
"size.(x)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a7a0edc8-ba7f-4152-8d5f-b4ad3fbe6f0a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n"
],
"text/plain": [
"524288-frame, 1-channel SampleBuf{Q0f15, 1}\n",
"11.888616780045352s sampled at 44100.0Hz\n",
"▁▁▆▆▆▅▇▆▆▆▆▆▆▆▆▆▆▆▆▆▆▅▆▆▆▆▆▆▆▅▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▅▆▆▆▅▆▆▆▆▆▆▆▆▆▆▆▆▆▅▆▆▆▆▆▆▆▅▆▆▆▆▆▆▆▆"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"float_to_audio(collect(x[1][:]),fs)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.7.0-beta3",
"language": "julia",
"name": "julia-1.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}