bugGNU Octave - Bugs: bug #65298, fft and ifft produce residual...

 
 

bug #65298: fft and ifft produce residual O(eps) complex values unlike matlab

Submitter:  Pavlo Bobrek <bobrek>
Submitted:  Mon 12 Feb 2024 09:37:15 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Duplicate Assigned to:  None
Originator Name:  bobrek Open/Closed:  * Closed
Release:  * 8.4.0 Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 13 Feb 2024 03:13:02 AM UTC, comment #8: 

yes, i thought this sounded familiar.  also, that report points to bug #43742, which was resurrected again just this past august with a refreshed patch.  It seems that conjugate symmetric input should follow a streamlined code path and result in a real output.

closing this report as a duplicate.  perhaps some attention on those other two 2014/2015 reports could get fixes into Octave 10?

Nicholas Jankowski <nrjank>
Group Member
Tue 13 Feb 2024 02:54:09 AM UTC, comment #7: 
Dmitri A. Sergatskov <dasergatskov>
Tue 13 Feb 2024 12:33:40 AM UTC, comment #6: 

" Is the 'residual imaginary parts' a known issue with octave's fft/ifft? "

I have some vague recollection that this comes up every 10 years or so and dismissed as "such as life". FFTW now days comes with
long double and quad precision which should probably help with this issue (though they probably will be slower).

Dmitri.
--



Dmitri A. Sergatskov <dasergatskov>
Mon 12 Feb 2024 11:14:48 PM UTC, comment #5: 

Fftw library.

Anonymous
Mon 12 Feb 2024 10:07:00 PM UTC, comment #4: 

saving the output h as a mat file and loading it into matlab 2023b, it can confirm that

matlab2023b:

>> max(imag(ifft(fft(h))))

ans =

     0

>> isreal(ifft(fft(h)))

ans =

  logical

   1


octave 9.0.1:

>> max(imag(ifft(fft(h))))
ans = 2.276170624955701e-17

>> isreal(ifft(fft(h)))
ans = 0


which as Dmitri said, triggers the alternate plotting method.

Is the 'residual imaginary parts' a known issue with octave's fft/ifft? is the issue with the fft or the ifft? and assuming this is a new bug, what would be a better retitle?

Nicholas Jankowski <nrjank>
Group Member
Mon 12 Feb 2024 10:03:11 PM UTC, comment #3: 

The function does not really matter. You can do something like:

octave:14> x = linspace(0,20,1001);
octave:15> y = cos(x)./sqrt(x+1);
octave:16> figure(1)
octave:17> plot(y)
octave:18> figure(2)
octave:19> plot(ifft(fft(y)))

Note, that if you do plot(x,y) and plot(x, ifft(fft(y)) it would be fine too.

Dmitri.
--


Dmitri A. Sergatskov <dasergatskov>
Mon 12 Feb 2024 09:51:51 PM UTC, comment #2: 

can't compare with current matlab, as matlab2023b produces:


>> [h, sT] = rcosfir(0.2,[-6 6], 64, 1, 'sqrt');
Error using rcosfir
rcosfir has been removed. Use rcosdesign instead.

>> [h, sT] = rcosdesign(0.2,[-6 6], 64, 1, 'sqrt');
Error using rcosdesign
Too many output arguments.


Assuming the octave package plans to retain the function for backward compatibility, it would be useful if you could include examples of your expected matlab output (numeric and graphical if possible.) along with the version that generated it.

Nicholas Jankowski <nrjank>
Group Member
Mon 12 Feb 2024 09:48:57 PM UTC, comment #1: 

Try plot(real(ifft(fft(h))).
There is a imaginary spillage of the order of eps, and
plot(z) where z is a complex number is equivalent of
plot(real(a), imag(a))

Dmitri.
--



Dmitri A. Sergatskov <dasergatskov>
Mon 12 Feb 2024 09:37:15 PM UTC, original submission:  


pkg load signal
pkg load communicatons
[h, sT] = rcosfir(0.2,[-6 6], 64, 1, 'sqrt');
figure(1)
plot(h)
figure(2)
plot(ifft(fft(h)))

figure(1) and figure(2) should be the same. They are not even close.

Pavlo Bobrek <bobrek>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Carbon-Copy List
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by bobrek (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-02-13 nrjank Dependencies- Depends on bugs #45932
        Dependencies- Depends on bugs #43742
    2024-02-13 nrjank StatusNeed Info Duplicate
        Open/ClosedOpen Closed
    2024-02-12 nrjank Summaryfft and ifft do not work correctly and do not agree with Matlab fft and ifft produce residual O(eps) complex values unlike matlab
    2024-02-12 nrjank StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code