function y = fft127(x,u,ip,op)
% y = fft127(x,u,ip,op)
% y  : the 127 point DFT of x 
% u  : a vector of precomputed multiplicative constants
% ip : input permutation
% op : ouput permutation

y = zeros(127,1);
x = x(ip);                                        % input permutation
x(2:127) = KRED([2,3,7],[1,2,1],3,x(2:127));      % reduction operations
y(1) = x(1)+x(2);                                 % DC term calculation
% -------------------- block : 1 -------------------------------------------------
y(2) = x(2)*u(1);                       
% -------------------- block : 2 -------------------------------------------------
y(3) = x(3)*u(2);                       
% -------------------- block : 3 -------------------------------------------------
v = ID2I(1,1,x(4:5));              % v = (I(1) kron D2 kron I(1)) * x(4:5)
v = v.*u(3:5);                          
y(4:5) = ID2tI(1,1,v);             % y(4:5) = (I(1) kron D2' kron I(1)) * v
% -------------------- block : 6 = 2 * 3 -----------------------------------------
v = ID2I(1,1,x(6:7));              % v = (I(1) kron D2 kron I(1)) * x(6:7)
v = v.*u(6:8);                          
y(6:7) = ID2tI(1,1,v);             % y(6:7) = (I(1) kron D2' kron I(1)) * v
% -------------------- block : 9 -------------------------------------------------
v = ID3I(2,1,x(8:13));             % v = (I(2) kron D3 kron I(1)) * x(8:13)
v = ID2I(1,5,v);                   % v = (I(1) kron D2 kron I(5)) * v
v = v.*u(9:23);                         
v = ID2tI(1,5,v);                  % v = (I(1) kron D2' kron I(5)) * v
y(8:13) = ID3tI(2,1,v);            % y(8:13) = (I(2) kron D3' kron I(1)) * v
% -------------------- block : 18 = 2 * 9 ----------------------------------------
v = ID3I(2,1,x(14:19));            % v = (I(2) kron D3 kron I(1)) * x(14:19)
v = ID2I(1,5,v);                   % v = (I(1) kron D2 kron I(5)) * v
v = v.*u(24:38);                        
v = ID2tI(1,5,v);                  % v = (I(1) kron D2' kron I(5)) * v
y(14:19) = ID3tI(2,1,v);           % y(14:19) = (I(2) kron D3' kron I(1)) * v
% -------------------- block : 7 -------------------------------------------------
v = ID3I(2,1,x(20:25));            % v = (I(2) kron D3 kron I(1)) * x(20:25)
v = ID2I(1,5,v);                   % v = (I(1) kron D2 kron I(5)) * v
v = v.*u(39:53);                        
v = ID2tI(1,5,v);                  % v = (I(1) kron D2' kron I(5)) * v
y(20:25) = ID3tI(2,1,v);           % y(20:25) = (I(2) kron D3' kron I(1)) * v
% -------------------- block : 14 = 2 * 7 ----------------------------------------
v = ID3I(2,1,x(26:31));            % v = (I(2) kron D3 kron I(1)) * x(26:31)
v = ID2I(1,5,v);                   % v = (I(1) kron D2 kron I(5)) * v
v = v.*u(54:68);                        
v = ID2tI(1,5,v);                  % v = (I(1) kron D2' kron I(5)) * v
y(26:31) = ID3tI(2,1,v);           % y(26:31) = (I(2) kron D3' kron I(1)) * v
% -------------------- block : 21 = 3 * 7 ----------------------------------------
v = ID3I(4,1,x(32:43));            % v = (I(4) kron D3 kron I(1)) * x(32:43)
v = ID2I(1,10,v);                  % v = (I(1) kron D2 kron I(10)) * v
v = ID2I(3,5,v);                   % v = (I(3) kron D2 kron I(5)) * v
v = v.*u(69:113);                       
v = ID2tI(1,15,v);                 % v = (I(1) kron D2' kron I(15)) * v
v = ID2tI(2,5,v);                  % v = (I(2) kron D2' kron I(5)) * v
y(32:43) = ID3tI(4,1,v);           % y(32:43) = (I(4) kron D3' kron I(1)) * v
% -------------------- block : 42 = 2 * 3 * 7 ------------------------------------
v = ID3I(4,1,x(44:55));            % v = (I(4) kron D3 kron I(1)) * x(44:55)
v = ID2I(1,10,v);                  % v = (I(1) kron D2 kron I(10)) * v
v = ID2I(3,5,v);                   % v = (I(3) kron D2 kron I(5)) * v
v = v.*u(114:158);                      
v = ID2tI(1,15,v);                 % v = (I(1) kron D2' kron I(15)) * v
v = ID2tI(2,5,v);                  % v = (I(2) kron D2' kron I(5)) * v
y(44:55) = ID3tI(4,1,v);           % y(44:55) = (I(4) kron D3' kron I(1)) * v
% -------------------- block : 63 = 9 * 7 ----------------------------------------
v = ID3I(2,6,x(56:91));            % v = (I(2) kron D3 kron I(6)) * x(56:91)
v = ID3I(20,1,v);                  % v = (I(20) kron D3 kron I(1)) * v
v = ID2I(1,50,v);                  % v = (I(1) kron D2 kron I(50)) * v
v = ID2I(15,5,v);                  % v = (I(15) kron D2 kron I(5)) * v
v = v.*u(159:383);                      
v = ID2tI(1,75,v);                 % v = (I(1) kron D2' kron I(75)) * v
v = ID2tI(10,5,v);                 % v = (I(10) kron D2' kron I(5)) * v
v = ID3tI(2,10,v);                 % v = (I(2) kron D3' kron I(10)) * v
y(56:91) = ID3tI(12,1,v);          % y(56:91) = (I(12) kron D3' kron I(1)) * v
% -------------------- block : 126 = 2 * 9 * 7 -----------------------------------
v = ID3I(2,6,x(92:127));           % v = (I(2) kron D3 kron I(6)) * x(92:127)
v = ID3I(20,1,v);                  % v = (I(20) kron D3 kron I(1)) * v
v = ID2I(1,50,v);                  % v = (I(1) kron D2 kron I(50)) * v
v = ID2I(15,5,v);                  % v = (I(15) kron D2 kron I(5)) * v
v = v.*u(384:608);                      
v = ID2tI(1,75,v);                 % v = (I(1) kron D2' kron I(75)) * v
v = ID2tI(10,5,v);                 % v = (I(10) kron D2' kron I(5)) * v
v = ID3tI(2,10,v);                 % v = (I(2) kron D3' kron I(10)) * v
y(92:127) = ID3tI(12,1,v);         % y(92:127) = (I(12) kron D3' kron I(1)) * v
% --------------------------------------------------------------------------------
y(2) = y(1)+y(2);                                 % DC term calculation
y(2:127) = tKRED([2,3,7],[1,2,1],3,y(2:127));     % transpose reduction operations
y = y(op);                                        % output permutation

% For complex data - 
% Total Number of Real Multiplications : 1216
% Total Number of Real Additions: 6760

