function [fd, Shift, vf] = find_cent_spect(fdata)
fd = fdata;
N = size(fdata, 1);

% Shift = 0;
% for jj = 1:10
%     V = max(abs(fd), [], 2);
%     shift = floor(N/2) + 1 - round(sum((1:N).'.*V)./sum(V));
%     Shift = Shift + shift;
%     if shift == 0
%         break;
%     end
%     fd = circshift(fd, [shift, 0]);
% end

% for jj = 1:10
%     V = max(abs(fd), [], 2);
%     % V = sum(abs(fd), 2);
%     % shift = floor(N/2) + 1 - round(sum((1:N).'.*V)./sum(V));
%     loc = (0:N - 1) - floor(N/2);
%     shift = -round(sum(loc(:).*V)/sum(V));
%     Shift = Shift + shift;
%     if shift == 0
%         break;
%     end
%     fd = circshift(fdata, [Shift, 0]);
% end

V = max(abs(fd), [], 2);
V = V/max(V)*10;
vec = -100:100;
shift = zeros(1, length(vec));
loc = (0:N - 1) - floor(N/2);
for J = 1:length(vec)
    V1 = circshift(V, vec(J));
    % shift(J) = sum(loc(:).*V1.^1.70);
    shift(J) = sum(loc(:).*V1.^1.00);
end
[~, val] = min(abs(shift));
Shift = vec(val);
vf = circshift(V, vec(val));
fd = circshift(fdata, [Shift, 0]);
