function Overlap_Add_header_gen(h,N)
% Overlap_Add_header_gen(N)
%
% Creates a header file for an N-point FFT/IFFT function
% file name is OverlapAdd_header_N.h where N the order of the FFT/IFFT
% M=log2(N) which is the number of stages 
% N2 = N/2 which is the number of twiddle factors
% PI is the fixed-point approximation to pi
% 
% This program also creates the header file filter_coeff.h
% The variable h must contain the filter coefficients
% It is assumed that the filter order (P) is less than N/2
% Here, P is the filter order and L is the number of 
% inputs to read in, where L = N-P

M=log2(N);
N2=N/2;

s=['FFT_header.h'];
fid = fopen(s,'w');		            % Open (or create) file

s=['// FFT_header.h\n'];
fprintf(fid,s);                     % Label file

s=['// This file must be included in (I)FFT_func.c\n'];
fprintf(fid,s);                     % Label file

s=['// and by the program that calls (I)FFT_func.c\n\n'];
fprintf(fid,s);                     % Label file

s=['#define N ' num2str(N) '                      // N-point FFT\n'];
fprintf(fid,s);                     % Define N
                                    % where N is the FFT order
s=['#define M ' num2str(M) '                        // M=log2(N)\n'];
fprintf(fid,s);                     % Define M                                   

s=['#define N2 ' num2str(N2) '                       // N/2 (number of twiddle factors)\n'];
fprintf(fid,s);                     % Define N2

s=['#define PI ' num2str(pi,'%11.15g') '        // fixed-point approx. to pi\n\n'];
fprintf(fid,s);                     % Define PI

s=['typedef struct {float real,imag;} COMPLEX;       // structure COMPLEX\n\n'];
fprintf(fid,s);                     % Define COMPLEX

fclose(fid);						% Close FFT_header.h

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create second header file  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

P=length(h)-1;
L=N-P;

s=['filter_coeff.h'];
fid = fopen(s,'w');		            % Open (or create) file

s=['// filter_coeff.h\n'];
fprintf(fid,s);                     % Label file

s=['// This file must be included in Overlap_Add_FIR.c\n\n'];
fprintf(fid,s);  

s=['#define L ' num2str(L) '       // Number of samples to read in\n'];
fprintf(fid,s);                     % Define L

s=['#define P ' num2str(P) '       // Filter order (filter duration minus one)\n\n'];
fprintf(fid,s);                     % Define P

s=['float h[' num2str(P+1) ']=\n{\n'];
fprintf(fid,s);                     % Print "float h[P+1]={" 
                                    % where P+1 is the filter duration

for i=1:P
    fprintf(fid,'%d,' ,h(i));       % Print P points
    if mod(i,6) == 0
        fprintf(fid,'\n');
    end
end
    
fprintf(fid,'%d' ,h(P+1));          % Print (P+1)th point
fprintf(fid,'};\n');                % Print closing bracket                                    
                                    
fclose(fid);						% Close file twiddle.h
