136
Quiz on Ch.2 Count up six times starting with each number: AB3C 16 101101 2 1234 5

Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Quiz on Ch.2

Count up six times starting with each number:

• AB3C16

• 1011012

• 12345

Page 2: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Quiz on Ch.2

What is the largest positive integer that can be represented with 7 bits?

Page 3: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Extra-credit QUIZ:

3

Page 4: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Conclusion: We can convert from hex to octal, using binary as a stepping-stone!

4

binary

hexadecimal

octal

Page 5: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Chapter 3

Data Representation

Page 6: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Data compression

Reduction in the amount of space (memory) needed to store or transmit the data

Measured by the Compression ratio = The size of the compressed data divided by the size of the original data

Example: A file of size 200 MB is compressed with the ZIP utility, and its size is 150 MB after compression.

What is the compression ratio?𝟏𝟓𝟎 𝑴𝑩

𝟐𝟎𝟎 𝑴𝑩=

𝟏𝟓

𝟐𝟎=

𝟑

𝟒= 𝟎. 𝟕𝟓 = 𝟕𝟓%

6

Page 7: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ

Two files are compressed with the ZIP utility:

• One is originally 200 MB, and becomes 150 MB after compression

• The other is originally 15 MB, and 11 MB after compression

Which file is better/more compressed?

7

Page 8: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Solution

Two files are compressed with the ZIP utility:

• One is originally 200 MB, and becomes 150 MB after compression

• The other is originally 15 MB, and 11 MB after compression

8

r1 = 0.75

r2 = 11 MB / 15 MB = 11/15 = 0.733

r2 < r1, so the second file has (slightly) better compression

Page 9: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Quiz

A video file is originally 3.5 GB long.

We compress with a compression ratio of 0.2 (20%).

What is the final size of the file?

9

Page 10: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Solution

A video file is originally 3.5 GB long.

We compress with a compression ratio of 0.2 (20%).

What is the final size of the file?

10

r = 0.2 = 𝑓𝑖𝑛𝑎𝑙 𝑠𝑖𝑧𝑒

𝑖𝑛𝑖𝑡𝑖𝑎𝑙 𝑠𝑖𝑧𝑒

final size = 0.2 x initial size = 0.2 x 3.5 GB = 0.7 GB = 700 MB

Page 11: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Data compression

The Compression ratio is always between 0 and 1

(0% and 100%)

Compression techniques can be

Lossless → the data can be retrieved without any loss of the original information

Lossy → some information may be lost in the process (but it doesn’t matter for the purposes of the intended application)

11

Page 12: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Information can be represented in one of two ways: analog or digital

Analog data

A continuous representation, similar to the actual information it represents

Digital data

A discrete representation, breaking the information up into separate elements

12

Analog vs. Digital

Page 13: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Computers cannot work well with analog data, so we digitize the data

Digitizing = Breaking data into pieces and representing those pieces separately, by using a finite number of binary digits

There are two operations performed:

• one in time (a.k.a. sampling)

• the other in amplitude (a.k.a. quantizing)

13

Page 14: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

There are two operations performed when digitizing a continuous signal:

• one in time (a.k.a. sampling)

• the other in amplitude (a.k.a. quantizing)

14

Page 15: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Quiz

A digital compass reads the position of a robot 20 times a second.

What is the time elapsed between two consecutive readings?

Is this a sampling error or quantization error?

15

Page 16: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Analog and Digital Information

Why do we use binary to represent digitized data?

• Price: transistors are (now) cheap to produce

–Remember Babbage!

• Reliability: transistors don’t get (easily) jammed

–Remember Babbage!

16

Page 17: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Electronic Signals

Important facts about electronic signals

• An analog signal continually fluctuates up and down

• A digital signal has only a high or low state, corresponding to the two binary digits

17

Figure 3.2

An analog and a digital signal

Page 18: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

• All electronic signals (both analog and digital) degrade due to absorption in transmission lines

• The amplitude (voltage) of electronic signals (both analog and digital) fluctuates due to environmental effects, a.k.a. noise

18

Figure 3.3

Degradation of analog and digital signals

The difference is that digital signals can be easily

regenerated!

Page 19: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Binary Representations

One bit can be either 0 or 1

• One bit can represent two things

Two bits can represent four things (Why?)

How many things can three bits represent?

How many things can four bits represent?

19

Page 20: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

20

Why does the number of combinations double with

every extra bit?

Page 21: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Conclusions onBinary Representations

How many things can n bits represent?

What happens every time you increase the number of bits by one?

21

Page 22: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ

A digital thermometer has a scale from 50 to 100 degrees (F). The temperature is represented on 7 bits. What is the smallest temperature difference that it can measure?

Is this a sampling error or quantization error?

22

Page 23: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Solution

A digital thermometer has a scale from 50 to 100 degrees (F). The temperature is represented on 7 bits. What is the smallest temperature difference that it can measure?

7 bits → 27 = 128 values → 127 intervals

(100-50)/127 = 0.394 deg/interval

Is this a sampling error or quantization error?

Quantization, since it’s in the vertical direction (amplitude)23

Beware of the “fencepost error”!

Image source: http://en.wikipedia.org/wiki/Fencepost_error

Page 24: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Similar quiz for individual work

A digital volt-meter has a scale from 0 to 30 volt (V).

The voltage is represented on 9 bits. What is the smallest voltage difference that it can represent?

Is this a sampling error or quantization error?

24

Page 25: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Reversing the problem of Binary Representations

How many things can n bits represent?

How many bits are needed to represent Nthings?

25

Say, all desktops in this lab?

Page 26: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

How many bits are needed to represent all 45 desktops in this lab?

The inverse of the power (2n) is the logarithm:

26

What’s wrong with this answer?

Base is 2

Page 27: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

How many bits are needed to represent all 45 desktops in this lab?

27

The “ceiling” function returns the next integer that is greater than or equal to its argument!

Page 28: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

How many bits are needed to represent all 45 desktops in this lab?

28

Alternative solution:

What’s the smallest power of 2 that is ≥ N?

Page 29: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Computers are multimedia devices, dealing with a vast array of information categories.

Computers store, present, and help us modify many types of data:

• Numbers

• Text

• Audio

• Images and graphics

• Video

• Smell (machine olfaction!)

• Haptics (touch)

• Chess positions

• Etc. etc. etc.

29

Positive integers

Negative integers

Real (various precisions)

Complex

See Ch.2!

Page 30: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

3.2 Representing Numeric Data

Negative integers

Signed-magnitude representation

The sign represents the ordering, and the digits represent the magnitude of the number

30

Page 31: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Negative Integers

There is a problem with the sign-magnitude representation: plus zero and minus zero.

• More complex hardware is required!

Solution: Let’s not represent the sign explicitly!

“Complement” representation

31

Page 32: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Ten’s complement

Using two decimal digits, represent 100 numbers

• If unsigned, the range would be 0…?

• Let 1 through 49 represent 1 … 49

• Let 50 through 99 represent -50 … -1

32

Page 33: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Ten’s complement

33

Top: representations (the “label on the jar”)

Bottom: the actual numbers that are being

represented (the “content of the jar”)

Page 34: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZGiven the following representations, find in each case what actual number is being represented:

• 51

• 52

• 96

• 47

34

Top: representations

Bottom: numbers represented

Page 35: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZGiven the following number is being represented, find in each case what is the tens’ complement representation:

• -48

• 47

• 0

• 96

35

Top: representations

Bottom: numbers represented

Page 36: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Quick work for next time:

• Read pp.55-63 of our text

• Solve the quiz on slide 24

• Solve end-of-chapter ex. 1-6, 21, 27-31 in notebook

36EOL1

Page 37: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

EXTRA-CREDIT QUIZ

37

Page 38: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZWhat is the representation (top) for each of these actual numbers (bottom)?

• -45

• -40

• -30

• -5

38

Page 39: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Why the “complement” in ten’s complement?

100 – 50 = 50

100 – 49 = 51

……………………..

100 – 1 = 99

In general:

100 – i is the representation of – i

39

Positive number

Negative number

Page 40: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

We can use ten’s complement to calculate!

To perform addition, add the numbers and discard any carry

40

Now you try it

48 (signed-magnitude)

- 1

47

How does it work in

the new scheme?

Page 41: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Adding negative numbers:

41

Try these:

4 - 4 -4

- 3 +3 + -3

Page 42: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Important conclusions

In any complement representation:

• Positive and negative numbers are treated the same! We can add without knowing if they’re positive or negative!

• Subtraction is performed as addition, by changing signs: a – b = a + (-b). This greatly simplifies the hardware!

42

Page 43: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

43

Two’s Complement

What do you notice

about the left-most bit

(MSB)?

Important: It’s not

sign-magnitude!!

Page 44: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

44

QUIZ

John has encountered this two’s

complement number:

1000 0111

He says: The number is negative, b/c

the MSB is one.

The magnitude is just 111, which

means 7.

Therefore the number is -7 in decimal!

Is John correct?

Page 45: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Two’s complement on 4 bits (k = 4)

45

What is:

• The largest positive number?

• The largest negative number?

• -1?

Repeat the questions above for:

• 5 bits (k = 5)

• 6 bits

• 8 bits

• N bits (general N)

Not in text

Page 46: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

46

http://xkcd.com/571/

Two’s complement on 16 bits

Page 47: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

47

“Signposts” for two’s comp.

0000 0000 means ...

0111 1111 means ...

1000 0000 means ...

1111 1111 means ...

Page 48: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Formula to compute the negative of a number on k digits:

• for ten’s comp: Negative(I) → 10k - I

• for two’s comp: Negative(I) → 2k - I

Practice: find the 8-bit two’s comp. representations:

7

-7

-110

200 (trick question!)

-129 (trick question!)

048

Page 49: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

“Fast” two’s complementEasier way to change the sign of a number:

Flip all bits, then add 1

Try it out! Find the negatives of the following

two’s complement numbers:

0000 0011

1000 0000

1000 0001

1000 0011

1001 0110

1111 111149

This is how subtraction is implemented in

computer hardware!A – B = A + (-B)

Page 50: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ

What is the 8-bit two’s complement representation of these numbers?

• -13

• 40

50

Page 51: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Two’s complement arithmetic

Addition and subtraction are the same as in unsigned:

-127 1000 0001

+ 1 0000 0001

-126 1000 0010

Ignore any Carry out of the MSB:

-1 1111 1111

+

-1 1111 1111

-2 1111 1110

51

Page 52: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ

Perform the following operation in 8-bit two’s complement:

40 – 13

52

Page 53: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Trick QUIZ

What decimal number does this binary number represent?

1001 1110

53

Page 54: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

What happens if the computed value won't fit in the given number of bits k?

Overflow

If k = 8 bits, adding 127 to 3 overflows:1111 1111

+ 0000 0011

10000 0010

… but adding -1 to 3 doesn’t!

54

Page 55: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Conclusions:

Overflow is specific to the representation(unsigned, sign-mag., two’s comp., floating point etc.)

Overflow is something we should always expect (and make provisions for) when mapping an infinite world onto a finite machine!

55

Page 56: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

SKIP Representing Real Numbers

56

Page 57: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

3.3 Representing Text

Basic idea:There are finite number of characters to represent, so list them all and assign each a (binary) number, a.k.a. code.

Character setA list of characters and the codes used to represent each one

Computer manufacturers (eventually) agreed to standardize

– Read “Character Set Maze” on p.6757

Page 58: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

The ASCII Character Set

ASCII = American Standard Code for Information Interchange

ASCII originally used seven bits to represent each character, allowing for 128 unique characters

Later extended ASCII evolved so that all eight bits were used

• How many characters can be represented?

58

Page 59: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

7-bit ASCII Character Set

59

Page 60: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ

Encode “Hello, world!” in ASCII

Decode 67 79 83 67 32 49 51 48 50 from ASCII

Page 61: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

The ASCII table is already built into Python!

61

Page 62: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

The ASCII Character Set

62

The first 32 characters in the ASCII character chart do not have a simple character representation to print to the screen.

They are called control characters

Page 63: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

8-bit (“extended”) ASCII Character Sets

63

By using 8 bits instead of 7, the number of codes extends from 128 to 256.

Extended ASCII is always a superset of 7-bit ASCII:

• The first 128 characters correspond exactly to 7-bit ASCII

Not in text

Problem: Computer vendors couldn’t agree on one set!

Page 64: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Extended ASCII: IBM code page 437

64

http://en.wikipedia.org/wiki/Code_page_437

Not in text

Page 65: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Extended ASCII: Latin-1

65http://en.wikipedia.org/wiki/ISO/IEC_8859-1

Not in text

Page 66: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ

What do these bits represent?

1101 1110

66

Page 67: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Solution

It depends on what is being represented!

1101 1110

67

Unsigned integer: …

Signed integer (2’s complement): …

IBM 437 character: …

Latin-1 character: …

Page 68: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ:

Your boss tells you to develop a webpage using the extended ASCII character set. What do you reply?

68

Page 69: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

The Unicode Character Set

None of the Extended ASCII character sets were enough for international use (256!)

Unicode uses 16 bits per character

How many characters can UNICODE represent?

Unicode is a superset of Latin-1: The first 256 characters correspond exactly to Latin-1 characters (http://unicode.org/charts/PDF/U0080.pdf )

69

Simplified Chinese has

6500!

Page 70: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Unicode examples

70Figure 3.6 A few characters in the Unicode character set

Page 71: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Text Compression

Sometimes, assigning 8 or 16 bits to each character in a document uses too much memory

We need ways to store and transmit text efficiently

Text compression techniques:– keyword encoding– run-length encoding– Huffman encoding

71

Page 72: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Keyword Encoding

Replace frequently used words with a single character, for example here’s a substitution chart:

72

Page 73: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Keyword EncodingOriginal text:

We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness. That to secure these rights, Governments are instituted among Men, deriving their just powers from the consent of the governed, Thatwhenever any Form of Government becomes destructive of these ends, it is the Right of the People to alter or to abolish it, and to institute new Government, laying its foundation on such principles and organizing its powers in such form, as to them shall seem most likely to effect their Safety and Happiness.

73

Page 74: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Encoded text:

We hold # truths to be self-evident, $ all men are created equal, $ ~y are endowed by ~ir Creator with certain unalienable Rights, $ among # are Life, Liberty + ~ pursuit of Happiness. $ to secure # rights, Governments are instituted among Men, deriving ~ir just powers from ~ consent of ~ governed, $ whenever any Form of Government becomes destructive of # ends, it is ~ Right of ~ People to alter or to abolish it, + to institute new Government, laying its foundation on such principles + organizing its powers in such form, ^ to ~m shall seem most likely to effect ~ir Safety + Happiness.

74

Page 75: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Keyword Encoding

How much did we compress?

Original paragraph

656 characters

Encoded paragraph

596 characters

Characters saved

60 characters

Compression ratio

596/656 = 0.9085

75

Page 76: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Could we use this substitution chart for any arbitrary text?

76

QUIZ

A: No, we cannot use it for text that contains the symbols themselves!

Page 77: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Quick work for next time:

• Read pp.64-73 of our text

• Solve again all today’s quizzes

77End week 1

Page 78: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ

What decimal number does this binary number represent?

1011 0010

78

Perform this addition in 8-bit two’s complement:

8 – 11 =

Page 79: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ Select all that apply:

The Latin-1 character set:

• Is a 5-bit representation

• Is a 7-bit representation

• Is a 16-bit representation

• Is an extension of ASCII

• Is an extension of Unicode

• Contains letters used in European languages

79

Page 80: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ Select all that apply:

The Unicode representation:

• Uses 16 bits

• Is an extension of ASCII

• Is an extension of Latin-1

• Is an extension of IBM-437

• Contains letters used in all world languages

• Can accommodate over 65,000 characters

• Is used in the majority of web pages today

80

Page 81: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Run-Length Encoding

A single character may be repeated over and over in a long sequence.

Replace a repeated sequence with – a flag character, followed by

– the repeated character, followed by

– the number of repetitions.

Example:

81

• * is the flag character• b is the repeated character• 8 is the number of times b

is repeated

Page 82: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Run-Length EncodingEncoding example:

Original text is

bbbbbbbbjjjkLLqqqqqq+++++Encoded text is

*b8jjjkLL*q6*+5

Compression ratio: 15/25 = .6

Why isn't LL encoded? Why not jjj?

82

Page 83: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Run-Length Encoding

Decoding example:

Encoded text is

*x4*p4l*k7Original text is

xxxxpppplkkkkkkk

83

Page 84: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZDecode using RLE:

*a4*A4HIJ*Z5

Encode using RLE:

Hummm, Burrrrr, OOOPS!

• In both problems, calculate the compression ratio!

84

Page 85: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Huffman CodesLetter & Word Frequency distributions:

85

Page 86: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Huffman CodesConclusion: each language and each topic have specific frequencies of characters and groups of characters (digraphs, trigraphs etc.)

Why should the characters “X" or "z" take up the same number of bits as "e" or "t"?

Huffman codes use variable-length bit strings to

represent each character. More frequently-used letters

have shorter strings to represent them, and vice-versa!

86

Page 87: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Huffman encoding example

“ballboard” would be1010001001001010110001111011

compression ratio

28/63 (7-bit ASCII)

QUIZ:

Encode “roadbed”

87

Page 88: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Huffman decoding

In Huffman encoding no character's bit string is the prefix of any other character's bit string. Codes with this property are called prefix codes.

To decode

look for match left to right, bit by bit

record letter when the first match is found

continue where you left off, going left to right

88

Page 89: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ Huffman decoding

89

Decode:

1011111001010

Page 90: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ Huffman decoding

90

Decode:

1001101111011

EOL3

Page 91: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ: Decipher the coded text using the Huffman table:

91

0010110101001110100110011011010011000111

01111001110100111

Page 92: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

3.4 Representing Audio Data

92

We perceive sound when:

• a series of air waves cause to vibrate a membrane in

our ear (eardrum), which

• is connected to the malleus, incus, and stapes

(hammer, anvil, and stirrup), which

• are connected to the cochlea, which

• sends nerve signals to our brain.

Page 93: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

The tricky evolution of the middle ear

93

Not in text

Source of figures: http://en.wikipedia.org/wiki/Evolution_of_mammalian_auditory_ossicles

Correspondence discovered in 1837 (!)

through embriology

The hammer, anvil, and stirrup,

of mammals used to be jaw

bones in reptiles!

… but how could this happen?

Surely an early mammal with an

unhinged jaw couldn’t survive!

Page 94: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

The tricky evolution of the middle ear

94

Not in text

Source of figures: http://en.wikipedia.org/wiki/Evolution_of_mammalian_auditory_ossicles

Morganucodon, a.k.a. Morgie

discovered in the1950s

Correspondence discovered in 1837 (!)

through embriology

Page 95: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Analog Audio

Record players and stereos send analog signals to speakers to produce sound.

These signals are analog representations of the sound waves.

The voltage in the signal varies in direct proportion to the amplitude of the sound wave.

95

Page 96: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Remember: Sampling and Quantizing

96

Some information

is lost, but the sound is

reproduced with a

reasonable quality

Not in text

Page 97: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

From Analog to Digital Audio

Digitize the signal by sampling and quantizing

– periodically measure the voltage

– record the numeric value in binary

How often should we sample?

Nyquist’s Theorem says that the nr. of samples per second needs to be at least double the highest frequency in the signal.

97

Page 98: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

From Analog to Digital Audio

How often should we sample?

Nyquist’s Theorem says that the nr. of samples per second needs to be at least double the highest frequency in the signal.

The highest frequency the human ear can perceive is 20,000 Hz (20 KHz).

98

Page 99: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

From Analog to Digital Audio

How often should we sample?

A sampling rate of about 40,000 times per second is enough to create a reasonable sound reproduction.

99

44,000 for audio CD, to be exact

Page 100: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ: Sampling

A telephone voice channel is designed to allow frequencies up to 4,000 Hz (4 kHz).

How many samples must be collected every second to digitize the signal?

100

Page 101: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Digital Audio on a CD

101

Figure 3.9

A CD player reading

binary information

“pit”

“land”

Page 102: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Digital Audio on a CD

On the surface of the CD are microscopic pits

and lands that represent binary digits

A low intensity laser is pointed as the disc. The

laser light reflects strongly if the surface is

smooth and poorly if the surface is pitted ???

(p.75 of text)

102

Page 103: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

103

Pit height is about ¼ the

laser’s wavelength

“destructive

interference”

FYI: How the pits and lands are actually readNot in text

Page 104: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

104

Both halves of the

laser beam reflect off

pit or both halves off

land.

The two halves are “in

phase”.

Half of the laser beam

reflects off pit and half

off land.

The 2 halves are “out

of phase”.

FYI: How the pits and lands are actually read

Not in text

Page 105: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Audio FormatsAudio Formats

– WAV, AU, AIFF, VQF, and MP3

MP3 (MPEG-2, audio layer 3 file) is dominant

– analyzes the frequency spread and discards information that can’t be heard by humans (>16 kHz)

– bit stream is compressed using a form of Huffman encoding to achieve additional compression

Is this a lossy or lossless compression?105

Page 106: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ: MP3MP3

– analyzes the frequency spread and discards information that can’t be heard by most humans (>16 kHz)

How many MP3 samples are there in a 3-minute song?

106

Page 107: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

MP3

– analyzes the frequency spread and discards information that can’t be heard by most humans (>16 kHz)

How many MP3 samples are there in a 3-minute song?

If each sample is represented as one Byte, what is the total size of the file?

107

QUIZ: MP3

Page 108: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

SolutionHow many MP3 samples are there in a 3-

minute song?

16,000 x 2 x 60 x 3 = 5,760,000 samples

If each sample is represented as one Byte, what is the total size of the file?

5,760,000 samples = 5,760,000 Bytes ≈ 5.76 MB

Note: MP3 then applies Huffman coding, which further reduces the size of the file.

108EOL 3

Page 109: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

109

MP3 quiz reloaded!

Page 110: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

3.5 Representing Images and Graphics

Color

Perception of the frequencies of light that reach

the retinas of our eyes

Human retinas have three types of color

photoreceptor cone cells that correspond to the

colors of red, green, and blue.

110

Page 111: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Color is expressed as an RGB (red-green-blue) value = three numbers that indicate the relative contribution of each of these three primary colors

An RGB value of (255, 255, 0) maximizes the contribution of red and green, and minimizes the contribution of blue, which results in a bright yellow.

111

Page 112: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

112

Dark means low number, light

means high.

Look at the snow and the black

side of the barn!

Source: Wikipedia – RGB color model

Page 113: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Can you understand this HTML code?

<font color="#FF0000">

Blah blah …

</font>

113

RGB Color Chart in hex

Page 114: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ

114

Explain the similarities and differences between 00FF00 and 008800

Page 115: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

The color cube

115

Figure 3.10 Three-dimensional color space

Page 116: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Depth of colorcolor depth

The amount of data that is used to represent a color

HiColor

A 16-bit color depth: five bits used for each number in an RGB value with the extra bit sometimes used to represent transparency

TrueColor

A 24-bit color depth: eight bits used for each number in an RGB value

116

Page 117: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ

117

Are these HiColor

or TrueColor?

EOL5

Page 118: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Extra-credit question

118

Page 119: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Tarleton Purple

119

The correct "Tarleton Purple" color codes:

• Hex: 4F 2D 7F

• RGB: 79 45 127 (decimal)

Source: http://www.tarleton.edu/webservices/guidelines.html

Page 120: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

How to digitize a picture

• Sample it → Represent it as a collection of individual dots called pixels.

• Quantize it → Represent each pixel as one of 224 possible colors (TrueColor)

Resolution = The # of pixels used to represent a picture

120

Page 121: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Example of sampling into pixels

121

Figure 3.12 A digitized picture composed of many individual pixels

Whole

picture

Page 122: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

122

Figure 3.12 A digitized picture composed of many individual pixels

Magnified portion

of the picture

See the pixels?

Hands-on: paste the

high-res image from

the previous slide in

Paint, then choose

ZOOM = 800

Page 123: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

QUIZ: Images

A low-res image has 200 rows and 300 columns of pixels.

• What is the resolution?

• If the pixels are represented in True-Color, what is the size of the file?

• Same question in High-Color.

123

Page 124: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Two types of image formats

• Raster Graphics = Storage on a pixel-by-pixel

basis

• Vector Graphics = Storage in vector (i.e. mathematical) form

124

Page 125: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Raster Graphics

GIF format• Each image is made up of only 256 colors (indexed color –

similar to palette!)

• But they can be a different 256 for each image!

• Supports animation! Example

• Optimal for line art

PNG format (“ping” = Portable Network Graphics)

Like GIF but achieves greater compression with wider range of color depth

No animations

125

Page 126: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Bitmap formatContains the pixel color values of the image from left to right and from top to bottom

• Great candidate for run-length compression!

• Lossless, but files are large!

JPEG formatAverages color hues over short distances

• Lossy compression!

Optimal for color photographs

126

Page 127: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Vector GraphicsA format that describes an image in terms of lines and geometric shapes

A vector graphic is a series of commands that describe a line’s direction, thickness, and color.

The file sizes tend to be smaller because not every pixel is described.

Example: Flash

127

Page 128: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Vector Graphics

The good side:

Vector graphics can be resized mathematically and changes can be calculated dynamically as needed

The bad side:

Vector graphics are not good for representing real-world images

128

Page 129: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

SKIP: 3.6 Representing Video

129

Read: Bio → Bob Bemer

Read: Ethical Issues →Snowden’s revelations

Page 130: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Source: AP CS Principles – Course and Exam Descriptions

Chapter QUIZ

Based on the many examples of data compression we covered, answer this:

Page 131: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Quick workTo do by next class, before starting to work

on homework:

• Read the entire Chapter 3

• SKIP …

• Answer end-of-chapter questions 8 – 19, 32, 33 in your notebook

131

This is not homework!Do not turn in for

grading!

Page 132: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Homework problems :

--36, 40, 41, 47, 49, 51, 52, 53, 61.

--Answer thought questions 4 and 5

together (200-word answer expected!):4. Where is Edward Snowden now?

5. What do you think history will call him?

Due Thursday, Sep.27 at beginning of class

132

Page 133: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and
Page 134: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Control Character: newline

134

Source: http://en.wikipedia.org/wiki/Newline#Unicode

FYI

Page 135: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Chapter Review Questions

• Distinguish between analog and digital information

• Explain data compression and calculate compression ratios

• Explain the binary formats for negative (two’s complement), fractional, and floating-point values

• Describe the characteristics of the ASCII and Unicodecharacter sets

• Perform various types of text compression with pencil and paper: Keyword, Run-length, Huffman

135

Page 136: Quiz on Ch · • All electronic signals (both analog and digital) degrade due to absorption in transmission lines • The amplitude (voltage) of electronic signals (both analog and

Chapter Review Questions

• Explain the nature of sound and its representation

• Explain how RGB values define a color

• Distinguish between raster and vector graphics

• Explain temporal and spatial video compression

136