⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 read_single_precision_hex.m

📁 mimo2x2天线选择系统的全系统matlab程序,先前的是dsp程序.
💻 M
字号:
function A=read_single_precision_hex(name)
%
% A = read_single_precision(filename)
%
% Read the single precision floating-point values
% stored in a Code Composer Studio .dat file.
% 
% Return value: A = vector containing elements from .dat file

fid = fopen(name,'rt');
x = fscanf(fid,'%d',2);
if x(1) ~= 1651 | x(2) ~= 1
    error('Not a valid hex-format .dat file!')
end

% there is no way to directly convert a string of hex-coded
% bits into the corresponding floating point value
% we have to trick matlab by writing to an intermediate binary
% file

x = fscanf(fid,'%s',3);
x = fscanf(fid,'%c',1);
x = fscanf(fid,'%c');
x = reshape(x,[11 length(x)/11]);
x = x(3:end-1,:);
x = reshape(x,[2 length(x(:))/2]).';
x = hex2dec(x);

% the byte order is reversed => big endian
fid2 = fopen('tmp_rw_file','w+','ieee-be');
fwrite(fid2,x,'uint8');
frewind(fid2);
A = fread(fid2,'float32');

fclose(fid);
fclose(fid2);
delete('tmp_rw_file')

⌨️ 快捷键说明

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