Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug producing infrequent NaN from calcnaff #587

Merged
merged 2 commits into from
Mar 29, 2023

Conversation

pcsch
Copy link
Contributor

@pcsch pcsch commented Mar 28, 2023

Dear all,

This pull request concerns MATLAB.
As noted in #40 calcnaff sometimes produces NaN values even though the input is valid and a second run does result in valid frequencies.
The problem is that the interface between MATLAB and the NAFF algorithm did no write to the last element of the
complex input to NAFF.
This pull request fixes that.

In my tests this also fixed the fluctuating results from run to run (e.g. phase) seen in #40 as well.

Fixes #40

Copy link
Contributor

@lfarv lfarv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Any comment @lnadolski ?

Comment on lines -74 to -81
%It seems there is a bug in nafflib, something returns nan even for valid data
niter = 0;
while any(isnan(frequency)) && (niter < nitermax)
pause(2);
fprintf('Warning Nan returned by NAFF (x%d)\n', niter);
niter = niter +1;
[frequency,amplitude,phase] = nafflib(Y, Yp, WindowType,nfreq,1); % add debugging
end
Copy link
Contributor

@lfarv lfarv Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So apparently, up to now, if the output is wrong, we try again until it gets right !
This looks crazy, your fix is really welcome, @pcsch !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line #7 should become
2. Yp - angle vector

Line 36 should become
NT = 9996; % divisible by 6

line #60
elseif any(isnan(Y(1,:)))
should read
elseif any(isnan(Yp(1,:)))

@lfarv lfarv requested a review from lnadolski March 28, 2023 20:22
The second test for NaN was wrong Y was replaced by Yp
Copy link
Contributor

@lnadolski lnadolski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart 3 small modifications in calcnaff, this looks fine for me.

Comment on lines -74 to -81
%It seems there is a bug in nafflib, something returns nan even for valid data
niter = 0;
while any(isnan(frequency)) && (niter < nitermax)
pause(2);
fprintf('Warning Nan returned by NAFF (x%d)\n', niter);
niter = niter +1;
[frequency,amplitude,phase] = nafflib(Y, Yp, WindowType,nfreq,1); % add debugging
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line #7 should become
2. Yp - angle vector

Line 36 should become
NT = 9996; % divisible by 6

line #60
elseif any(isnan(Y(1,:)))
should read
elseif any(isnan(Yp(1,:)))

@lfarv lfarv self-requested a review March 29, 2023 07:32
Copy link
Contributor

@lfarv lfarv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK again ! Thanks @pcsch and @lnadolski

@lfarv lfarv merged commit 5c287fd into atcollab:master Mar 29, 2023
@lfarv lfarv added Matlab For Matlab/Octave AT code bug fix labels Mar 29, 2023
@lfarv lfarv mentioned this pull request Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Matlab For Matlab/Octave AT code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nafflib problems
3 participants