02.10.2019 Views

UploadFile_6417

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

256 Chapter 6 IMPLEMENTATION OF DISCRETE-TIME FILTERS<br />

MATLAB Implementation Using (6.32), we can develop the<br />

MATLAB function, TwosComplement, which obtains the two’s-complement<br />

format representation. We can use the bitcmp function and then add one<br />

to the result to obtain the two’s-complement. However, we will use the<br />

last equality in (6.32) to obtain the two’s-complement since this approach<br />

will also be useful for fractional numbers. The function can use scalar<br />

as well as vector values. The result is a decimal equivalent of the two’scomplement<br />

representation. As before, the dec2bin can be used to obtain<br />

the binary code.<br />

function y = TwosComplement(x,b)<br />

% y = TwosComplement(x,b)<br />

% ---------------<br />

% Decimal equivalent of<br />

% Sign-Magnitude format integer to b-bit Ones’-Complement format conversion<br />

%<br />

% x: integer between -2^(b-1) > y = TwosComplement(x,4)<br />

y =<br />

8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7<br />

>> y = dec2bin(y,4); disp(sprintf(’%s’,[y’;char(ones(1,16)*32)]))<br />

1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111<br />

The two’s-complement format has many interesting characteristics<br />

and advantages. These will be given after we discuss the next format,<br />

namely the ten’s-complement.<br />

□<br />

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).<br />

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!