Top Banner

Click here to load reader

35

Training report on Embedded Systems and MATLAB

Apr 16, 2017

Download

Engineering

Aswin Sreeraj
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Training report on Embedded Systems and MATLAB

Govind Ballabh Pant Govt. Engineering College

Okhla, New Delhi -110020

REPORT OF INDUSTRIAL TRAINING

At WebTek Labs Pvt. Ltd.

On Embedded Systems & MATLAB

SUBMITTED BY:

Aswin Sreeraj

Electronics and Communication Engineering

5th SEM

02320902814

Page 2: Training report on Embedded Systems and MATLAB

INDEX

Page No.

1. About WebTek Labs 04

2. Acknowledgement 05

3. Declaration 06

4. Introduction 07

a. Embedded Systems 07

b. MATLAB 08

5. Embedded System 09

6. Microcontroller 10

a. Features 10

b. Microcontroller vs. Microprocessor 11

7. ATmega16 13

a. Features 13

b. Pin Diagram 14

c. Pin Descriptions 15

d. Software 16

e. Block Diagram 17

f. I/O ports 18

g. DC motor interfacing 20

h. LCD interfacing 21

i. Serial Communication 22

i. ATmega16 USART 22

8. MATLAB 24

a. The MATLAB System 25

b. Data types 26

c. Variables 26

d. Matrices 26

e. Structures 27

f. Functions 27

g. Function Handles 28

h. Classes and Object-Oriented Programming 28

i. Graphics and GUI Programming 28

Page 3: Training report on Embedded Systems and MATLAB

9. Image Processing in MATLAB 30

a. Capabilities 30

b. Image Representation 30

c. Reading and writing image files 31

d. Basic operations 31

e. Filters 33

i. Linear Filter 33

ii. Non-linear Filter 33

10. Conclusion 34

11. Bibliography 35

Page 4: Training report on Embedded Systems and MATLAB

About WEBTEK LABS

WebTek Labs Pvt. Ltd. is recognized as a leading IT solution providing organization with a dynamic and fast growing team of diversely talented individuals. Incorporated in 2001, they initially started with Recruitment & Staffing services. They paralleled this by providing knowledge and skill development certification training programs. WebTek Certified Tester (WCT) Program that aims to provide IT companies trained software Testers has reached soaring heights of recognition over the years. Few years later after its inception, WebTek Labs added Software development & testing services to the portfolio.

Having partnered and worked with some of the leading names across Education, IT, ITES, Banking, Insurance, Aviation, Retail, Healthcare, Hospitality, Media, Manufacturing and FMCG sectors, WebTek Labs has explored business opportunities in software solutions with the Government, Corporate and Institutes.

With over a decade of experience they create and deliver high-impact solutions, enabling their clients to achieve their business goals and enhance their competitiveness. WebTek's Research & Development team consistently innovates to provide up-to-date solutions keeping in pace with changing times. Their main business verticals are

Recruitment & Staffing Software Development and Testing Services Digital Marketing Enterprise Mobility Certifications & Trainings for Career Management Software solutions

Page 5: Training report on Embedded Systems and MATLAB

ACKNOWLEDGEMENT

I would like to express my sincere gratitude to WebTek Labs for giving

me an opportunity to undergo Industrial Training for six weeks as well as

for providing me the knowledge of Embedded Systems and MATLAB. I

would also like to thank alla the technical experts, engineers and

executives for explaining the practical aspects of the theoretical

knowledge.

It is my pleasure to be indebted to various people, who directly or

indirectly contributed in the development of this work and who influenced

my thinking, behaviour, and acts during the course of study.

Lastly, I would like to thank the almighty and my parents for their moral

support and my friends with whom I shared my day-to-day experience

and received lots of suggestions that improved my quality of work.

Page 6: Training report on Embedded Systems and MATLAB

DECLARATION

I, Aswin Sreeraj, student of B.Tech 3rd year, studying at

Govind Ballabh Pant Govt. Engineering College, Okhla,

hereby declare that the summer training report on

“Embedded systems and MATLAB” submitted to Guru

Gobind Singh Indraprastha University in partial fulfilment

of Degree of Bachelor of Technology is the original work

conducted by me.

The information and data given in the report is authentic

to the best of my knowledge. This summer training

report is not being submitted to any other University for

award of any other Degree, Diploma and Fellowship.

Page 7: Training report on Embedded Systems and MATLAB

INTRODUCTION

Embedded Systems

An embedded system is a system that has software embedded into

computer-hardware, which makes a system dedicated for an application

(s) or specific part of an application or product or part of a larger system.

The uses of embedded systems are virtually limitless, because every day

new products are introduced to the market that utilize embedded

computers in many ways. In recent years, hardware such as

microprocessors, microcontrollers, and FPGA chips have become much

cheaper. So when implementing a new form of control, it's wiser to just

buy the generic chip and write your own custom software for it.

Producing a custom-made chip to handle a particular task or set of tasks

costs far more time and money. Many embedded computers even come

with extensive libraries, so that "writing your own software" becomes a

very trivial task indeed.

Embedded systems are often required to provide Real-Time response. A Real-Time system is defined as a system whose correctness depends on the timeliness of its response. Examples of such systems are flight control systems of an aircraft, sensor systems in nuclear reactors and power plants. For these systems, delay in response is a fatal error. A more relaxed version of Real-Time Systems, is the one where timely response with small delays is acceptable. Example of such a system would be the Scheduling Display System on the railway platforms. In technical terminology, Real-Time Systems can be classified as:

Hard Real-Time Systems - systems with severe constraints on the timeliness of the response.

Soft Real-Time Systems - systems which tolerate small variations in response times.

Hybrid Real-Time Systems - systems which exhibit both hard and soft constraints on its performance.

Embedded systems are playing important roles in our lives every day, even though they might not necessarily be visible. Some of the embedded systems we use every day control the menu system on television, the timer in a microwave oven, a cellphone, an MP3 player or any other device with some amount of intelligence built-in. Embedded systems is a rapidly growing industry where growth opportunities are numerous.

Page 8: Training report on Embedded Systems and MATLAB

MATLAB

MATLAB stands for MATRIX laboratory. It is a high level technical

computing language and interactive environment for algorithm

development, data visualization, data analysis and numeric computation.

MATLAB has many advantages compared to conventional computer

languages (e.g., C, FORTRAN) for solving technical problems. MATLAB

is an interactive system whose basic data element is an array that does

not require dimensioning. The software package has been commercially

available since 1984 and is now considered as a standard tool at most

universities and industries worldwide.

It has powerful built-in routines that enable a very wide variety of

computations. It also has easy to use graphics commands that make the

visualization of results immediately available. Specific applications are

collected in packages referred to as toolbox. There are toolboxes for

signal processing, symbolic computation, control theory, simulation,

optimization, and several other fields of applied science and engineering.

Below we see the schematic diagram of a typical project, showing which

steps are often realised with MATLAB

Page 9: Training report on Embedded Systems and MATLAB

Embedded system An embedded system is a computer system with a dedicated function

within a larger mechanical or electrical system, often with real-time

computing constraints.[1][2] It is embedded as part of a complete device

often including hardware and mechanical parts. Embedded systems are

designed to do some specific task, rather than be a general-purpose

computer for multiple tasks. Some also have real-time performance

constraints that must be met, for reasons such as safety and usability;

others may

have low or no

performance

requirements,

allowing the

system

hardware to be

simplified to

reduce costs.

Properties of

typically

embedded

computers

when

compared with general-purpose counterparts are low power

consumption, small size, rugged operating ranges, and low per-unit cost.

Embedded systems range from no user interface at all, in systems

dedicated only to one task, to complex graphical user interfaces that

resemble modern computer desktop operating systems

Modern embedded systems are often based on microcontrollers which

have on-chip peripherals, thus reducing power consumption, size and

cost. Embedded systems talk with the outside world via peripherals, like

Serial Communication Interfaces, Timers, ADC/DAC, USB, Ethernet, etc.

Embedded systems are commonly found in consumer, cooking,

industrial, automotive, medical, commercial and military applications.

Embedded systems range from portable devices such as digital watches

and MP3 players, to large stationary installations like traffic lights, factory

controllers, and largely complex systems like hybrid vehicles, MRI, and

avionics.

Page 10: Training report on Embedded Systems and MATLAB

Microcontroller

A microcontroller (or MCU, short for microcontroller unit) is a small

computer (SoC) on a single integrated circuit containing a processor

core, memory, and programmable input/output peripherals. Program

memory in the form of Ferroelectric RAM, NOR flash or OTP ROM is

also often included on chip, as

well as a typically small

amount of RAM.

A microcontroller can be

considered a self-contained

system with a processor,

memory and peripherals and

can be used as an embedded

system.[13] The majority of

microcontrollers in use today

are embedded in other

machinery, such as automobiles, telephones, appliances, and

peripherals for computer systems.

Features:

Microcontrollers are "embedded" inside some other device (often a

consumer product) so that they can control the features or actions

of the product. Another name for a microcontroller, therefore, is

"embedded controller."

Microcontrollers are dedicated to one task and run one specific

program. The program is stored in ROM (read-only memory) and

generally does not change.

Microcontrollers are often low-power devices.

A microcontroller has a dedicated input device and often (but not

always) has a small LED or LCD display for output. A

microcontroller also takes input from the device it is controlling and

controls the device by sending signals to different components in

the device.

A microcontroller is often small and low cost.

A microcontroller is often, but not always, ruggedized in some way.

The microcontroller controlling a car's engine, for example, has to

work in temperature extremes that a normal computer generally

cannot handle.

Page 11: Training report on Embedded Systems and MATLAB

As of 2008, there are several dozen microcontroller architectures and

vendors including:

ARM core processors (many vendors)

o ARM Cortex-M cores are specifically targeted towards

microcontroller applications

Atmel AVR (8-bit), AVR32 (32-bit), and AT91SAM (32-bit)

Cypress Semiconductor's M8C Core used in their PSoC

(Programmable System-on-Chip)

Freescale ColdFire (32-bit) and S08 (8-bit)

Freescale 68HC11 (8-bit), and others based on the Motorola 6800

family

Intel 8051, also manufactured by NXP Semiconductors, Infineon

and many others

Infineon: 8-bit XC800, 16-bit XE166, 32-bit XMC4000 (ARM based

Cortex M4F), 32-bit TriCore and, 32-bit Aurix Tricore Bit

microcontrollers

MIPS

Microchip Technology PIC, (8-bit PIC16, PIC18, 16-bit dsPIC33 /

PIC24), (32-bit PIC32)

Rabbit 2000 (8-bit)

Renesas Electronics: RL78 16-bit MCU; RX 32-bit MCU; SuperH;

V850 32-bit MCU; H8; R8C 16-bit MCU

Silicon Laboratories Pipelined 8-bit 8051 Microcontrollers and

mixed-signal ARM-based 32-bit microcontrollers

STMicroelectronics STM8 (8-bit), ST10 (16-bit) and STM32 (32-bit)

Texas Instruments TI MSP430 (16-bit), MSP432 (32-bit), C2000

(32-bit)

Toshiba TLCS-870 (8-bit/16-bit)

Microcontroller vs. microprocessor

Microprocessor is an IC which has only the CPU inside them. These microprocessors don’t have RAM, ROM, and other peripheral on the chip. A system designer has to add them externally to make them functional.

Microcontroller has a CPU, in addition with a fixed amount of RAM, ROM and other peripherals all embedded on a single chip. Today different

Page 12: Training report on Embedded Systems and MATLAB

manufacturers produce microcontrollers with a wide range of features available in different versions.

Microcontrollers are designed to

perform specific tasks. Specific

means depending on the input,

some processing needs to be done

and output is delivered. For

example, keyboards, mouse,

washing machine, bikes,

telephone, watches, etc. Since the

applications are very specific, they

need small resources like RAM,

ROM, I/O ports etc. and hence can

be embedded on a single chip.

This in turn reduces the size and

the cost.

Microprocessor find applications

where tasks are unspecific like

developing software, games,

websites, photo editing, creating documents etc. In such cases the

relationship between input and

output is not defined.

The clock speed of the

Microprocessor is quite high

as compared to the

microcontroller. Whereas the

microcontrollers operate from

a few MHz to 30 to 50 MHz,

today’s microprocessor

operate above 1GHz as they

perform complex tasks.

A microcontroller is far

cheaper than a

microprocessor. However

microcontroller cannot be used

in place of microprocessor and using a microprocessor is not advised in

place of a microcontroller as it makes the application quite costly

Page 13: Training report on Embedded Systems and MATLAB

ATmega16 The microcontroller used is ATmega16, which is a 40-pin IC and belongs

to the MegaAVR category of AVR family. AVR is a family of

microcontrollers de. These are modified Harvard architecture 8-bit RISC

single-chip microcontrollers. AVR was one of the first microcontroller

families to use on-chip flash memory for program storage, as opposed to

one-time programmable ROM, EPROM, or EEPROM used by other

microcontrollers at the time.Atmel Corporation is an American-based

designer and manufacturer of semiconductors, founded in 1984. The

company focuses on embedded systems built around

microcontrollers.The ATmega16 is a low-power CMOS 8-bit

microcontroller based on the AVR enhanced RISC architecture.

Features: High-performance, Low-power Atmel AVR 8-bit Microcontroller Advanced RISC Architecture

o 131 Powerful Instructions – Most o Single-clock Cycle Execution o 32 x 8 General Purpose Working Registers o Fully Static Operation o Up to 16 MIPS Throughput at 16 MHz

High Endurance Non-volatile Memory segments o 16 Kbytes of In-System Self-programmable Flash program

memory o 512 Bytes EEPROM o 1 Kbyte Internal SRAM o Write/Erase Cycles: 10,000 Flash/100,000 EEPROM o Data retention: 20 years at 85°C/100 years at 25°C

Peripheral Features o Two 8-bit Timer/Counters with Separate Prescalers and

Compare Modes o One 16-bit Timer/Counter with Separate Prescaler, Compare

Mode, and Capture Mode o Real Time Counter with Separate Oscillator o Four PWM Channels o 8-channel, 10-bit ADC

8 Single-ended Channels 7 Differential Channels in TQFP Package Only 2 Differential Channels with Programmable Gain at 1x,

10x, or 200x o Byte-oriented Two-wire Serial Interface

Page 14: Training report on Embedded Systems and MATLAB

o Programmable Serial USART o Master/Slave SPI Serial Interface o On-chip Analog Comparator

Special Microcontroller Features o Power-on Reset and Programmable Brown-out Detection o Internal Calibrated RC Oscillator o External and Internal Interrupt Sources

I/O and Packages o 32 Programmable I/O Lines o 40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF

Operating Voltages: 4.5V - 5.5V Speed Grades: 0 - 16 MHz

PIN DIAGRAM

Page 15: Training report on Embedded Systems and MATLAB

PIN DESCRIPTIONS

VCC & GND Digital supply voltage & Ground. Port A (PA7..PA0) Port A serves as the analog inputs to the

A/D Converter. Port A also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can provide internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink and source capability. When pins PA0 to PA7 are used as inputs and are externally pulled low, they will source current if the internal pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Port B (PB7..PB0) Port B is an 8-bit bi-directional I/O port with

internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Port C (PC7..PC0) Port C is an 8-bit bi-directional I/O port with

internal pull-up resistors (selected for each bit). The Port C output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Port D (PD7..PD0) Port D is an 8-bit bi-directional I/O port with

internal pull-up resistors (selected for each

Page 16: Training report on Embedded Systems and MATLAB

bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the clock is not running.

RESET Reset Input. A low level on this pin for

longer than the minimum pulse length will generate a reset, even if the clock is not running. Shorter pulses are not guaranteed to generate a reset.

XTAL1 Input to the inverting Oscillator amplifier and

input to the internal clock operating circuit. XTAL2 O/P from the inverting Oscillator amplifier. AVCC AVCC is the supply voltage pin for Port A

and the A/D Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter.

AREF AREF is the analog reference pin for the

A/D Converter

SOFTWARE

The software used for communicating with the hardware of the ATmega16 microcontroller is WinAVR which uses C language for writing the codes. The C code is compiled and converted into hex code. The programmer used is usbarp.

WinAVR 2010 is a suite of executable, open source software development tools for the Atmel AVR series of RISC microprocessors hosted on the Windows platform. It includes the GNU GCC compiler for C and C++. It is used by AVR Studio for compiling programs/applications.

Page 17: Training report on Embedded Systems and MATLAB

Block Diagram

Page 18: Training report on Embedded Systems and MATLAB

I/O Ports AVR is 8 bit microcontroller. All its ports are 8 bit wide. Every port has 3 registers associated with it each one with 8 bits. Every bit in those registers configure pins of particular port. Bit0 of these registers is associated with Pin0 of the port, Bit1 of these registers is associated with Pin1 of the port …and like wise for other bits.

DDRx register

DDRx (Data Direction Register) configures data direction of port pins. Means its setting determines whether port pins will be used for input or output. Writing 0 to a bit in DDRx makes corresponding port pin as input, while writing 1 to a bit in DDRx makes corresponding port pin as output.

Example:

to make all pins of port A as input pins : DDRA = 0b00000000;

to make all pins of port A as output pins : DDRA = 0b11111111;

to make lower nibble of port B as output and higher nibble as input : DDRB = 0b00001111;

PINx register

PINx (Port PIN) used to read data from port pins. In order to read the data from port pin, first you have to change port’s data direction to input. This is done by setting bits in DDRx to zero. If port is made output, then reading PINx register will give you data that has been output on port pins. Now there are two input modes. Either you can use port pins as tri stated inputs or you can activate internal pull up. It will be explained shortly.

Example:

To read data from port A.

DDRA = 0x00; //Set port a as input

x = PINA; //Read contents of port a

Page 19: Training report on Embedded Systems and MATLAB

PORTx register

PORTx is used for two purposes.

1) To output data : when port is configured as output

When you set bits in DDRx to 1, corresponding pins becomes output pins. Now you can write data into respective bits in PORTx register. This will immediately change state of output pins according to data you have written. In other words to output data on to port pins, you have to write it into PORTx register. However do not forget to set data direction as output.

example :

to output 0xFF data on port b

DDRB = 0b11111111; //set all pins of port b as outputs

PORTB = 0xFF; //write data on port

to output data in variable x on port a

DDRA = 0xFF; //make port a as output

PORTA = x; //output variable on port

to output data on only 0th bit of port c

DDRC.0 = 1; //set only 0th pin of port c as output

PORTC.0 = 1; //make it high.

2) To activate/deactivate pull up resistors – when port is configures as input

When you set bits in DDRx to 0, i.e. make port pins as inputs, then corresponding bits in PORTx register are used to activate/deactivate pull-up registers associated with that pin. In order to activate pull-up resister, set bit in PORTx to 1, and to deactivate (tri-state) set it to 0.

However, if you configure pin as tri state. Then pin goes into state of high impedance. It is now simply connected to input of some OpAmp inside the µC and no other circuit is driving it from µC. Thus pin has very high impedance. In this case, if pin is left floating ,then even small static charge present on surrounding objects can change logic state of pin. If you try to read corresponding bit in pin register, its state cannot be predicted. This may cause your program to go haywire, if it depends on input from that particular pin.

Page 20: Training report on Embedded Systems and MATLAB

DC MOTOR INTERFACING

The simplest DC rotating machine consists of a single loop of wire rotating about a fixed axis. The magnetic field is supplied by the North and South poles of the magnet.

Rotor is the rotating part.Stator is the stationary part. We can reverse the motor direction the simply by reversing the

power supply connection of motor. It means motor is bipolar device.

Necessary Medium to Operate

We are working on microcontroller and the maximum output current that it can provide is 20mA.

But our motor works on 1Amp current so to remove this problem we will have to connect motor driver IC L293D in between the microcontroller and motor.

PIN DESCRIPTION

Figure: L293D Figure: Interfacing with ATmega16

Page 21: Training report on Embedded Systems and MATLAB

LCD INTERFACING LCD’s are all around us so liquid crystal displays are very useful

in these days. It is a kind of display that is made up of a special matter state

formed using liquid and crystal both , it’s a forth state of matter The most popular one is 16x2 LCD module. It has 2 rows & 16

columns. The intelligent displays are two types: o Text Display o Graphics Display

PIN DESCRIPTION

Figure: pin configuration for 16 X 2 LCD 8 data pins D7:D0 Bi-directional data/command pins. Alphanumeric characters are

sent in ASCII format. RS: Register Select

RS = 0 -> Command Register is selected RS = 1 -> Data Register is selected

R/𝑊: Read or Write 0 -> Write, 1 -> Read

E: Enable (Latch data) Used to latch the data present on the data pins. A high-to-low edge is needed to latch the data. VEE: contrast control. VDD & VSS: Power supply

VDD= +5V, VSS=GND

Page 22: Training report on Embedded Systems and MATLAB

Serial Communication In computing, a serial port is a serial communication physical interface through which information transfers in or out one bit at a time.Throughout most of the history of personal computers, data transfer through serial ports connected the computer to devices such as terminals and various peripherals. For serial communication with devices like computer, ATmega16 is interfaced with MAX232. The reason for using MAX232 is that atmega16 works at TTL voltage level and for serial port we require other voltage level, max232 converts the TTL voltage level to the required voltage level. Atmega32 will receive the signal from MAX232 and transmit to max232 which will be received by serial port.

The MAX232 is a dual transmitter / dual receiver that typically is used to convert the RX, TX, CTS, RTS signals. It converts signals from a TIA-232 (RS-232) serial port to signals suitable for use in TTL-compatible digital logic circuits.

ATmega16 USART USART stands for Universal Synchronous Asynchronous Receiver/Transmitter. This is of the synchronous type, i.e. the data bits are synchronized with the clock pulses. Main task of Serial USART is to initialize the serial port, sending a character, receiving a character and sending/receiving formatted strings.

USART Pin Configuration

1. RxD: USART Receiver Pin (ATMega8 Pin 2; ATMega16/32 Pin 14) 2. TxD: USART Transmit Pin (ATMega8 Pin 3; ATMega16/32 Pin 15) 3. XCK: USART Clock Pin (ATMega8 Pin 6; ATMega16/32 Pin 1)

Registers

1) UDR: USART Data Register (16-bit): The USART Transmit Data

Buffer Register and USART Receive Data Buffer Registers share

the same I/O address referred to as USART Data Register or UDR.

Page 23: Training report on Embedded Systems and MATLAB

2) UCSRA: USART Control and Status Register A (8-bit): Used for

setting various status flags and control siganls.

3) UCSRB: USART Control and Status Register B (8-bit): Used for

setting various status flags and control siganls.

4) UCSRC: USART Control and Status Register C (8-bit): Used for

setting various status flags and control siganls.

5) UBRR: USART Baud Rate Register (16-bit): The baud rate of

USART is set using the 16-bit wide USART Baud Rate Register

(UBRR). The 16-bit UBRR register is comprised of two 8-bit

registers – UBRRH (high) and UBRRL (low). Since there can be

only specific baud rate values, there can be specific values for

UBRR, which when converted to binary will not exceed 12 bits.

Hence there are only 12 bits reserved for UBRR[11:0].

Figure: MAX232 interfaced with ATmega16

Page 24: Training report on Embedded Systems and MATLAB

MATLAB MATLAB (matrix laboratory) is a multi-paradigm numerical computing

environment and fourth-generation programming language. A proprietary

programming language developed by MathWorks, MATLAB allows

matrix manipulations, plotting of functions and data, implementation of

algorithms, creation of user interfaces, and interfacing with programs

written in other languages, including C, C++, C#, Java, Fortran and

Python.

MATLAB is a high-performance language for technical computing. It

integrates computation, visualization, and programming in an easy-to-

use environment where problems and solutions are expressed in familiar

mathematical notation. Typical uses include:

Math and computation

Algorithm development

Modeling, simulation, and prototyping

Data analysis, exploration, and visualization

Scientific and engineering graphics

Application development, including Graphical User Interface

building

MATLAB is an interactive system whose basic data element is an array

that does not require dimensioning. This allows you to solve many

technical computing problems, especially those with matrix and vector

formulations, in a fraction of the time it would take to write a program in a

scalar noninteractive language such as C or Fortran. The name MATLAB

stands for matrix laboratory. MATLAB was originally written to provide

easy access to matrix software developed by the LINPACK and

EISPACK projects, which together represent the state-of-the-art in

software for matrix computation.

MATLAB has evolved over a period of years with input from many users.

In university environments, it is the standard instructional tool for

introductory and advanced courses in mathematics, engineering, and

science. In industry, MATLAB is the tool of choice for high-productivity

research, development, and analysis.

Page 25: Training report on Embedded Systems and MATLAB

MATLAB features a family of application-specific solutions called

toolboxes. Very important to most users of MATLAB, toolboxes allow you

to learn and apply specialized technology. Toolboxes are comprehensive

collections of MATLAB functions (M-files) that extend the MATLAB

environment to solve particular classes of problems. Areas in which

toolboxes are available include signal processing, control systems,

neural networks, fuzzy logic, wavelets, simulation, and many others..

The MATLAB System

The MATLAB system consists of five main parts:

The MATLAB language: This is a high-level matrix/array language

with control flow statements, functions, data structures, input/output,

and object-oriented programming features. It allows both

"programming in the small" to rapidly create quick and dirty throw-

away programs, and "programming in the large" to create complete

large and complex application programs.

The MATLAB working environment.: This is the set of tools and

facilities that you work with as the MATLAB user or programmer. It

includes facilities for managing the variables in your workspace and

importing and exporting data. It also includes tools for developing,

managing, debugging, and profiling M-files, MATLAB's applications

Handle Graphics: This is the MATLAB graphics system. It includes

high-level commands for two-dimensional and three-dimensional data

visualization, image processing, animation, and presentation graphics.

It also includes low-level commands that allow you to fully customize

the appearance of graphics as well as to build complete Graphical

User Interfaces on your MATLAB applications.

The MATLAB mathematical function library: This is a vast collection of

computational algorithms ranging from elementary functions like sum,

sine, cosine, and complex arithmetic, to more sophisticated functions

like matrix inverse, matrix eigenvalues, Bessel functions, and fast

Fourier transforms.

Page 26: Training report on Embedded Systems and MATLAB

The MATLAB Application Program Interface (API): This is a library

that allows you to write C and Fortran programs that interact with

MATLAB. It include facilities for calling routines from MATLAB

(dynamic linking), calling MATLAB as a computational engine, and for

reading and writing MAT-files.

DATA TYPES

By default, all constant and variables in MATLAB are double precision

floating point. All computations are also performed in double precision by

default. Double precision floating-point numbers in MATLAB have a finite

precision of roughly 16 significant decimal digits and a finite range of

roughly 10−308 to 10−308

.

VARIABLES

Variable names consist of a letter, followed by any number of letters,

digits, or underscores.

>>x = 17 >> y = 3*sin(x) x = y = 17 -1.6097 3.0000

MATLAB uses only the first 31 characters of a variable name. MATLAB

is case sensitive; it distinguishes between uppercase and lowercase

letters. A and a are not the same variable. To view the value(s) assigned

to any variable, simply enter the variable name in the Command window.

MATRICES

A matrix is entered as a list of its elements following a few basic

conventions:

Separate the elements of a row with blanks or commas.

Use a semicolon, ;, to indicate the end of each row.

Surround the entire list of elements with square brackets, [ ]

.

Page 27: Training report on Embedded Systems and MATLAB

For example, type in the Command window:

>>A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

MATLAB displays the matrix you just entered:

A =

16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

The element in row iand column j of A is denoted by A(i,j). If you try to

use the value of an element outside of the matrix, it is an error. On the

other hand, if you store a value in an element outside of the matrix, the

size increases auto

matically to accommodate the new element. A scalar is equivalent to a

1x1 matrix. In thiscase, the square brackets are not required:

A = 16

STRUCTURES

MATLAB has structure data types. Since all variables in MATLAB are

arrays, a more adequate name is "structure array", where each element

of the array has the same field names. In addition, MATLAB supports

dynamic field names (field look-ups by name, field manipulations, etc.).

Unfortunately, MATLAB JIT does not support MATLAB structures,

therefore just a simple bundling of various variables into a structure will

come at a cost.

FUNCTIONS

When creating a MATLAB function, the name of the file should match the

name of the first function in the file. Valid function names begin with an

alphabetic character, and can contain letters, numbers, or underscores.

Functions are also often case sensitive.

Page 28: Training report on Embedded Systems and MATLAB

FUNCTION HANDLES

MATLAB supports elements of lambda calculus by introducing function

handles, or function references, which are implemented either in .m files

or anonymous nested functions.

CLASSES AND OBJECT-ORIENTED PROGRAMMING

MATLAB supports object-oriented programming including classes,

inheritance, virtual dispatch, packages, pass-by-value semantics, and

pass-by-reference semantics. However, the syntax and calling

conventions are significantly different from other languages. MATLAB

has value classes and reference classes, depending on whether the

class has handle as a super-class (for reference classes) or not (for

value classes).

Method call behavior is different between value and reference classes.

For example, a call to a method

A simple class in MATLAB

classdef hello methods function greet(this) disp('Hello!') end end end

GRAPHICS AND GRAPHICAL USER INTERFACE

PROGRAMMING

MATLAB supports developing applications with graphical user interface

(GUI) features. MATLAB includes GUIDE(GUI development

environment) for graphically designing GUIs. It also has tightly integrated

graph-plotting features. For example, the function plot can be used to

produce a graph from two vectors x and y. The code:

>>x = 0:pi/100:2*pi;

>>y = sin(x);

>>plot(x,y)

Page 29: Training report on Embedded Systems and MATLAB

produces the following figure of the sine function:

Page 30: Training report on Embedded Systems and MATLAB

IMAGE PROCESSING IN MATLAB Image Processing Toolbox provides a comprehensive set of reference-

standard algorithms, functions, and apps for image processing, analysis,

visualization, and algorithm development. You can perform image

analysis, image segmentation, image enhancement, noise reduction,

geometric transformations, and image registration. Many toolbox

functions support multicore processors, GPUs, and C-code generation.

Image Processing Toolbox supports a diverse set of image types,

including high dynamic range, gigapixel resolution, embedded ICC

profile, and tomographic. Visualization functions and apps let you explore

images and videos, examine a region of pixels, adjust color and contrast,

create contours or histograms, and manipulate regions of interest (ROIs).

The toolbox supports workflows for processing, displaying, and

navigating large images.

Capabilities

Exploration and Discovery

Image Enhancement

Image Analysis

Image Segmentation

Image Registration and Geometric Transformations

Large Image Processing and Performance Acceleration

Image representation

There are five types of images in MATLAB.

1. Grayscale. A grayscale image M pixels tall and N pixels wide is represented as a matrix of double datatype of size M×N. Element values (e.g., MyImage(m,n)) denote the pixel grayscale intensities in [0,1] with 0=black and 1=white.

2. Truecolor RGB. A truecolor red-green-blue (RGB) image is represented as a three-dimensional M×N×3 double matrix. Each pixel has red, green, blue components along the third dimension with values in [0,1], for example, the color components of pixel

Page 31: Training report on Embedded Systems and MATLAB

(m,n) are MyImage(m,n,1) = red, MyImage(m,n,2) = green, MyImage(m,n,3) = blue.

3. Indexed. Indexed (paletted) images are represented with an index matrix of size M×N and a colormap matrix of size K×3. The colormap holds all colors used in the image and the index matrix represents the pixels by referring to colors in the colormap. For example, if the 22nd color is magenta MyColormap(22,:) = [1,0,1], then MyImage(m,n) = 22 is a magenta-colored pixel.

4. Binary. A binary image is represented by an M×N logical matrix where pixel values are 1 (true) or 0 (false).

5. uint8. This type uses less memory and some operations compute faster than with double types. For simplicity, this tutorial does not discuss uint8 further.

Grayscale is usually the preferred format for image processing. In cases requiring color, an RGB color image can be decomposed and handled as three separate grayscale images. Indexed images must be converted to grayscale or RGB for most operations.

Reading and writing image files

MATLAB can read and write images with the imread and imwrite commands. When reading images, an unfortunate problem is that imread returns the image data in uint8 datatype, which must be converted to double and rescaled before use.

[Img,Map,Alpha] = imread(Filename); imwrite(MyImage,'myimage.png');

Basic operations Below are some basic operations on a grayscale image u:

% Statistics uMax = max(u(:)); % Compute the maximum value uMin = min(u(:)); % Minimum uPower = sum(u(:).^2); % Power uAvg = mean(u(:)); % Average uVar = var(u(:)); % Variance uMed = median(u(:)); % Median

Page 32: Training report on Embedded Systems and MATLAB

hist(u(:),linspace(0,1,256)); % Plot histogram % Basic manipulations uClip = min(max(u,0),1); % Clip elements to [0,1] uPad = u([1,1:end,end],[1,1:end,end]); % Pad image with one-pixel margin uPad = padarray(u,[k,k],'replicate'); % Pad image with k-pixel margin uCrop = u(RowStart:RowEnd,ColStart:ColEnd); % Crop image uFlip = flipud(u); % Flip in the up/down direction uFlip = fliplr(u); % Flip left/right uResize = imresize(u,ScaleFactor); % Interpolate image uRot = rot90(u,k); % Rotate by k*90 degrees with integer k uRot = imrotate(u,Angle); % Rotate by Angle degrees uc = (u - min(u(:))/(max(u(:)) - min(u(:))); % Stretch contrast to [0,1] uq = round(u*(K-1))/(K-1); % Quantize to K graylevels {0,1/K,2/K,...,1} % Simulating noise uNoisy = u + randn(size(u))*sigma; % Add white Gaussian noise of standard deviation sigma uNoisy = u; uNoisy(rand(size(u)) < p) = round(rand(size(u))); % Salt and pepper noise

Page 33: Training report on Embedded Systems and MATLAB

FILTERS:

1. Linear Filter

A linear filter is an operation where at every pixel xm,n of an image, a

linear function is evaluated on the pixel and its neighbors to compute

a new pixel value ym,n.

A linear filter in two dimensions has the general form

𝑦𝑚,𝑛 =∑∑ℎ𝑗,𝑘𝑥𝑚−𝑗,𝑛−𝑘𝑘𝑗

where x is the input, y is the output, and h is the filter impulse

response. Different choices of h lead to filters that smooth, sharpen,

and detect edges, to name a few applications. The right-hand side of

the above equation is denoted concisely as h∗x and is called the

“convolution of h and x.”

Spatial-domain filtering

Fourier-domain filtering

2. Non-linear Filter

A nonlinear filter is an operation where each filtered pixel ym,n is a

nonlinear function of xm,n and its neighbors.

Order statistic filters

Morphological filters

Page 34: Training report on Embedded Systems and MATLAB

Conclusion An embedded system is a special purpose system that is used to

perform one or few dedicated functions. Simply, we can call any

computer system embedded inside an electronic device an embedded

system. Embedded systems are made to perform few tasks only, after

implementation you can’t use them for another purposes.

Embedded systems are implemented using microcontrollers (and

microprocessors).Microcontroller is a full computer system on a chip,

even if its resources are far more limited than of a desktop personal

computer. It is designed for standalone operations. A microcontroller has

a processor and many peripherals integrated with it on the same chip,

like a flash memory, RAM, I/O ports, serial communication ports, ADC

…Etc.

Atmega16 microcontroller is a 40-pin IC and belongs to the MegaAVR

category of AVR family. It has various features which are suitable for the

implementation of an embedded system. Various peripherals can be

interfaced with ATmega16 microcontroller.

MATLAB (“MATrix LABoratory”) is a tool for numerical computation

and visualization. The basic data element is a matrix, so if you need a

program that manipulates array-based data it is generally fast to write

and run in MATLAB.

Image Processing is processing of images using mathematical operations

by using any form of signal processing for which the input is an image, a

series of images, or a video, such as a photograph or video frame; the

output of image processing may be either an image or a set of

characteristics or parameters related to the image. In MATLAB , there is a

toolbox for performing image processing

Page 35: Training report on Embedded Systems and MATLAB

References & Bibliography

Barrett, Steven F., and Daniel J. Pack. Atmel AVR Microcontroller

Primer: Programming and Interfacing. San Rafael, CA: Morgan &

Claypool, 2008. Print.

MATLAB. "Image Processing Toolbox." Image Processing Toolbox -

MATLAB - MathWorks India. N.p., n.d. Web. 20 Sep. 2016.

{https://in.mathworks.com/products/image/}

Getreuer, Pascal. "Image Processing with MATLAB - Pascal

Getreuer." Pascal Getreuer. N.p., n.d. Web. 20 Sep. 2016.

{ http://www.getreuer.info/tutorials/matlabimaging}

Atmel. "ATmega16." ATmega16. N.p., n.d. Web. 20 Sept. 2016.

{http://www.atmel.com/devices/ATMEGA16.aspx}

"Embedded System." Wikipedia. Wikimedia Foundation, n.d.

Web. 20 Sept. 2016.

{https://en.wikipedia.org/wiki/Embedded_system}

Atmel. "ATmega16." ATmega16. N.p., n.d. Web. 20 Sept. 2016.

{https://en.wikipedia.org/wiki/Microcontroller}

"A Brief Introduction to Matlab." A Brief Introduction to Matlab. N.p.,

n.d. Web. 20 Nov. 2016.

{http://www.egr.msu.edu/~aviyente/Matlab_intro.htm}