function writeQFcoeff(in, filename, f, numbits) % This function takes an input vector and writes the coefficients to a % txt file with a format ready to import in to QF software % If no arguments are present, print the help if nargin == 0 disp('The writeQFcoeff function takes two or four input arguments') disp('and writes a file out that is formatted for import into') disp('QuickFilter software.') disp(' ') disp('USEAGE #1: Floating point output') disp('writeQFcoeff(INPUT, FILENAME)') disp('INPUT is the name of the vector to be written') disp('FILENAME is the name of the file to be written') disp(' ') disp('EXAMPLE:') disp('writeQFcoeff(num, ''num.txt'')') disp(' ') disp('USEAGE #2: Fixed point output') disp('writeQFcoeff(INPUT, FILENAME, FIXED, NUMBER BITS)') disp('INPUT is the name of the vector to be written') disp('FILENAME is the name of the file to be written') disp('FIXED indicated that the output should be fixed-point') disp('NUMBER BITS is the number of bits to use in the fixed-point output') disp(' ') disp('EXAMPLE:') disp('writeQFcoeff(num, ''num.txt'', ''fixed'', 32)') elseif (nargin == 2) % Floating point output fid = fopen(filename, 'wt'); for i = 1:length(in) fprintf(fid, '%-1.15f\n',in(i)); end fclose(fid); return elseif (nargin == 4) % Fixed point output % Convert the output to 2's complement fixed point with numbits bits i = find((in < -1) | (in >= 1)); if isempty(i) y = floor(2^(numbits-1) * in); index = find(y < 0); y(index) = 2^numbits + y(index); else error('error: floating number must be in [-1,1)') return; end % Save to txt file formatting = ['%0' num2str(numbits/4) 'X']; fid = fopen(filename, 'wt'); for i = 1:length(y) fprintf(fid, [formatting '\n'] ,y(i)); end fclose(fid); return else error('Number of input arguments must be 2 or 4.') return end