?? float2qnm.m
字號:
function [num_fixed] = float2qnm (num_float, n, m);
% File name: float2qnm.m
%
% Description: mat lab routine for converting a signed
% floating point number into its equivalent signed Qn.m
% format fixed point number.
%num_float: floating point number to be converted into Qn.m
% Fixed-point format
% n: num of bits to the left of the decimal point with MSB
% as signed bit
% m: number of bits to the right of the decimal point
% num_fixed: converted signed fixed-point number in Qn.m format
% Total number of bits in the fixed-point representation
N = n+m;
% change number into fixed-point number
num_fixed = fix (num_float* 2^m);
% saturate if the number is greater than the max positive
% represent able number or less than the min negative
% represent-able number in signed Qn.m format
if num_fixed > 2^(N-1) - 1
num_fixed = 2^(N-1) - 1;
else if num_fixed < - 2^(N-1)
num_fixed = 2^(N-1);
end
% if negative, compute its 2?s complement by first
% inverting all bits
% of the magnitude of the number and than adding one to it
if num_fixed < 0
num_fixed = bitxor (2^N-1, abs(num_fixed)) + 1;
dec2hex (num_fixed);
end
% extract N bits
num_fixed = bitand(num_fixed, 2^N - 1);
end
% function [num_fixed] = float2qnm (num_float, n, m);
% % File name: float2qnm.m
% %
% % Description: mat lab routine for converting a signed
% % floating point number into its equivalent signed Qn.m
% % format fixed point number.
% %num_float: floating point number to be converted into Qn.m
% % Fixed-point format
% % n: num of bits to the left of the decimal point with MSB
% % as signed bit
% % m: number of bits to the right of the decimal point
% % num_fixed: converted signed fixed-point number in Qn.m format
% % Total number of bits in the fixed-point representation
% N = n+m;
% % change number into fixed-point number
% num_fixed = fix (num_float* 2^m);
% % saturate if the number is greater than the max positive
% % represent able number or less than the min negative
% % represent-able number in signed Qn.m format
% if num_fixed > 2^(N-1) - 1
% num_fixed = 2^(N-1) - 1;
% else if num_fixed < - 2^(N-1)
% num_fixed = 2^(N-1);
% end
% % if negative, compute its 2?s complement by first
% % inverting all bits
% % of the magnitude of the number and than adding one to it
% if num_fixed < 0
% num_fixed = bitxor (2^N-1, abs(num_fixed)) + 1;
% dec2hex (num_fixed);
% end
% % extract N bits
% num_fixed = bitand(num_fixed, 2^N - 1);
% end
% function [num_fixed] = float2qnm (num_float, n, m);
% % File name: float2qnm.m
% %
% % Description: mat lab routine for converting a signed
% % floating point number into its equivalent signed Qn.m
% % format fixed point number.
% %num_float: floating point number to be converted into Qn.m
% % Fixed-point format
% % n: num of bits to the left of the decimal point with MSB
% % as signed bit
% % m: number of bits to the right of the decimal point
% % num_fixed: converted signed fixed-point number in Qn.m format
% % Total number of bits in the fixed-point representation
% N = n+m;
% % change number into fixed-point number
% num_fixed = fix (num_float* 2^m);
% % saturate if the number is greater than the max positive
% % represent able number or less than the min negative
% % represent-able number in signed Qn.m format
% if num_fixed > 2^(N-1) - 1
% num_fixed = 2^(N-1) - 1;
% else if num_fixed < - 2^(N-1)
% num_fixed = 2^(N-1);
% end
% % if negative, compute its 2?s complement by first
% % inverting all bits
% % of the magnitude of the number and than adding one to it
% if num_fixed < 0
% num_fixed = bitxor (2^N-1, abs(num_fixed)) + 1;
% dec2hex (num_fixed);
% end
% % extract N bits
% num_fixed = bitand(num_fixed, 2^N - 1);
% end
% function [num_fixed] = float2qnm (num_float, n, m);
% % File name: float2qnm.m
% %
% % Description: mat lab routine for converting a signed
% % floating point number into its equivalent signed Qn.m
% % format fixed point number.
% %num_float: floating point number to be converted into Qn.m
% % Fixed-point format
% % n: num of bits to the left of the decimal point with MSB
% % as signed bit
% % m: number of bits to the right of the decimal point
% % num_fixed: converted signed fixed-point number in Qn.m format
% % Total number of bits in the fixed-point representation
% N = n+m;
% % change number into fixed-point number
% num_fixed = fix (num_float* 2^m);
% % saturate if the number is greater than the max positive
% % represent able number or less than the min negative
% % represent-able number in signed Qn.m format
% if num_fixed > 2^(N-1) - 1
% num_fixed = 2^(N-1) - 1;
% else if num_fixed < - 2^(N-1)
% num_fixed = 2^(N-1);
% end
% % if negative, compute its 2?s complement by first
% % inverting all bits
% % of the magnitude of the number and than adding one to it
% if num_fixed < 0
% num_fixed = bitxor (2^N-1, abs(num_fixed)) + 1;
% dec2hex (num_fixed);
% end
% % extract N bits
% num_fixed = bitand(num_fixed, 2^N - 1);
% end
% function [num_fixed] = float2qnm (num_float, n, m);
% % File name: float2qnm.m
% %
% % Description: mat lab routine for converting a signed
% % floating point number into its equivalent signed Qn.m
% % format fixed point number.
% %num_float: floating point number to be converted into Qn.m
% % Fixed-point format
% % n: num of bits to the left of the decimal point with MSB
% % as signed bit
% % m: number of bits to the right of the decimal point
% % num_fixed: converted signed fixed-point number in Qn.m format
% % Total number of bits in the fixed-point representation
% N = n+m;
% % change number into fixed-point number
% num_fixed = fix (num_float* 2^m);
% % saturate if the number is greater than the max positive
% % represent able number or less than the min negative
% % represent-able number in signed Qn.m format
% if num_fixed > 2^(N-1) - 1
% num_fixed = 2^(N-1) - 1;
% else if num_fixed < - 2^(N-1)
% num_fixed = 2^(N-1);
% end
% % if negative, compute its 2?s complement by first
% % inverting all bits
% % of the magnitude of the number and than adding one to it
% if num_fixed < 0
% num_fixed = bitxor (2^N-1, abs(num_fixed)) + 1;
% dec2hex (num_fixed);
% end
% % extract N bits
% num_fixed = bitand(num_fixed, 2^N - 1);
% end
% function [num_fixed] = float2qnm (num_float, n, m);
% % File name: float2qnm.m
% %
% % Description: mat lab routine for converting a signed
% % floating point number into its equivalent signed Qn.m
% % format fixed point number.
% %num_float: floating point number to be converted into Qn.m
% % Fixed-point format
% % n: num of bits to the left of the decimal point with MSB
% % as signed bit
% % m: number of bits to the right of the decimal point
% % num_fixed: converted signed fixed-point number in Qn.m format
% % Total number of bits in the fixed-point representation
% N = n+m;
% % change number into fixed-point number
% num_fixed = fix (num_float* 2^m);
% % saturate if the number is greater than the max positive
% % represent able number or less than the min negative
% % represent-able number in signed Qn.m format
% if num_fixed > 2^(N-1) - 1
% num_fixed = 2^(N-1) - 1;
% else if num_fixed < - 2^(N-1)
% num_fixed = 2^(N-1);
% end
% % if negative, compute its 2?s complement by first
% % inverting all bits
% % of the magnitude of the number and than adding one to it
% if num_fixed < 0
% num_fixed = bitxor (2^N-1, abs(num_fixed)) + 1;
% dec2hex (num_fixed);
% end
% % extract N bits
% num_fixed = bitand(num_fixed, 2^N - 1);
% end
% function [num_fixed] = float2qnm (num_float, n, m);
% % File name: float2qnm.m
% %
% % Description: mat lab routine for converting a signed
% % floating point number into its equivalent signed Qn.m
% % format fixed point number.
% %num_float: floating point number to be converted into Qn.m
% % Fixed-point format
% % n: num of bits to the left of the decimal point with MSB
% % as signed bit
% % m: number of bits to the right of the decimal point
% % num_fixed: converted signed fixed-point number in Qn.m format
% % Total number of bits in the fixed-point representation
% N = n+m;
% % change number into fixed-point number
% num_fixed = fix (num_float* 2^m);
% % saturate if the number is greater than the max positive
% % represent able number or less than the min negative
% % represent-able number in signed Qn.m format
% if num_fixed > 2^(N-1) - 1
% num_fixed = 2^(N-1) - 1;
% else if num_fixed < - 2^(N-1)
% num_fixed = 2^(N-1);
% end
% % if negative, compute its 2?s complement by first
% % inverting all bits
% % of the magnitude of the number and than adding one to it
% if num_fixed < 0
% num_fixed = bitxor (2^N-1, abs(num_fixed)) + 1;
% dec2hex (num_fixed);
% end
% % extract N bits
% num_fixed = bitand(num_fixed, 2^N - 1);
% end
%
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -