Pregunta

I am porting a Matlab/Octave code to C. One of the implementations I need to port is the DST transform. In Matlab/Octave, this is done using

A =[0.00000   4.24264   5.65685   7.07107   8.48528   0.00000]
res = dst(A)
ans =
22.3599   -4.7499   -4.4287    2.9465   -6.8864    1.9383

In C, I have done what the FFTW3 documentation says:

n = 6;
fftw_plan plan = fftw_plan_r2r_1d( n, in, out, FFTW_RODFT10, FFTW_ESTIMATE);
fftw_execute ( plan );

where in is the input array. The result of this is, out:

 42.588457
-9.899495
 0.000000
 2.449490
-11.411543
 5.656854

Why are those results so different? Any ideas of what I am doing wrong here, if any?

¿Fue útil?

Solución

If you are looking for exactly the same tranform, you may try the RODFT00 flag instead.

According to docs of fftw, matlab, octave, it seems to fit, except for a 2 factor. Output of fftw may be twice the one of matlab or octave.

http://www.mathworks.fr/fr/help/pde/ug/dst.html

http://octave.sourceforge.net/signal/function/dst.html

http://www.fftw.org/doc/1d-Real_002dodd-DFTs-_0028DSTs_0029.html

Bye,

Otros consejos

tried this x=[ 0 -0.041389004581424 -0.049979175343607 -0.057007496876302 -0.062473969179509 -0.066378592253228 -0.068721366097459 -0.069502290712203 -0.068721366097459 -0.066378592253228 -0.062473969179509 -0.057007496876302 -0.049979175343607 -0.041389004581424 0.500000000000000 -0.500000000000000]

matlab's dst gives : dst(x)=[-0.524649937006448 -0.208549082037091 0.175438242940290 -0.201365706563574 0.122632326416342 0.023410695189363 -0.170916792532103 0.404635063593086 -0.557336293807673 0.766827077578399 -0.834391996423464 0.916008576298954 -0.836787527646708 0.743037852780101 -0.522660424688284 0.285317021943821]

using FFTW with "FFTW_RODFT00" flag gives [-1.0493 -0.417098 0.350876 -0.402731 0.245265 0.0468214 -0.341834 0.80927 -1.11467 1.53365 -1.66878 1.83202 -1.67358 1.48608 -1.04532 0.570634]

Basically a factor of two is the difference, even if one uses same flag

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top