Che materia stai cercando?

Digital Camera Appunti scolastici Premium

A simple digital camera captures images, stores images in digital format (no film; multiple images stored in camera, whose number depends on amount of memory and bits used per image), downloads images to PC. Systems-on-a-chip and high-capacity flash memory are only recently possible. There are many more features with real digital camera: variable size... Vedi di più

Esame di Sistemi embedded docente Prof. L. Pomante

Anteprima

ESTRATTO DOCUMENTO

Quantization step

• Achieve high compression ratio by reducing image

quality

– Reduce bit precision of encoded data

• Fewer bits needed for encoding

• One way is to divide all values by a factor of 2

– Simple right shifts can do this

– Dequantization would reverse process for decompression

144 5 -5 -1 3 -10 1 5

1150 39 -43 -10 26 -83 11 41 Divide each cell’s -10 0 14 -9 -1 0 3 -1

-81 -3 115 -73 -6 -2 22 -5 value by 8 2 -1 0 -5 3 0 2 -5

14 -11 1 -42 26 -3 17 -38 0 -8 -2 -2 5 -3 -2 1

2 -61 -13 -12 36 -23 -18 5 6 2 5 -1 1 -3 1 -1

44 13 37 -4 10 -21 7 -8 5 -1 -1 -1 3 -4 -3 2

36 -11 -9 -4 20 -28 -21 14 -2 -1 3 -1 0 0 2 -3

-19 -7 21 -6 3 3 12 -21 -1 -2 -1 -2 -1 0 1 -1

-5 -13 -11 -17 -4 -1 7 -4

After being decoded using DCT After quantization

Embedded Systems Design: A Unified 10

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Huffman encoding step

• Serialize 8 x 8 block of pixels

– Values are converted into single list using zigzag pattern

• Perform Huffman encoding

– More frequently occurring pixels assigned short binary code

– Longer binary codes left for less frequently occurring pixels

• Each pixel in serial list converted to Huffman encoded values

– Much shorter list, thus compression

Embedded Systems Design: A Unified 11

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Huffman encoding example

• Pixel frequencies on left

– Pixel value –1 occurs 15 times

– Pixel value 14 occurs 1 time Huffman

Pixel

• Build Huffman tree from bottom up Huffman tree codes

frequencies

– Create one leaf node for each pixel 6

value and assign frequency as node’s -1 00

-1 15x 4 0

value 100

0 8x 3 -2 110

-2 6x

– Create an internal node by joining any 5

29 1 010

1 5x

two nodes whose sum is a minimal 2 1110

2 5x

value 3

1 1010

1

3 5x 1 7 5

1 8 0110

4

• 5 5x

This sum is internal nodes value 5

-1 -3 11110

-3 4x 1

– Repeat until complete binary tree 1

9 -5

6 10110

8

-5 3x 1

5 0 -10

• 01110

Traverse tree from root to leaf to -2

0

-10 2x 1 144

6 111111

5

144 1x 4

obtain binary code for leaf’s pixel 5

5

5 -9 111110

-9 1x 2

3

value 5 -8 101111

-8 1x 2

2

2 -4

4 101110

3

-4 1x

– Append 0 for left traversal, 1 for right 2 6

-5 -3 011111

-10

6 1x

traversal 1 14

1

1 1 011110

14 1x 1 1

• -9 144

Huffman encoding is reversible -4 -8

14 6

– No code is a prefix of another code

Embedded Systems Design: A Unified 12

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Archive step

• Record starting address and image size

– Can use linked list

• One possible way to archive images

– If max number of images archived is N:

• Set aside memory for N addresses and N image-size variables

• Keep a counter for location of next available address

• Initialize addresses and image-size variables to 0

• Set global memory address to N x 4

– Assuming addresses, image-size variables occupy N x 4 bytes

• First image archived starting at address N x 4

• Global memory address updated to N x 4 + (compressed image size)

• Memory requirement based on N, image size, and average

compression ratio

Embedded Systems Design: A Unified 13

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Uploading to PC

• When connected to PC and upload command received

– Read images from memory

– Transmit serially using UART

– While transmitting

• Reset pointers, image-size variables and global memory pointer

accordingly

Embedded Systems Design: A Unified 14

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Requirements Specification

• System’s requirements – what system should do

– Nonfunctional requirements

• Constraints on design metrics (e.g., “should use 0.001 watt or less”)

– Functional requirements

• System’s behavior (e.g., “output X should be input Y times 2”)

– Initial specification may be very general and come from marketing dept.

• E.g., short document detailing market need for a low-end digital camera that:

– captures and stores at least 50 low-res images and uploads to PC,

– costs around $100 with single medium-size IC costing less that $25,

– has long as possible battery life,

– has expected sales volume of 200,000 if market entry < 6 months,

– 100,000 if between 6 and 12 months,

– insignificant sales beyond 12 months

Embedded Systems Design: A Unified 15

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Nonfunctional requirements

• Design metrics of importance based on initial specification

– Performance: time required to process image

– Size: number of elementary logic gates (2-input NAND gate) in IC

– Power: measure of avg. electrical energy consumed while processing

– Energy: battery lifetime (power x time)

• Constrained metrics

– Values must be below (sometimes above) certain threshold

• Optimization metrics

– Improved as much as possible to improve product

• Metric can be both constrained and optimization

Embedded Systems Design: A Unified 16

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Nonfunctional requirements (cont.)

• Performance

– Must process image fast enough to be useful

– 1 sec reasonable constraint

• Slower would be annoying

• Faster not necessary for low-end of market

– Therefore, constrained metric

• Size

– Must use IC that fits in reasonably sized camera

– Constrained and optimization metric

• Constraint may be 200,000 gates, but smaller would be cheaper

• Power

– Must operate below certain temperature (cooling fan not possible)

– Therefore, constrained metric

• Energy

– Reducing power or time reduces energy

– Optimized metric: want battery to last as long as possible

Embedded Systems Design: A Unified 17

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Informal functional specification

• Flowchart breaks functionality

down into simpler functions Zero-bias adjust

CCD

input

• Each function’s details could then

be described in English DCT

– Done earlier in chapter Quantize yes

no Done?

Archive in

• Low quality image has resolution memory

of 64 x 64 More Transmit serially

yes no serial output

8×8 e.g., 011010...

blocks?

• Mapping functions to a particular

processor type not done at this

stage

Embedded Systems Design: A Unified 18

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Refined functional specification

• Refine informal specification into

one that can actually be executed Executable model of digital camera

• Can use C/C++ code to describe

each function CCD.C

101011010

– Called system-level model, 110101010

010101101

prototype, or simply model ... CODEC.C

CCDPP.C

– Also is first implementation image file

• Can provide insight into operations

of system CNTRL.C 101010101

– Profiling can find computationally 010101010

101010101

intensive functions 0...

UART.C

• Can obtain sample output used to output file

verify correctness of final

implementation

Embedded Systems Design: A Unified 19

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

CCD module

• Simulates real CCD

• CcdInitialize is passed name of image file void CcdInitialize(const char *imageFileName) {

• imageFileHandle = fopen(imageFileName, "r");

CcdCapture reads “image” from file rowIndex = -1;

• CcdPopPixel outputs pixels one at a time colIndex = -1;

#include <stdio.h> }

#define SZ_ROW 64 void CcdCapture(void) {

#define SZ_COL (64 + 2) int pixel;

static FILE *imageFileHandle; rewind(imageFileHandle);

static char buffer[SZ_ROW][SZ_COL]; for(rowIndex=0; rowIndex<SZ_ROW; rowIndex++) {

static unsigned rowIndex, colIndex; for(colIndex=0; colIndex<SZ_COL; colIndex++) {

char CcdPopPixel(void) { if( fscanf(imageFileHandle, "%i", &pixel) == 1 ) {

char pixel;

pixel = buffer[rowIndex][colIndex]; buffer[rowIndex][colIndex] = (char)pixel;

if( ++colIndex == SZ_COL ) { }

colIndex = 0;

if( ++rowIndex == SZ_ROW ) { }

colIndex = -1; }

rowIndex = -1;

} rowIndex = 0;

} colIndex = 0;

return pixel;

} }

Embedded Systems Design: A Unified 20

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

CCDPP (CCD PreProcessing) module

define SZ_ROW 64

#

• Performs zero-bias adjustment #define SZ_COL 64

• CcdppCapture uses CcdCapture and CcdPopPixel to obtain static char buffer[SZ_ROW][SZ_COL];

image static unsigned rowIndex, colIndex;

• Performs zero-bias adjustment after each row read in void CcdppInitialize() {

rowIndex = -1;

void CcdppCapture(void) { colIndex = -1;

char bias; }

CcdCapture(); char CcdppPopPixel(void) {

for(rowIndex=0; rowIndex<SZ_ROW; rowIndex++) { char pixel;

for(colIndex=0; colIndex<SZ_COL; colIndex++) { pixel = buffer[rowIndex][colIndex];

buffer[rowIndex][colIndex] = CcdPopPixel(); if( ++colIndex == SZ_COL ) {

} colIndex = 0;

bias = (CcdPopPixel() + CcdPopPixel()) / 2; if( ++rowIndex == SZ_ROW ) {

for(colIndex=0; colIndex<SZ_COL; colIndex++) { colIndex = -1;

buffer[rowIndex][colIndex] -= bias; rowIndex = -1;

} }

} }

rowIndex = 0; return pixel;

colIndex = 0; }

} Embedded Systems Design: A Unified 21

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

UART module

• Actually a half UART

– Only transmits, does not receive

• UartInitialize is passed name of file to output to

• UartSend transmits (writes to output file) bytes at a time

#include <stdio.h>

static FILE *outputFileHandle;

void UartInitialize(const char *outputFileName) {

outputFileHandle = fopen(outputFileName, "w");

}

void UartSend(char d) {

fprintf(outputFileHandle, "%i\n", (int)d);

}

Embedded Systems Design: A Unified 22

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

CODEC module

static short ibuffer[8][8], obuffer[8][8], idx;

• Models FDCT encoding void CodecInitialize(void) { idx = 0; }

• ibuffer holds original 8 x 8 block void CodecPushPixel(short p) {

• obuffer holds encoded 8 x 8 block if( idx == 64 ) idx = 0;

ibuffer[idx / 8][idx % 8] = p; idx++;

• CodecPushPixel called 64 times to fill }

ibuffer with original block void CodecDoFdct(void) {

int x, y;

• CodecDoFdct called once to for(x=0; x<8; x++) {

transform 8 x 8 block for(y=0; y<8; y++)

obuffer[x][y] = FDCT(x, y, ibuffer);

– Explained in next slide }

idx = 0;

• CodecPopPixel called 64 times to }

retrieve encoded block from obuffer short CodecPopPixel(void) {

short p;

if( idx == 64 ) idx = 0;

p = obuffer[idx / 8][idx % 8]; idx++;

return p;

}

Embedded Systems Design: A Unified 23

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

CODEC (cont.)

• Implementing FDCT formula

C(h) = if (h == 0) then 1/sqrt(2) else 1.0 static const short COS_TABLE[8][8] = {

F(u,v) = ¼ x C(u) x C(v) Σ Σ D x

x=0..7 y=0..7 xy { 32768, 32138, 30273, 27245, 23170, 18204, 12539, 6392 },

cos(π(2u + 1)u/16) x cos(π(2y + 1)v/16) { 32768, 27245, 12539, -6392, -23170, -32138, -30273, -18204 },

• Only 64 possible inputs to COS, so table can { 32768, 18204, -12539, -32138, -23170, 6392, 30273, 27245 },

be used to save performance time { 32768, 6392, -30273, -18204, 23170, 27245, -12539, -32138 },

– Floating-point values multiplied by 32,678 and { 32768, -6392, -30273, 18204, 23170, -27245, -12539, 32138 },

rounded to nearest integer { 32768, -18204, -12539, 32138, -23170, -6392, 30273, -27245 },

– 32,678 chosen in order to store each value in 2 { 32768, -27245, 12539, 6392, -23170, 32138, -30273, 18204 },

bytes of memory { 32768, -32138, 30273, -27245, 23170, -18204, 12539, -6392 }

– Fixed-point representation explained more later };

• FDCT unrolls inner loop of summation, static int FDCT(int u, int v, short img[8][8]) {

implements outer summation as two double s[8], r = 0; int x;

consecutive for loops for(x=0; x<8; x++) {

s[x] = img[x][0] * COS(0, v) + img[x][1] * COS(1, v) +

static short ONE_OVER_SQRT_TWO = 23170; img[x][2] * COS(2, v) + img[x][3] * COS(3, v) +

static double COS(int xy, int uv) { img[x][4] * COS(4, v) + img[x][5] * COS(5, v) +

return COS_TABLE[xy][uv] / 32768.0; img[x][6] * COS(6, v) + img[x][7] * COS(7, v);

} }

static double C(int h) { for(x=0; x<8; x++) r += s[x] * COS(x, u);

return h ? 1.0 : ONE_OVER_SQRT_TWO / 32768.0; return (short)(r * .25 * C(u) * C(v));

} }

Embedded Systems Design: A Unified 24

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

CNTRL (controller) module

• Heart of the system void CntrlSendImage(void) {

• CntrlInitialize for consistency with other modules only for(i=0; i<SZ_ROW; i++)

for(j=0; j<SZ_COL; j++) {

• CntrlCaptureImage uses CCDPP module to input temp = buffer[i][j];

image and place in buffer UartSend(((char*)&temp)[0]); /* send upper byte */

UartSend(((char*)&temp)[1]); /* send lower byte */

• CntrlCompressImage breaks the 64 x 64 buffer into 8 x }

}

8 blocks and performs FDCT on each block using the }

CODEC module

– void CntrlCompressImage(void) {

Also performs quantization on each block for(i=0; i<NUM_ROW_BLOCKS; i++)

• CntrlSendImage transmits encoded image serially using

UART module for(j=0; j<NUM_COL_BLOCKS; j++) {

for(k=0; k<8; k++)

void CntrlCaptureImage(void) { for(l=0; l<8; l++)

CcdppCapture(); CodecPushPixel(

for(i=0; i<SZ_ROW; i++) (char)buffer[i * 8 + k][j * 8 + l]);

for(j=0; j<SZ_COL; j++) CodecDoFdct();/* part 1 - FDCT */

buffer[i][j] = CcdppPopPixel(); for(k=0; k<8; k++)

} for(l=0; l<8; l++) {

#define SZ_ROW 64 buffer[i * 8 + k][j * 8 + l] = CodecPopPixel();

#define SZ_COL 64 /* part 2 - quantization */

#define NUM_ROW_BLOCKS (SZ_ROW / 8) buffer[i*8+k][j*8+l] >>= 6;

#define NUM_COL_BLOCKS (SZ_COL / 8) }

static short buffer[SZ_ROW][SZ_COL], i, j, k, l, temp; }

void CntrlInitialize(void) {} }

Embedded Systems Design: A Unified 25

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Putting it all together

• Main initializes all modules, then uses CNTRL module to capture,

compress, and transmit one image

• This system-level model can be used for extensive experimentation

– Bugs much easier to correct here rather than in later models

int main(int argc, char *argv[]) {

char *uartOutputFileName = argc > 1 ? argv[1] : "uart_out.txt";

char *imageFileName = argc > 2 ? argv[2] : "image.txt";

/* initialize the modules */

UartInitialize(uartOutputFileName);

CcdInitialize(imageFileName);

CcdppInitialize();

CodecInitialize();

CntrlInitialize();

/* simulate functionality */

CntrlCaptureImage();

CntrlCompressImage();

CntrlSendImage();

}

Embedded Systems Design: A Unified 26

Hardware/Software Introduction, (c) 2000 Vahid/Givargis Design

• Determine system’s architecture

– Processors

• Any combination of single-purpose (custom or standard) or general-purpose processors

– Memories, buses

• Map functionality to that architecture

– Multiple functions on one processor

– One function on one or more processors

• Implementation

– A particular architecture and mapping

– Solution space is set of all implementations

• Starting point

– Low-end general-purpose processor connected to flash memory

• All functionality mapped to software running on processor

• Usually satisfies power, size, and time-to-market constraints

• If timing constraint not satisfied then later implementations could:

– use single-purpose processors for time-critical functions

– rewrite functional specification

Embedded Systems Design: A Unified 27

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Implementation 1: Microcontroller alone

• Low-end processor could be Intel 8051 microcontroller

• Total IC cost including NRE about $5

• Well below 200 mW power

• Time-to-market about 3 months

• However, one image per second not possible

– 12 MHz, 12 cycles per instruction

• Executes one million instructions per second

– CcdppCapture has nested loops resulting in 4096 (64 x 64) iterations

• ~100 assembly instructions each iteration

• 409,000 (4096 x 100) instructions per image

• Half of budget for reading image alone

– Would be over budget after adding compute-intensive DCT and

Huffman encoding

Embedded Systems Design: A Unified 28

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Implementation 2:

Microcontroller and CCDPP

EEPROM RAM

8051

UART

SOC CCDPP

• CCDPP function implemented on custom single-purpose processor

– Improves performance – less microcontroller cycles

– Increases NRE cost and time-to-market

– Easy to implement

• Simple datapath

• Few states in controller

• Simple UART easy to implement as single-purpose processor also

• EEPROM for program memory and RAM for data memory added as well

Embedded Systems Design: A Unified 29

Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Microcontroller

• Synthesizable version of Intel 8051 available

– Written in VHDL

– Captured at register transfer level (RTL) Block diagram of Intel 8051 processor core

• Fetches instruction from ROM

• Decodes using Instruction Decoder 4K ROM

Instruction

Decoder

• ALU executes arithmetic operations Controller

– Source and destination registers reside in 128

ALU RAM

RAM

• Special data movement instructions used to To External Memory Bus

load and store externally

• Special program generates VHDL description

of ROM from output of C compiler/linker

Embedded Systems Design: A Unified 30

Hardware/Software Introduction, (c) 2000 Vahid/Givargis


PAGINE

47

PESO

264.31 KB

AUTORE

Atreyu

PUBBLICATO

+1 anno fa


DESCRIZIONE DISPENSA

A simple digital camera captures images, stores images in digital format (no film; multiple images stored in camera, whose number depends on amount of memory and bits used per image), downloads images to PC. Systems-on-a-chip and high-capacity flash memory are only recently possible. There are many more features with real digital camera: variable size images, image deletion, digital stretching, zooming in and out.


DETTAGLI
Corso di laurea: Corso di laurea magistrale in ingegneria delle telecomunicazioni
SSD:
Università: L'Aquila - Univaq
A.A.: 2011-2012

I contenuti di questa pagina costituiscono rielaborazioni personali del Publisher Atreyu di informazioni apprese con la frequenza delle lezioni di Sistemi embedded e studio autonomo di eventuali libri di riferimento in preparazione dell'esame finale o della tesi. Non devono intendersi come materiale ufficiale dell'università L'Aquila - Univaq o del prof Pomante Luigi.

Acquista con carta o conto PayPal

Scarica il file tutte le volte che vuoi

Paga con un conto PayPal per usufruire della garanzia Soddisfatto o rimborsato

Recensioni
Ti è piaciuto questo appunto? Valutalo!

Altri appunti di Sistemi embedded

Programmazione concorrente
Dispensa
Sistemi Embedded
Dispensa
SystemC
Dispensa
Real-time and embedded operating systems
Dispensa