MATLAB: Zero values of a fitted curve

fitted curvefnzerosfourier serieszero crossing

Hi to everybody, i have a time history dataset that i have fitted with a fourier series to find its peaks. Now i am in need of the zero crossing values of the curve, and as output the corresponding values of time of these zero crossing. Is there a function that does it automatically? I have tried with fnzeros but seems not to work for fitted curves but only for functions, am i wrong? Maybe i'm missing some statement in the code. Waiting for someone's reply i would thank in advance those willing to help me 😀

Best Answer

There's a paper by Prof. Boyd from the University of Michigan that appears to address this:
"Computing the zeros, maxima and inflection points of Chebyshev, Legendre and Fourier series: solving transcendental equations by spectral interpolation and polynomial rootfinding" http://link.springer.com/article/10.1007%2Fs10665-006-9087-5#page-1
I think this does what you want (not that the roots of the fourier series are given in the variable t):
% fourier coefficients
% (dummy data)
a = [1, 1, 1, 1];
b = [0, 0, 1, 0];
% Note:
% a(1) corresponds to a_0 in the reference
% a(2:end) corresponds to a(1:N) in the reference;
N = numel(a) - 1;
h = [a(end:-1:2) + 1i*b(end:-1:2), 2*a(1), (a(2:end) - 1i*b(2:end))];
B = diag(ones(2*N - 1, 1), 1);
B(end, :) = -h(1:end - 1)/(a(end) - 1i*b(end));
z = eig(B);
t = angle(z);
% note: duplicate t's are imgaginary roots
% eliminate duplicates within tolerance
tol = 10*eps;
t = sort(t);
ind = find(diff(t)./abs(t(2:end)) < tol);
ind = [ind; ind + 1];
t(ind(:)) = [];
% plot results
% f = ugly inline fourier series anonymous function
f = @(x, a, b) sum(bsxfun(@times, a(:).', cos(x(:)*(0:numel(a) - 1))) + bsxfun(@times, b(:).', sin(x(:)*(0:numel(b)-1))), 2);
x = linspace(-pi, pi, 128 + 1);
hf = figure;
ha = axes;
axis([-pi, pi, -sum(a+b)-0.5, sum(a+b)+0.5]);
hold(ha, 'on');
plot(x, f(x, a, b));
plot(t, f(t, a, b), 'o');
plot([-pi, pi], [0, 0], '--c');
I probably won't be around much in the next two days, but feel free to leave a comment, and I'll try to get back to you.