% function to obtain certainty funtion from response function.
% mann@eecg.toronto.edu
% applies the Octave "diff" operator to get 255 point derivative from 256 points
% and then uses an FFT to interpolate from 255 points to 256 points

function c = convert_Finv_to_c(Finv)

Finv=Finv(2:255); % Remove endpoints

% Add smoothing here
sigma=32.0;
x=-2*sigma:2*sigma;
lx=length(x);
filter=exp(-0.5*(x.^2)/sigma);
filter=filter/sum(filter);
smoothFinv=conv2(Finv, filter', 'valid');
Finv=smoothFinv;

uncertainty = diff(Finv);
certainty = 1../uncertainty;

CERTAINTY=fft(certainty(:));
%CERTAINTY=[CERTAINTY(1:127);0;0;CERTAINTY(129:255)]; % zero out one and pad one
CERTAINTY=[CERTAINTY(1:16);zeros(224,1);CERTAINTY(238:253)];
c=ifft(CERTAINTY(:)).';
c=real(c); % try with certainty function from last run
%figure; plot(1:n,c); title('inverse of uncertainty function')

[M,N]=size(Finv);
if N==1 % input is a column vector so return a column vector
  c=c(:);
end%if
