标签:log int logs 技术 error form image scom bit
上代码:
% x = -7:7 y = OnesComplement(x, 4)
函数OnesComplement代码:
function [y] = OnesComplement(x, B); % Decimal equivalent of Sign-Magnitude format integer % to b-bit Ones‘-Complement format conversion % ---------------------------------------------------------- % [y] = ladrfilt(x, B) % x = integer between -2^(b-1) < x < 2^(b-1) (sign-magnitude) % y = integer between 0 <= y <= 2^b-1 (1‘s-complement) % % if any((x <= -2^(B-1) | (x >= 2^(B-1)))) error(‘Numbers must satisfy -2^(B-1) < x < 2^(B-1)‘) end s = sign(x); % sign of x (-1 if x<0, 0 if x=0, 1 if x>0) sb = (s < 0); % sign-bit (0 if x>=0, 1 if x<0) y = (1-sb) .* x + sb .* bitcmp(abs(x), B);
运行结果:
《DSP using MATLAB》示例 Example 6.11
标签:log int logs 技术 error form image scom bit
原文地址:http://www.cnblogs.com/ky027wh-sx/p/6440466.html