write_int16_hex.m

来自「mimo2x2天线选择系统的全系统matlab程序,先前的是dsp程序.」· M 代码 · 共 31 行

M
31
字号
function write_int16_hex(name,A)
%
% write_int16_hex(name,A)
%
% Write elements of matrix A in .dat format, suitable for loading
% into Code Composer Studio.
%
% Elements are rounded to to 16-bit signed integer format
% and the values are stored in hex-format (little endian)

A=A(:).';
N=length(A);
if mod(N,2)
    A(end+1)=0; % hex format stores 32 bit words, zero-pad to even length
    N = N+1;
end

% convert to double and/or round to nearest integer
A=double(int16(A));

if any(A>2^15-1 | A<-2^15)
    error('One or more values are out of range')
end

% change order to compensate for endianess difference
A = [A(2:2:end); A(1:2:end)];

fid = fopen(name,'wt');
fprintf(fid,'1651 1 0 0 %X\n',N);
fprintf(fid,'0x%04X%04X\n',A + (A<0)*2^16);
fclose(fid);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?