Matlab单精度数据转换成IEEE754单精度数据及误差分析
考虑四种转换方式
1、 Matlab中默认的Double类型转换为IEEE单精度,在求分数部分的值时,四舍五入采用floor方式。
2、 Matlab中默认的Double类型转换为IEEE单精度,在求分数部分的值时,四舍五入采用Round方式。
3、 Matlab中默认的Single类型转换为IEEE单精度,在求分数部分的值时,四舍五入采用floor方式。
4、 Matlab中默认的Single类型转换为IEEE单精度,在求分数部分的值时,四舍五入采用Round方式。
以第四种方式作为参考,取10000点Hann窗系数作为测试数据,比较几种方式得到结果的差异。
Matlab代码如下
PointNum=5000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
WindowCoe_Double=hann(PointNum,‘symmetric’);
WindowCoe_Single=zeros(1,length(WindowCoe_Double),‘single’);
for iteration=1:length(WindowCoe_Double)
WindowCoe_Single(iteration)=single(WindowCoe_Double(iteration));
end
Coe_SingleRound_Dec=zeros(1,length(WindowCoe_Single));
Coe_SingleFloor_Dec=zeros(1,length(WindowCoe_Single));
WindowCoe_SingleRound_Dec=zeros(1,length(WindowCoe_Single),‘single’);
WindowCoe_SingleFloor_Dec=zeros(1,length(WindowCoe_Single),‘single’);
for iteration=1:length(WindowCoe_Single)
Coe_SingleRound_Dec(iteration)=Single_Round2Dec32_IEEE754(WindowCoe_Single(iteration)); WindowCoe_SingleRound_Dec(iteration)=Dec32_IEEE754ToSingle(Coe_SingleRound_Dec(iteration));
Coe_SingleFloor_Dec(iteration)=Single_Floor2Dec32_IEEE754(WindowCoe_Single(iteration));
WindowCoe_SingleFloor_Dec(iteration)=Dec32_IEEE754ToSingle(Coe_SingleFloor_Dec(iteration));
end
Coe_DoubleRound_Dec=zeros(1,length(WindowCoe_Double));
Coe_DoubleFloor_Dec=zeros(1,length(WindowCoe_Double));
WindowCoe_DoubleRound_Dec=zeros(1,length(WindowCoe_Double));
WindowCoe_DoubleFloor_Dec=zeros(1,length(WindowCoe_Double));
for iteratio