Data storage
Data storage
Data StorageDiscussion
• Data used and processed by a computer system is stored as electronic files
•Data can take many forms
• Saving student name, age marks … (characters , numbers ......)
• Saving a photo taken by a digital camera (picture)
• Record and save speech/music (sound)
• Recording a video (video)
• All the above will be saved as electronic files BUT each will be in a
different format.
2
Data Storage
•Data stored on a computer can be of different types:
•Text and numbers
•Sound (music/ speech)
•Pictures
•Video
•Each type of data will be stored in a different way.
3
Data Compression
•Compression means storing data in a format
that requires less space than usual
•Compression reduces the size of a file
•In order to be used again, a compressed file
must be uncompressed .
4
Compression Benefits
Compression reduces file size therefore:
1. Storage benefit▪ Files can be stored using less disk space i.e.
▪ Less money spent on buying disks
2. Transmission benefit
▪ File is sent faster via a network (internet) i.e.
▪Takes less time to download/upload a file▪ Less money spent on internet fees.
5
Compression Techniques
•Two compression techniques:
1. Lossless compression
2. Lossy compression
6
Lossless compression
•The file is reduced in size for transmission and
storage BUT without losing any information
•it can be put back together again (uncompressed)
to produce a file identical to the original
•E.g. compressing text files. (Files that contain only
characters)
7
Lossy compression
• Reduces a file by permanently eliminating certain information
• Difference is usually not noticeable to human eye or ear
• When decompressed, some detail is lost and the file is not exactly
like the original
• Used for pictures(JPEG), video (MP4) and sound (MP3), where a
certain amount of information loss will not be detected by most
users.
8
Text and numbers
By text we mean any alphanumeric characters i.e. a combination of:
• A-Z , a-z, 0-9 , punctuation marks , symbols
• Any character present on a keyboard
• Every character is represented by a unique numeric value called the ASCII code
• ASCII code is usually in binary
• 1 character is represented by 1 byte (00000000 - 11111111 )
• Can also be written in equivalent decimal (0 to 128) or HEX (0 to 7F)
• "A" is 0100 0001," B" is 0100 0010, and so forth.
9
ASCII code10
ASCII code defines a unique binary number between 0000000 and 1111111 for all the characters found on a standard keyboard
Text files
•A Text file is stored in ASCII format
•ASCII format uses 1 byte per character
•Any text file can be converted to a string of 0's and 1‘
•and hence easily understood by the computer
•Binary ASCII code can be converted to DEN or HEX to
make it easier to read for humans.
11
Text file Compression
•A Text file may be compressed
•BUT we need to get the exact original after uncompressing
•Which type of compression is appropriate?
•WHY?
• loss of any data would be disastrous e.g. a spreadsheet file
storing student marks
•Read textbook page 80
12
Picture files•Pictures/images/photos are made up of pixels
•A pixel is a single dot in a graphic image
•Number of pixels = resolution
•Higher resolution = More pixels = higher quality picture
•Resolution measured as =
• (number of pixels per row) X (number of rows)
•An image having 1024 pixels per row with 768 rows has a resolution of 1024x768 = 786 432 Pixels
• The file size of a picture depends on the number of pixels
13
Picture file compression•The format in which a picture is saved tells us
▪If the picture was compressed or not
▪ And if compressed then which compression technique was used?
▪ Lossy or lossless?
•Several picture file formats exist
•Uncompressed formats: BMP, TIFF
• Lossless Compressed formats: PNG , GIF
• Lossy compressed format :JPEG
14
JPEG format• JPEG is the most common format for pictures
• JPEG = Joint Photographic Experts Group
• JPEG is a file compression format designed to make photo files
smaller in size for storage and for transmission
• JPEG is an example of lossy file compression
• i.e. once the image is compressed, a new file is formed
and the original file can no longer be rebuilt
15
How does JPEG reduce file size
JPEG is an example of lossy file compression
•JPEG uses the limitations of human vision to
remove some colours from the picture
•JPEG discards information that the human eye
would not notice.
16
Calculating size of a Picture file • An uncompressed colour picture file requires 24 bits to store each pixel
• Remember 8 bits = 1 byte
• i.e 24 ÷ 8 = 3 bytes per pixel
• There fore a picture of resolution 600 X 800 requires
• 600 x 800 = 480 000 pixels
• Each pixel needs 3 bytes for storage of color information
• 480 000 pixels need : (480 000 x 3) bytes
• = 1440 000 bytes
• = 1440 ÷ 1024 = 1406 kilobytes (KB)
• = 1406 ÷ 1024 = 1.3 megabytes (MB)
17
Activity 6.2(a) from textbook
•(a) An image is 1200 pixels by 1600 pixels. Calculate:
• (i) the total number of pixels in the original image
• (ii) the number of bytes occupied by this file
• (iii) the file size of the jpeg image (in kilobytes) if the
original image was reduced by a factor of 8.
18
Activity 6.2(b) from textbook(b) A second image is 3072 pixels by 2304 pixels. Calculate:
• (i) the total number of pixels in the original image
• (ii) the number of bytes occupied by this file
• (iii) the file size of the jpeg image (in megabytes) if the original image
was reduced by a factor of 5.
• (iv) How many uncompressed files of the size calculated in part (ii)
could be stored on a 4-gigabyte memory card?
• (v) How many compressed files of the size calculated in part (iii) could
be stored on the same 4-gigabyte memory card?
19
Sound (Music) Files
•Two ways of representing music files
1. MP3
2. MIDI
20
MP3 files
•Uses lossy compression technology to reduce the size of
a music file by up to 90%
• A 700 MB music CD can be compressed to just 50-70 MB MP3 file
•The original music is compressed in such a way that it
does not noticeably affect the quality of the sound
• i.e Listeners will not be able to make the difference between
original and MP3.
21
How does MP3 reduce the music file size?
•Discards unimportant parts of the music
•If two sounds are played at same time it keeps
the louder sound and the softer sound is
removed
•Removes sounds human ear cannot hear very
well.
22
MIDI Files• MIDI is a communication protocol (A protocol is a set of rules)
• This protocol allows electronic musical instruments to communicate with each other.
• A MIDI file consists of a list of commands that instruct a device (e.g. an electronic organ,
a sound card in a computer or in a mobile phone) how to produce a particular sound
• MIDI files do not contain any audio hence, their size is considerably smaller
• For example, a 10 MB MP3 file only requires about 10 KB file size when saved as
MIDI.
• Suitable for devices where memory or storage space is limited
• For example, storing ring tones on a mobile phone.
23
Video files
Video files are stored in MP4 format
• MP4 allows the storage of multimedia files in a lossy compressed form
• Can store in same file:
• sound
• Music
• Videos
• Photos
• Animation
• MP4 is used to stream Videos over the internet (YouTube, Online movies…)
• Smaller file size
• No noticeable loss in quality.
24
How does MP4 reduce file size of videos
•MP4 allows the storage of multimedia files in
a lossy compressed form
•MP4 files use a variety of methods such as
removing some of the colour information in
each video frame
25
Other file compression formatsWe have seen JPEG, MP3 and MP4, But there exist other
compression formats:
1. ZIP
• format that supports lossless data compression
• Suitable for compressing text files
2. GIF
• Lossless compression used with pictures
3. PNG• Lossless compression for pictures (Better than GIF)
26
Definitions27
Computer Science Workbook P36 Q 6Textbook Chapter 6 Activities 6.1-6.2
28 Homework 1
1 (a) Robin wants to send a large file to Jennifer over the Internet.
State two benefits of compressing the file to send it.
Benefit 1 ...................................................................................................................................
Benefit 2 ...................................................................................................................................
(b) Two types of compression are lossy and lossless.
Choose the most suitable type of compression for the following and explain your choice.
(i) Downloading the code for a computer program:
Type of compression .........................................................................................................
Explanation .......................................................................................................................
(ii) Streaming a video file:
Type of compression .........................................................................................................
Explanation .......................................................................................................................
29 Homework 2
End Data Storage
30