MATLAB实现截位的问题
讨论MATLAB怎样提取10进制中的位的方法,因为做FFT时要用到截位,相去验证它,向同庆请教,
原来只是除以2的N次方,取模取余就行了,可恨我还想了一下午,也没有一个好办法。
接下来的问题是,对于负数我该怎么处理。
无论是有符号还是无符号数,如果做加减的话,都可以当做无符号数处理。但对于乘法运算则不然。
而蝶形运算是有乘法的,所以不能简单做为无符号数处理。具体实现过程如下:
%%=============================================================================
%%对第一级的输出进行截位处理
%%==============================================================================
%先转换成16进制,再换成10进制,把有符号数据转换成无符号,其实不用这么麻烦的。直接用下面的程序即可。
%Stg1_OutData1_Real = Stg1_OutData1_Real+2^34*(Stg1_OutData1_Real < 0);
%Stg1_OutData2_Real = Stg1_OutData2_Real+2^34*(Stg1_OutData2_Real < 0);
%Stg1_OutData1_Imag = Stg1_OutData1_Imag+2^34*(Stg1_OutData1_Imag < 0);
%Stg1_OutData2_Imag = Stg1_OutData2_Imag+2^34*(Stg1_OutData2_Imag < 0);
Stg1_OutData1_Real = dec2hex(Stg1_OutData1_Real+2^34*(Stg1_OutData1_Real < 0),9);
Stg1_OutData2_Real = dec2hex(Stg1_OutData2_Real+2^34*(Stg1_OutData2_Real < 0),9);
Stg1_OutData1_Imag = dec2hex(Stg1_OutData1_Imag+2^34*(Stg1_OutData1_Imag < 0),9);
Stg1_OutData2_Imag = dec2hex(Stg1_OutData2_Imag+2^34*(Stg1_OutData2_Imag < 0),9);
% end;
Stg1_OutData1_Real = hex2dec(Stg1_OutData1_Real);
Stg1_OutData2_Real = hex2dec(Stg1_OutData2_Real);
Stg1_OutData1_Imag = hex2dec(Stg1_OutData1_Imag);
Stg1_OutData2_Imag = hex2dec(Stg1_OutData2_Imag);
%trancate process
%截去低16位
%提取中间16位
Stg1_OutData1_Real = floor(Stg1_OutData1_Real/2^16);
Stg1_OutData1_Real = mod(Stg1_OutData1_Real,2^16);
%截去低16位
%提取中间16位
Stg1_OutData2_Real = floor(Stg1_OutData2_Real/2^16);
Stg1_OutData2_Real = mod(Stg1_OutData2_Real,2^16);
%截去低16位
%提取中间16位
Stg1_OutData1_Imag = floor(Stg1_OutData1_Imag/2^16);
Stg1_OutData1_Imag = mod(Stg1_OutData1_Imag,2^16);
%截去低16位
%提取中间16位
Stg1_OutData2_Imag = floor(Stg1_OutData2_Imag/2^16);
Stg1_OutData2_Imag = mod(Stg1_OutData2_Imag,2^16);
for i= 1:32
if bitget(Stg1_OutData1_Real(i),16) == 1
Stg1_OutData1_Real(i) = Stg1_OutData1_Real(i) - 2^16;
else
Stg1_OutData1_Real(i) = Stg1_OutData1_Real(i);
end;
if bitget(Stg1_OutData2_Real(i),16) == 1
Stg1_OutData2_Real(i) = Stg1_OutData2_Real(i) - 2^16;
else
Stg1_OutData2_Real(i) = Stg1_OutData2_Real(i);
end;
if bitget(Stg1_OutData1_Imag(i),16) == 1
Stg1_OutData1_Imag(i) = Stg1_OutData1_Imag(i) - 2^16;
else
Stg1_OutData1_Imag(i) = Stg1_OutData1_Imag(i);
end;
if bitget(Stg1_OutData2_Imag(i),16) == 1
Stg1_OutData2_Imag(i) = Stg1_OutData2_Imag(i) - 2^16;
else
Stg1_OutData2_Imag(i) = Stg1_OutData2_Imag(i);
end;
end;
%%===================================================
%%======================================================
a=1.23456789
roundn(a,-4)
提取10进制中的某一位
bitget