1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| function [] = printbinary(x,B,fname)
%PRINTBINARY print values of vector x in binary form into file fname.txt
% PRINTBINARY takes values of vector x,converts them to B bit two's complement
% binary format, and then prints the binary representation to the file
% "fname.txt".This i s used to print the coefficients of the
% decimating polyphase filter (s) in the intermediate frequency to baseband
% conversion process to afile so that they can be used to load the ROM
% modules in the VHDL implementation.
%
% INPUT ARGUMENTS
% - x - the vector that you desire to print in binary format
% - B - the number of bits in the binary representation
% - fname - a string representing the file where you want the data to
% be written to
fid=fopen([fname,'.txt' ],'wt'); % open a file in write mode
x=dec2bin(x,B); % convert elements of vector into B-bit binary
[row col]=size(x); % calculate number of rows and columns in binary ve c tor
for i=1:row % loop through rows
for j=1:col
if (x(i,j )=='/') % if number is negative, convert'/'s to 1's
x(i,j)='1';
end
fprintf(fid,'%c ',x(i,j)); % print elements of vector to a file,one character at a time
end
fprintf(fid ,'%c\n ',' '); % print a newline character to the file
end
fclose (fid); % close the file |
Partager