søn, 05 07 2009 kl. 14:10 +0000, skrev Autiwa:
> I modified the .m because I prefer that if fwhm is not defined, that
> fwhm is set to 0. En fact, it happens sometimes that it's a normal
> behaviour for a signal not to have a fwhm. It's disturbing to break
> the run of the program only because of that. I think it's sufficient
> to prompt a warning and set the value to 0. It avoid to have errors in
> the program.
The reason why I changed it is that people tend to complain when they
get a warning, because they cannot easily get rid of it. Errors are
different because you can catch these (using try-catch-blocks). So, I
would say that the function should either return 0 (or something
negative) in which case the behaviour should be documented or raise an
error.
> In addition, I tried to have a syntax that would have allowed someone
> to run it in matlab. But you changed the syntax and now, you can't run
> it under matlab environment.
Oh, I didn't realise you needed Matlab compatibility. Try the attached
version then.
> By the way, you have modified a lot of things so I don't think that
> all credit remain only to me.
I've mostly just inserted spaces to make the code more readable.
> My full name : Christophe Cossou
I've listed you as the author.
Søren
> Le dimanche 05 juillet 2009 à 15:48 +0200, Søren Hauberg a écrit :
> > tor, 02 07 2009 kl. 22:48 +0200, skrev Autiwa:
> > > Ok, I think it's good now :)
> >
> > Thanks. Since nobody has commented, I assume people think your stuff is
> > good :-)
> >
> > I've (hopefully) made the documentation somewhat more clear, and changed
> > the coding-style a bit. Could you check that I haven't broken anything?
> > I'm attaching the code.
> >
> > By the way, what is your full name? I think you should be given credit
> > for the code.
> >
> > Thanks
> > Søren
%% -*- texinfo -*-
%% @deftypefn {Function File} {} fwhm (@var{f})
%% @deftypefnx{Function File} {} fwhm (@var{x}, @var{f})
%% Return the full width at half maximum if a given signal.
%%
%% The full width at half maximum is an expression of the extent of a signal,
%% defined as the difference between the two extremal points of the signal where
%% it equals half of its maximum value.
%%
%% The signal is given by the vector @var{f} with optional @math{x}-values
%% @var{x}. If the latter is not given, it defaults to the indexes of @var{f}.
%%
%% If the full width at half maximum is not defined, the function returns 0.
%% @seealso{std}
%% @end deftypefn
%% This program is public domain.
%% Author: Christophe Cossou
function retval = fwhm (x, f)
%% Check input
if (nargin == 0)
error ('fwhm: not enough input arguments');
elseif (nargin == 1)
f = x;
x = 1:length (f);
end
if (numel (x) != numel (f))
error ('fwhm: number of elements does not match');
end
%% Locate maximum
fmax = max (f);
f_renorm = f - 0.5 * fmax;
ind = find (f_renorm(1:end-1) .* f_renorm (2:end) <= 0);
%% If the product is negative, this means that the 'half-maximum' is between
%% theses two values
if (length (ind) == 2)
%% We make a linear regression between the two values to get a more precise
%% estimation of the fwhm.
x1 = (0.5 * fmax - f (ind (1) + 1)) * (x (ind (1) + 1) - x (ind (1))) ...
/ (f (ind (1) + 1) - f (ind (1))) + x (ind (1) + 1);
x2 = (0.5 * fmax - f (ind (end) + 1)) * (x (ind (end) + 1) - x (ind (end))) ...
/ (f (ind (end) + 1) - f (ind (end))) + x (ind (end) + 1);
retval = x2 - x1;
else
% warning ('fwhm: full width at half maximum is not defined. FWHM is set to 0');
retval = 0;
end
------------------------------------------------------------------------------
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev