function y = FFA(x, fold_period)
fold_length = length(x);
y = 0;
if (fold_period ~= fold_length) && (fold_period ~= 0) && (fold_period ~= 1)
r = fold_length / fold_period;
m = log2(2^nextpow2(r));
N = 2^m;
if r < N
x=[x,zeros(1,(N*fold_period - length(x)))];
end
fold_length = length(x);
for mm = 1 : m
Nmr = 2^mm * fold_period;
for n = 1 : Nmr : fold_length
shift_length = 0;
step = 0;
for k = n : fold_period : (Nmr/2+n-1)
kp = k + Nmr/2;
temp1 = cycle_left_shift(x(kp:(kp+fold_period-1)),...
fold_period,shift_length);
temp2 = cycle_left_shift(x(kp:(kp+fold_period-1)),...
fold_period,(shift_length+1));
y((k+step*fold_period):(k+(step+1)*fold_period-1)) =...
x(k:(k+fold_period-1)) + temp1;
y((k+(step+1)*fold_period):(k+(step+2)*fold_period-1)) =...
x(k:(k+fold_period-1)) + temp2;
shift_length = shift_length + 1;
step = step + 1;
end
end
x = y;
end
y = x;
else if fold_period == 1
for i = 1 : fold_length
y(1) = y(1) + x(i);
end
for j = 2 : fold_length
y(j) = y(1);
end
else
y = x;
end
end
end