ifft(fft(x) returns very small imaginary parts when x is real?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ifft(fft(x) returns very small imaginary parts when x is real?

Octave - General mailing list
I have a problem with Octave:

x = dlmread('fin');
y = transpose(x);
z = fft(y);
w = ifft(z);
dlmwrite('fout',w,' ');

fin is real, but fout is complex with all data have very small imaginary
parts.  This seems to be a known bug:
https://savannah.gnu.org/bugs/?45932

Matlab does not have this problem with this same code.  However, while I can
create a script to run fine as a batch job in Octave, I cannot do this in
Matlab?  For example, the first line in an Octave script is
#!/opt/octave/bin/octave -qf
but I have not been able to find the Matlab counterpart.  For example,
#!/opt/matlab/2018a/bin/matlab
just puts me into Matlab instead of running the script.  I have tried
various flags that might be like Octave's "-qf" without success?




-----
https://www.PhysicalStudiesInstitute.org
--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: ifft(fft(x) returns very small imaginary parts when x is real?

Octave - General mailing list

On 05/05/2020 18:29, ingber--- via Help-octave wrote:

> I have a problem with Octave:
>
> x = dlmread('fin');
> y = transpose(x);
> z = fft(y);
> w = ifft(z);
> dlmwrite('fout',w,' ');
>
> fin is real, but fout is complex with all data have very small imaginary
> parts.  This seems to be a known bug:
> https://savannah.gnu.org/bugs/?45932
>
> Matlab does not have this problem with this same code.  However, while I can
> create a script to run fine as a batch job in Octave, I cannot do this in
> Matlab?  For example, the first line in an Octave script is
> #!/opt/octave/bin/octave -qf
> but I have not been able to find the Matlab counterpart.  For example,
> #!/opt/matlab/2018a/bin/matlab
> just puts me into Matlab instead of running the script.  I have tried
> various flags that might be like Octave's "-qf" without success?
>
>
>
>
> -----
> https://www.PhysicalStudiesInstitute.org
> --
> Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>
>

Just use

real(iff(spectrum))

- the small imaginary part is due to rounding errors.

--Sergei.