function Faf = frft(f, a)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ozakats 算法说明 %
% The fast Fractional Fourier Transform
% input: f = samples of the signal
% a = fractional power
% output: Faf = fast Fractional Fourier transform %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%error(nargchk(2, 2, nargin));
f = f(:);
N = length(f);
shft = rem((0:N-1)+fix(N/2),N)+1;
sN = sqrt(N);
a = mod(a,4);
% do special cases
if (a==0), Faf = f; return; end;
if (a==2), Faf = flipud(f); return; end;
if (a==1), Faf(shft,1) = fft(f(shft))/sN; return; end
if (a==3), Faf(shft,1) = ifft(f(shft))*sN; return; end
% reduce to interval 0.5 < a < 1.5
if (a>2.0), a = a-2; f = flipud(f); end
if (a>1.5), a = a-1; f(shft,1) = fft(f(shft))/sN; end %幅值归一化 ?
if (a<0.5), a = a+1; f(shft,1) = ifft(f(shft))*sN; end %幅值归一化 ?
% the general case for 0.5 < a < 1.5
alpha = a*pi/2;
tana2 = tan(alpha/2);
sina = sin(alpha);
f = [zeros(N-1,1) ; interp(f) ; zeros(N-1,1)]; % 2倍内插,前后各补N个0,数据长度从N变为4N-3
% chirp premultiplication
chrp = exp(-1i*pi/N*tana2/4*(-2*N+2:2*N-2)'.^2); %% 4N-3点的chirp信号
f = chrp.*f;
% chirp convolution
c = pi/N/sina/4;
Faf = fconv(exp(1i*c*(-(4*N-4):4*N-4)'.^2),f);%% 8N-7个点的chirp与4N-3点的chirp做卷积,变成12N-11点信号
Faf = Faf(4*N-3:8*N-7)*sqrt(c/pi);%% 取中间4N-3点信号
% chirp post multiplication
Faf = chrp.*Faf;
% normalizing constant
Faf = exp(-1i*(1-a)*pi/4)*Faf(N:2:end-N+1); %% 2倍抽取
function xint=interp(x)
% sinc interpolation
N = length(x);
y = zeros(2*N-1,1);
y(1:2:2*N-1) = x; %% 2倍内插,2N-1个点
xint = fconv(y(1:2*N-1), sinc([-(2*N-3):(2*N-3)]'/2)); %% 2N-1个点的y与4N-3个点的sinc做卷
xint = xint(2*N-2:end-2*N+3); %% 取 2N个点
%% 卷积函数
function z = fconv(x,y)
% convolution by fft
N = length([x(:);y(:)])-1; %%
% P = 2^nextpow2(N); %% 离N最近的2的整数次幂
P = 2^nextpow2(N);
z = ifft( fft(x,P) .* fft(y,P)); %% x,y卷积运算,P为FFT点数,为2的指数次幂
z = z(1:N); %%