k-Wave User Forum » Topic: Creating my own HDF5 input file: calculation of ddx_k_shift_pos_r
http://www.k-wave.org/forum/topic/creating-my-own-hdf5-input-file-calculation-of-ddx_k_shift_pos_r
Support for the k-Wave MATLAB toolboxen-USThu, 08 Aug 2024 20:12:37 +0000http://bbpress.org/?v=1.0.2<![CDATA[Search]]>q
http://www.k-wave.org/forum/search.php
Anthony on "Creating my own HDF5 input file: calculation of ddx_k_shift_pos_r"
http://www.k-wave.org/forum/topic/creating-my-own-hdf5-input-file-calculation-of-ddx_k_shift_pos_r#post-3756
Wed, 26 Jun 2013 14:58:19 +0000Anthony3756@http://www.k-wave.org/forum/<p>Hi everyone,</p>
<p>Just a little precision that might save some time if someone needs to do the same : as ddx_k_shift_pos_r (and its family) are complex values, you need to be careful when saving it with matlab into a HDF5 file.</p>
<p>The sequence must be stored as :</p>
<p>[real(ddx_k_shift_pos_r(1), imag(ddx_k_shift_pos_r(1),... ,real(ddx_k_shift_pos_r(Nx_r), imag(ddx_k_shift_pos_r(Nx_r)]. </p>
<p>i.e. a vector of size 2*Nx_r.</p>
<p>Anthony</p>
<p>PS : another trick (not related to ddx_k_shift_pos_r), don't forget to scale the source terms as explained in "kspaceFirstOrder_scaleSourceTerms.m".
</p>Anthony on "Creating my own HDF5 input file: calculation of ddx_k_shift_pos_r"
http://www.k-wave.org/forum/topic/creating-my-own-hdf5-input-file-calculation-of-ddx_k_shift_pos_r#post-3741
Fri, 21 Jun 2013 10:44:17 +0000Anthony3741@http://www.k-wave.org/forum/<p>Thanks for your explanation, </p>
<p>it seems to work now!</p>
<p>Anthony
</p>Bradley Treeby on "Creating my own HDF5 input file: calculation of ddx_k_shift_pos_r"
http://www.k-wave.org/forum/topic/creating-my-own-hdf5-input-file-calculation-of-ddx_k_shift_pos_r#post-3736
Thu, 20 Jun 2013 22:33:58 +0000Bradley Treeby3736@http://www.k-wave.org/forum/<p>Hi Anthony,</p>
<p>The formulae you mention are for when the staggered grid scheme is not used. This is an undocumented option that is only used for testing. The lines of code you need are directly above these, where</p>
<pre><code>ddx_k_shift_pos = ifftshift( 1i*kgrid.kx_vec .* exp(1i*kgrid.kx_vec*kgrid.dx/2) );
ddx_k_shift_neg = ifftshift( 1i*kgrid.kx_vec .* exp(-1i*kgrid.kx_vec*kgrid.dx/2) );
...</code></pre>
<p>The difference between _neg and _pos is the direction of the spatial shift term (negative or positive). The _r suffix is used to show that only the first half of the Fourier data in the x-dimension is stored (see the _saveToDisk code for more details). This is because the FFT routine used in the C++ code is the real-to-complex FFT. This doesn't calculate the redundant part of the output for the FFT over the first dimension.</p>
<p>Hope that helps!</p>
<p>Brad.
</p>Anthony on "Creating my own HDF5 input file: calculation of ddx_k_shift_pos_r"
http://www.k-wave.org/forum/topic/creating-my-own-hdf5-input-file-calculation-of-ddx_k_shift_pos_r#post-3734
Thu, 20 Jun 2013 16:43:31 +0000Anthony3734@http://www.k-wave.org/forum/<p>Hi everyone,</p>
<p>I am currently trying to write my own HDF5 input file for the C++ code and I only have a problem with ddx_k_shift_pos_r and its family (ddx_k_shift_neg_r, ddy_k_shift_pos, ddy_k_shift_neg etc...).</p>
<p>How to compute it? I have only found this formula in the matlab code (in kspaceFirstOrder3D.m):<br />
ddy_k_shift_pos = ifftshift( 1i*kgrid.ky_vec );<br />
ddy_k_shift_neg = ifftshift( 1i*kgrid.ky_vec );</p>
<p>More precisely, I have 3 questions:<br />
- it does not give the same result as when I read an input file created with kspaceFirstOrder_saveToDisk.m what makes me feel that my formula is not the right one, but I don't see anything else in the code...<br />
- what is the difference between ..._neg and ..._pos?<br />
- why is there a ..._r suffix along the x dimension? Is the formula different?</p>
<p>Sorry for the question, but I have fought with this the whole afternoon.<br />
Regards,<br />
Anthony
</p>