%23%20gallery_category%3A%20FDN%20Design%20%26%20Analysis%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.23.13%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Interpolate%20between%20two%20orthogonal%20matrices%0A%0A%20%20%20%20Interpolate%20between%20two%20orthogonal%20matrices%20so%20that%20each%20interpolant%20is%20orthogonal%20(geodesic%20on%20the%20orthogonal%20group).%20Then%20use%20three%20of%20these%20matrices%20as%20FDN%20feedback%20matrices%20and%20plot%20their%20impulse%20responses%20via%20%60pyFDN.dss2impz%60.%0A%0A%20%20%20%20Reference%3A%20*Schlecht%2C%20S.%2C%20Habets%2C%20E.%20(2015).%20Practical%20considerations%20of%20time-varying%20feedback%20delay%20networks.*%20Proc.%20Audio%20Eng.%20Soc.%20Conv.%0A%0A%20%20%20%20-%20Original%20version%3A%20Sebastian%20J.%20Schlecht%2C%20Friday%2C%2010.%20April%202020%0A%20%20%20%20-%20Translation%3A%20Sebastian%20J.%20Schlecht%2C%20Thursday%2C%2019.%20February%202026%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20math%0A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20plotly.io%20as%20pio%0A%0A%20%20%20%20pio.renderers.default%20%3D%20%22sphinx_gallery%22%20%20%23%20interactive%20in%20Jupyter%20%2B%20docs%20HTML%0A%20%20%20%20from%20scipy.linalg%20import%20hadamard%0A%0A%20%20%20%20import%20pyFDN%0A%0A%20%20%20%20return%20hadamard%2C%20math%2C%20np%2C%20pyFDN%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Parameters%20and%20interpolation%0A%0A%20%20%20%20Start%20from%20a%20Hadamard%20matrix%20(sign-normalized)%20and%20the%20identity%3B%20interpolate%20along%2020%20steps%20and%20verify%20each%20interpolant%20is%20orthogonal.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(hadamard%2C%20math%2C%20np%2C%20pyFDN)%3A%0A%20%20%20%20N%20%3D%204%0A%20%20%20%20%23%20Hadamard%2C%20normalized%20and%20sign-normalized%20on%20diagonal%20(match%20MATLAB%20fdnMatrixGallery)%0A%20%20%20%20A%20%3D%20hadamard(N)%20%2F%20math.sqrt(N)%0A%20%20%20%20A%20%3D%20A%20%40%20np.diag(np.sign(np.diag(A)))%0A%20%20%20%20B%20%3D%20np.eye(N)%0A%0A%20%20%20%20num_t%20%3D%2020%0A%20%20%20%20T%20%3D%20np.linspace(0%2C%201%2C%20num_t)%0A%20%20%20%20C%20%3D%20np.zeros((N%2C%20N%2C%20num_t))%0A%20%20%20%20for%20it%2C%20t%20in%20enumerate(T)%3A%0A%20%20%20%20%20%20%20%20C%5B%3A%2C%20%3A%2C%20it%5D%20%3D%20pyFDN.interpolate_orthogonal(A%2C%20B%2C%20t)%0A%0A%20%20%20%20is_orth%20%3D%20%5BpyFDN.is_orthogonal(C%5B%3A%2C%20%3A%2C%20it%5D)%20for%20it%20in%20range(num_t)%5D%0A%20%20%20%20assert%20all(is_orth)%2C%20%22All%20interpolants%20should%20be%20orthogonal%22%0A%20%20%20%20print(%22All%20interpolants%20are%20orthogonal.%22)%0A%20%20%20%20return%20C%2C%20N%2C%20T%2C%20num_t%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Animation%20of%20the%20interpolated%20feedback%20matrix%0A%0A%20%20%20%20Animate%20**C(t)**%20as%20a%20heatmap%3B%20use%20the%20slider%20or%20play%20button%20to%20move%20along%20the%20geodesic%20from%20A%20(t%3D0)%20to%20B%20(t%3D1).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20T%2C%20pyFDN)%3A%0A%20%20%20%20%23%20animate%20one%20plot_matrix%20heatmap%20per%20time%20step%20(slider%20%2B%20play%20built%20in).%0A%20%20%20%20_fig%20%3D%20pyFDN.animate(%0A%20%20%20%20%20%20%20%20lambda%20M%3A%20pyFDN.plot_matrix(M%2C%20zmin%3D-1%2C%20zmax%3D1)%2C%0A%20%20%20%20%20%20%20%20%5BC%5B%3A%2C%20%3A%2C%20k%5D%20for%20k%20in%20range(C.shape%5B2%5D)%5D%2C%0A%20%20%20%20%20%20%20%20labels%3DT%2C%0A%20%20%20%20%20%20%20%20label_prefix%3D%22t%20%3D%20%22%2C%0A%20%20%20%20%20%20%20%20label_format%3D%22.2f%22%2C%0A%20%20%20%20)%0A%20%20%20%20_fig.update_layout(height%3D420%2C%20width%3D420)%0A%20%20%20%20_fig.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Three%20impulse%20responses%20via%20dss2impz%0A%0A%20%20%20%20Use%20three%20feedback%20matrices%20(t%3D0%2C%20t%3D0.63%2C%20t%3D1)%20in%20a%20minimal%20FDN%20and%20compute%20the%20impulse%20response%20for%20each%20with%20%60pyFDN.dss2impz%60.%20Plot%20the%20three%20IRs%20(mu-law%20encoded%20for%20visibility).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20N%2C%20T%2C%20np%2C%20num_t%2C%20pyFDN)%3A%0A%20%20%20%20ir_len%20%3D%202000%0A%20%20%20%20delays%20%3D%20np.array(%5B101%2C%20163%2C%20197%2C%20241%5D%2C%20dtype%3Dnp.int64)%0A%20%20%20%20g%20%3D%200.999%0A%20%20%20%20b%20%3D%20np.ones((N%2C%201))%0A%20%20%20%20c%20%3D%20np.ones((1%2C%20N))%0A%20%20%20%20d%20%3D%20np.array(%5B%5B0.0%5D%5D)%0A%20%20%20%20idx%20%3D%20%5B0%2C%20num_t%20%2F%2F%203%20*%202%2C%20num_t%20-%201%5D%0A%20%20%20%20%23%20Pick%20three%20interpolants%3A%20start%20(A)%2C%20middle%2C%20end%20(B)%0A%20%20%20%20labels%20%3D%20%5Bf%22t%3D%7BT%5Bi%5D%3A.2f%7D%22%20for%20i%20in%20idx%5D%0A%20%20%20%20irs%20%3D%20%5B%5D%0A%20%20%20%20for%20i%20in%20idx%3A%0A%20%20%20%20%20%20%20%20Af%20%3D%20C%5B%3A%2C%20%3A%2C%20i%5D%20%40%20np.diag(g**delays)%0A%20%20%20%20%20%20%20%20ir%20%3D%20pyFDN.dss_to_impz(%0A%20%20%20%20%20%20%20%20%20%20%20%20ir_len%2C%20delays%2C%20Af%2C%20b%2C%20c%2C%20d%0A%20%20%20%20%20%20%20%20)%20%20%23%20feedback%20matrix%20with%20gain%20per%20delay%0A%20%20%20%20%20%20%20%20ir%20%3D%20np.asarray(ir).squeeze().ravel()%0A%20%20%20%20%20%20%20%20irs.append(ir)%0A%20%20%20%20pyFDN.plot_impulse_response(%0A%20%20%20%20%20%20%20%20*irs%2C%0A%20%20%20%20%20%20%20%20labels%3Dlabels%2C%0A%20%20%20%20%20%20%20%20title%3D%22FDN%20impulse%20response%20for%20three%20interpolated%20feedback%20matrices%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
f3061e623c2724f645159e61ebe431be