.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/indiv_funcs/unitary_ft.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_indiv_funcs_unitary_ft.py: Unitary FT ========== Demonstrate new argument to ft and ift that allows you to take an FT that's unitary in the vector sense -- this way, you don't have to e.g. multiply by dt and divide by the number of points. (This is a standard capability with raw numpy, but we just had not much use for it before) .. GENERATED FROM PYTHON SOURCE LINES 10-48 .. image-sg:: /auto_examples/indiv_funcs/images/sphx_glr_unitary_ft_001.png :alt: time domain, frequency domain :srcset: /auto_examples/indiv_funcs/images/sphx_glr_unitary_ft_001.png, /auto_examples/indiv_funcs/images/sphx_glr_unitary_ft_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python from pylab import * from pyspecdata import * fig, (ax_time, ax_freq) = subplots(2, 1) t = nddata(r_[0:0.5:1e-3], "t2") # 1 kHz SW with a freq. resolution of 1/0.5=2 Hz fake_data = exp(1j * 2 * pi * 100 * t - 10 * t * pi) # 10 Hz wide line at 100 Hz offset fake_data.add_noise(0.1).set_units("t2", "s") logger.info(strm("vector norm of fake data, before ft", linalg.norm(fake_data.data))) plot( fake_data, ax=ax_time, alpha=0.5, label="vector norm=%g" % linalg.norm(fake_data.data), ) ax_time.set_title("time domain") ax_freq.set_title("frequency domain") fake_data.ft("t2", shift=True, unitary=True) logger.info( strm("vector norm of fake data, after unitary ft", linalg.norm(fake_data.data)) ) assert fake_data.get_ft_prop("t2", "dt") == 1e-3 plot( fake_data, ax=ax_freq, alpha=0.5, label="vector norm=%g" % linalg.norm(fake_data.data), ) fake_data.ift( "t2" ) # because we already used "unitary" for the ft, it knows the ift is unitary. # In fact, passing "unitary" as a keyword argument will generate an error here logger.info( strm("vector norm of fake data, after unitary ift", linalg.norm(fake_data.data)) ) ax_time.legend(**dict(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.0)) ax_freq.legend(**dict(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.0)) fig.tight_layout() show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.586 seconds) .. _sphx_glr_download_auto_examples_indiv_funcs_unitary_ft.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: unitary_ft.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: unitary_ft.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_