signals instruments and signals, instruments, and systems€¦ · • good traininggy for your...

72
Signals Instruments and Signals, Instruments, and Systems School of Architecture, Civil and Environmental Engineering Environmental Engineering EPFL, SS 2012-2013 EPFL, SS 2012 2013 http://disal.epfl.ch/teaching/signals_instruments_systems/ 1

Upload: others

Post on 26-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Signals Instruments and Signals, Instruments, and Systemsy

School of Architecture, Civil and Environmental EngineeringEnvironmental Engineering

EPFL, SS 2012-2013EPFL, SS 2012 2013

http://disal.epfl.ch/teaching/signals_instruments_systems/

1

Page 2: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Signals, Instruments, and Systems – W1Part I: Course Organization,

Team and ContentTeam, and Content

2

Page 3: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Team beyond this courseDi ib d I lli S d Al i h L b

http://disal.epfl.chDistributed Intelligent Systems and Algorithms Laboratory:

l h i i li• Instructor: Alcherio Martinoli• Guest lecturers: Alexander Bahr, William C. Evans, Sven Gowal, Steven

Roelofsen, Milos Vasic • Teaching assistants:• Teaching assistants:

– Alexander Bahr (head TA, postdoctoral fellow)– Steven Roelofsen (TA, PhD student)– Milos Vasic (TA PhD student)Milos Vasic (TA, PhD student)– Fabian Baerenbold (help TA, master student)– Adrien Gaudard (help TA, master student)

• Support staff:pp– Ezequiel Di Mario (PhD student)– Bahar Haghighat (PhD student)– Inaki Navarro Oiza (postdoctoral fellow)– Jorge Soares (PhD student)– Zeynab Talebpour (PhD student)

3

Page 4: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Course Rationale Content Course Rationale, Content, and Prerequisites

4

Page 5: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Typical Field Instrumentation f E i t l M it ifor Environmental Monitoring

Ultrasound anemometer Laser based disdrometerUltrasound anemometer Laser-based disdrometer

Integrated compact weather station (temperature, humidity, anemometer disdrometer) Data logger 5

Page 6: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Local Climate MonitoringFeatures:- Very low sampling frequency < 1Hz- Very low power consumption: 25mW- Solar panel- Radio communicationRadio communication

Sensors:Air Temperature and Humidity- Air Temperature and Humidity

- Infrared Surface Temperature- Anemometer- Solar Radiation- Pluviometer- Soil moistureSo o s u e- Soil pressure

Visit http://sensorscope.epfl.ch for further details! 6

Page 7: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Permafrost MonitoringPermafrost Monitoring

• What is measured:– rock temperaturerock temperature– rock resistivity– crack widthcrack width– earth pressure

water pressure– water pressure

Pictures: courtesy of Permasense7

Page 8: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Seismic Event Monitoring• 38 strong-motion seismometers in 17-story steel-frame Factor Building.38 strong motion seismometers in 17 story steel frame Factor Building.• 100 free-field seismometers in UCLA campus ground at 100-m spacing

1 km Source: D. Estrin, UCLA 8

Page 9: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Ecosystem MonitoringScience• Understand response of wild populations (plants and animals) to habitats

tiover time.• Develop in situ observation of species and ecosystem dynamics.

TechniquesTechniques• Data acquisition of physical and chemical properties, at various

spatial and temporal scales, appropriate to the ecosystem, species and habitat.b .

• Automatic identification of organisms(current techniques involve close-range human observation).

• Measurements over long period of time,taken in-situ.

• Harsh environments with extremes in i b itemperature, moisture, obstructions, ...

Source: D. Estrin, UCLA 9

Page 10: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Embedded Systems at the Heart ofEmbedded Systems at the Heart of Modern Environmental Engineering

• Moving the lab to the field is “in”!• Most of the applications require large spatialMost of the applications require large spatial

distributions (scale of the domain >> scale of a node) → sensor networks)

• Some applications require controlled mobility → field robots

• The underlying hardware/software technology (at the single device level) share the same ( g )principles

10

Page 11: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Rationale (1)Rationale (1)• This course must allow you to become an power user of

the key instruments in environmental/civil engineeringthe key instruments in environmental/civil engineering used nowadays (sensor networks, meteorological stations, data loggers, etc.) and in the futuregg )(exploratory and cleaning robots, robotics sensor networks, etc.)B i t l b i d d• Being a power user means not only being an advanced user but also understand enough to collaborate with EE/CS/ME engineers to design the instruments of the g gfuture in environmental/civil engineering; idea: complexity shifted more and more from hardware to software a lot of domain knowledge can besoftware → a lot of domain knowledge can be transferred to the instruments at software level

11

Page 12: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Rationale (2)• Well-balanced course: theory, algorithms, tools and

practical exercisespractical exercises• It should prepare you to better follow a number of

master courses (especially in the new Environmentalmaster courses (especially in the new Environmental Monitoring and Modeling specialization)

• This course can be considered as an elevator to theThis course can be considered as an elevator to the master course “Distributed Intelligent Systems” for SIE/SGC students where various other sections and programs attend (past semester SIE, SGC, SIN, SSC, SEL, SMT, SGM, CSE, EMS, EDOC, 57 students)

• It should get you prepared for carrying out a design/semester/master project at DISAL 12

Page 13: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

What this course is about• Fundamentals of signal processing:

– Analog/Digital signals, Time/Frequency domains, Filters, Converters

• Fundamentals of embedded systems:– Microprocessors, microcontrollers, memory– Sensors and actuators

B i t l t h i d t– Basic control techniques and concepts– Basic notions of communication systems

• Fundamentals of computer science (from an embedded• Fundamentals of computer science (from an embedded systems perspective):– Basics of computer architecture– UNIX (crash course)– C programming (vs Java, Matlab/Octave) 13

Page 14: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Course PrerequisitesCourse Prerequisites• Matlab/Octave knowledgeg• Fundamentals on structured programming

(you learned Java, you will also learn C)(you learned Java, you will also learn C)• Fundamentals on probability calculus

F d t l l i (A l i I t IV• Fundamentals on analysis (Analysis I to IV, ODE, Fourier series and analysis, transforms)

• The Introduction to Control of Dynamical System course (Mullhaupt) will help although for now not fully leveraged

14

Page 15: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Organization of the Organization of the CourseCourse

15

Page 16: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Credits and Workload

• 5 ECTS• 1 ECTS = 30 h workload → 150 h workload total• Rough breakdown

– 60 h lecture (including reading, exam preparation)– 45 h hwk+lab (including preparation + reporting)– 45 h course project (including implementation, reporting,

reviewing and defense)

16

Page 17: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Grade• Final written exam, summer; 180 minutes• 60% performance during semester, 40%60% performance during semester, 40%

performance during the exam (compromise US/Europe style)

• During semester: mean performance of 9 hwk assignments (bundled into 3 series) (30%) and course project (30%)(30%) and course project (30%)

• During exam: all covered material is subject to examination, but the exam is open bookto examination, but the exam is open book (no electronic equipment allowed other than a basic, non programmable pocket

l l t )calculator)17

Page 18: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Lecture Notes & ReadingLecture Notes & Reading• Policy: no manuscript, but slides and your own notes• Preliminary lecture slides in pdf format available for

download on the course web site possibly before each lecture (wed evening), definitive ones after lecture (couple of days max)R di ill b dd d M dl h• Reading will be added on Moodle as the course progressesA t M dl i i i l h ld b ll t• Access to Moodle: in principle you should be all set because compulsory course and therefore automatic enrollment; if issues contact sis-ta@groupes epfl chenrollment; if issues contact [email protected]

18

Page 19: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Tools used in Exercises and Course Projects

• C programming environment• MatlabMatlab• Realistic simulator (Webots)• Real devices (desktop robots: e puck; desktop• Real devices (desktop robots: e-puck; desktop

sensor nodes: Mica-Z)OS UNIX (Li ) Ti OS• OS: UNIX (Linux), TinyOS

19

Page 20: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

MICAzMICAz• Microprocessor

8 bi i 8MH– 8 bit microprocessor, ~8MHz– 128kB program memory, 4kB SRAM– 512kB external flash (data logger)( gg )

• Transceiver– 802.15.4 (Zigbee)

• TinyOS• Sensor board

Light– Light – Temp– Microphone Acoustic – Buzzer (4 kHz Resonator)

20

Page 21: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

e-puck RobotComputation and memory

Actuators

and memoryCommunicationActuatorsSensors I/O

21

Page 22: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Realistic Simulation

• Discrete sensor and actuators• Noise and nonlinear characteristics faithfully reproduced• Single and multi-robot simulator• Different levels of simulation (different accuracy/faithfulness trade-Different levels of simulation (different accuracy/faithfulness trade-

offs)22

Page 23: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Labs (1)Labs (1) • Lab session 17:15-19:00 on Mon, GR B0 01 weekly

(first lab session: next week)(first lab session: next week)• Mini-tutorial (5-10 min) by the main lab designer at the

beginning of the labbeginning of the lab• 2h lab + 0.5 h preparation

9 l b t t t l ( 22 5 h t t l)• 9 lab sets total (= 22.5 h total)• Official solution available on Moodle after the lab

isession• Office hours (biweekly + exceptions see syllabus): wed

8:15 10 am in the computer room8:15-10 am in the computer room• [email protected] for ANY issue! 23

Page 24: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Labs (2)• Lab assignment posted on Friday of the previous week• Lab presence not compulsory but• Lab presence not compulsory but

– We do not repeat labs– If you do not come to labs you will have a hard time inIf you do not come to labs you will have a hard time in

solving the hwk and being efficient in the course project– Certain labs involve HW which we do not distribute outside

the lab sessions

• I think it is a lot of fun and really helps you d d l ffunderstand lecture stuff

• Assistants are well prepared and numerous• Dedicated feedback forms for each lab on Moodle

24

Page 25: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Hwk (1) • Each lab is followed by an hwk but bundled submission

every 3 weeks• Effort 2.5 h per hwk assignment 22.5h total roughly• Good training for your written examg y• Deadline: 12h00 on Monday after the last lab of the three-

week series, no late submission accepted unless motivated by provable health problems

• Penalty clock start from 14h00 of the due date• Specific projectable issues in submitting a write-up should

be mentioned in advance to the TAs• Network/Moodle server problems → TAs immediately

notified 25

Page 26: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Hwk (2)Hwk (2) • Hwk individually reviewed, distributed in a

timely fashion (target 2 weeks after submission, commented pdf)

• No official solution of hwk distributed; TAs available during office hours for discussion g(wed morning 8h15-10h00 or, even better, upon appointment via e-mail to TA list)pp )

26

Page 27: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Suggestions for a Successful E i S iExercise Series

From our teaching experience:• Read the assignment in advance (i.e. before the lab,

you have always a “free” evening), in this way you ill b ffi i t h th TA d fwill be more efficient when the TAs are around for

helping you on the toughest questions… B f t t h k h id f th i t• Before you start your hwk, have an idea of the point distribution: this roughly correspond to the breakdown in time you should have; if your time is tight investin time you should have; if your time is tight invest where it is worth!

• You do not have to achieve always 100/100: bonuses,You do not have to achieve always 100/100: bonuses, exam are also great opportunities to round up…

27

Page 28: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Course Project (1)• Course project list distributed and assigned after Easter

break• 45 h effort, defenses on the first week after sem end –

date? We need about 6 h on the same day• Team of 2 students (ad hoc solution for total odd number

in class)• Will distribute HW/SW at home• Short progress report (compulsory but not graded, 1

page) and debriefing with responsible TA/staff member• Final report to be submitted (pre-established max # of

pages and format)28

Page 29: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Course Project (2)

• Final presentation in front of the class (10 p (minutes + 5 min questions)

• Each of the project will have another team ofEach of the project will have another team of students as reviewers

• Each of the team members has to present• Each of the team members has to present

29

Page 30: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Suggestions for a Successful Course ProjectSuccessful Course Project

From our teaching experience:g p• Contact ASAP the responsible supervisor when

the projects will have been assigned for getting p j g g gstarted

• Plan your effort (milestone, time, etc.), y ( , , ),coordinate your team

• Arrive at the intermediate report milestone with pa clear plan, reading, tool handling, project understanding and possible some preliminary implementation behind you

30

Page 31: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Collaboration Policy

• Lecture and exam preparation: encouraged• Course project: mandatory (student team)p j y ( )• Lab: discussion encouraged • Hwk: discussion encouraged but problemHwk: discussion encouraged but problem

solved and submitted individually! We will be very strict in penalizing too similar y p gwrite-ups copies because 30% of the grade is acquired with hwk (n copies = # of points/n)!

31

Page 32: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Fi l N tFinal Notes

32

Page 33: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

5th Iteration at ENAC• Fourth iteration as compulsory course

A i lti l l t t f th t d t i t d l t thi• Again multiple lecturers: most of the students appreciated a lot this aspect last year (anyway impossible to teach the whole)

• More weight on the course project (and a bit less on the exam); o e we g t o t e cou se p oject (a d a b t ess o t e e a );complexity of the course project is the same but recognition of the gap in programming required for it in comparison to exercises.

• More C programming spread out after the introductory part as much as appropriate for reducing the gap above

• Hwk following up directly the lab but submission every 3 weeks as• Hwk following up directly the lab but submission every 3 weeks as last year

• No major course restructuring until the batch of SIE students with reinforced programming background will arrive (SS 2013-2014)

33

Page 34: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Signals, Instruments, and Systems – W1Signals, Instruments, and Systems W1Part II: Linux & C

34

Page 35: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Linux

35

Page 36: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

LinuxLinux is a free Unix based operating systemLinux is a free Unix-based operating system.

• DefinitionAn operating system is commonly abbreviated to either OS or O/S) is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer.

• Other OSs:Windows, Mac OS X, Android, etc…

Source: http://en.wikipedia.org/wiki/Operating_system 36

Page 37: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Linux

• Properties– Portable to most computer architectures– Multi-tasking– Multi-user

Time sharing (programs can share CPU)– Time sharing (programs can share CPU)– Plain text to store configurations (vs. ‘Registry’ of Windows)– Hierarchical file system– Command line interpreter

37

Page 38: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Ubuntu• Ubuntu is a particular flavor of Linux• Others: SUSE, RedHat, Fedora, etc…• Ubuntu’s graphical interface:

38

Page 39: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

The TerminalA t i l ( ‘ h ll t i l’) ll t i• A terminal (or ‘shell terminal’) allows you to give command-line orders

• Applications > Accessories > Terminal• Applications > Accessories > Terminal

39

Page 40: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Shell• The command shell is the interface which• The command shell is the interface which

interprets your commands• At the prompt commands can be entered• At the prompt, commands can be entered.

chris@disallap14:~$

• Commands represent programs.• Programs are located in the file system in foldersPrograms are located in the file system in folders.

40

Page 41: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Directory Structure and NavigationLinux organizes its directories differently to WindowsLinux organizes its directories differently to Windows

Absolute paths:

/ Root directory. Everything is mounted on top of this directory.

/bin Bin is short for ‘binaries’. This directory contains yprograms (executables).

/home/user Your ‘home’ directory. This is where you can store your data

Relative paths:

. Here (current directory).( y)

.. Parent directory.

41

Page 42: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Absolute vs. relative path• Absolute

– Starts with the root location: /– Examples: /bin/ps/h / / d/home/user/mydocs

• Relative– Starts with: . or ..– Examples:

/h ll ld./hello_world../../bin/ps 42

Page 43: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Environment Variables

• Definition: each process has its set of environment variables. By default, when a process is created it inherits a duplicate environment of its parent process

• Environment variables good to know:$PATH contains paths of executable files$ ’ h di$HOME user’s home directory

• To get the value of a variable, use:h $VARIABLE NAMEecho $VARIABLE_NAME

43

Page 44: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

$ L bl fil$PATH: Locate executable files

• When I type ps, I actually execute the program:/bin/ps

• /bin is part of the PATH

• Any program that is not located in the path must be executed by specifying its location:y p y g

44

Page 45: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Standard commands 1l li t th t t f th t di t• ls: lists the content of the current directoryls can take several arguments:

• ls mydocs (lists the content of mydocs)• ls -a (lists the content of the current directory

incl ding hidden files)including hidden files)• ls -l (lists the content of the current directory

including rights, owner, size and date properties)g g , , p p )• ls –la mydocs

45

Page 46: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Standard commands 2d changes the c rrent director• cd: changes the current directory

• Ex: change to directory mydocscd mydocscd mydocs

• pwd: prints the current working directory

Remark 1: The command prompt shows the current directoryRemark 2: ~ stands for /home/[username]Remark 2: ~ stands for /home/[username]

46

Page 47: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Standard commands 3: deletes the specified file (remo es)• rm: deletes the specified file (removes)

• Ex: remove file text.txtrm text txtrm text.txt

• rm –r: deletes files recursively inside directory. Ex:rm –r mydocs

• rm –f: forces the deletion of the specified file

Y h di trm –rf ~/* Your home directoryEverything inside it

f l d fil i h i diffi l hCareful: rm doesn’t move files into “trash”– it’s difficult to recover them!

47

Page 48: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Standard commands 4

• mv: moves/renames the specified file/folder– Ex: move text.txt into mydocsmv text.txt mydocs

– Ex: rename text.txt to file.txtmv text txt file txtmv text.txt file.txt

• cp: copies into another file (exactly like mvexcept that a copy is made)except that a copy is made)– Ex: copy text.txt and call the copy text_copy.txtcp text.txt text_copy.txt

48

Page 49: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Standard commands 5

• mkdir: creates a new folder (make dir.). Ex:mkdir myfolder

• man: displays the manual of the specified commandE : e plain command ‘mkdir’– Ex: explain command ‘mkdir’man mkdir

– To quit man, hit qq , q

man is very useful!

49

Page 50: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

man

50

Page 51: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Advanced commands

• ps: displays the current programs (processes) that are running (similar to the “task manager” of Windows)

• kill: stop the program with the specified PID (process ID).

51

Page 52: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Useful things…

• [TAB] auto-completes the command that is currently being typed.

• [TAB][TAB] displays all the remaining possibilities.

[TAB][TAB]

• [TAB][TAB] without having typed anything b f di l ll th th t bbefore displays all the programs that can be run from the path. 52

Page 53: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Redirection• It is possible to redirect the resulting output of a

program execution into a fileE it t t f t ‘l ’ i t fil t t t– Ex: write output of commant ‘ls’ into file out.txtls > out.txt

– Useful to save and analyze the data in Matlab forUseful to save and analyze the data in Matlab for example.

53

Page 54: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Pipes

• It is possible to use the output of a program directly as input to another program.– Ex: get values of all environment variables and find the

value of SHELL within env | grep “SHELL”env | grep SHELL

– This is quivalent to: env > out.txtgrep “SHELL” < out.txt

Remark: grep searches the input for the specified sequence.54

Page 55: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Programming in CProgramming in C

55

Page 56: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Question

• What is your level in programming?– Java?Java?– Matlab?– C?C?

56

Page 57: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

What is C?

• C is a programming language just like Java: It enables the programmer to tell to the p gcomputer what it should do.

• It was developed in 1972 and is still one ofIt was developed in 1972, and is still one of the most widely-used languages in the worldworld

57

Page 58: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

What is C?

58

Page 59: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Main differences with Java

• It is NOT object oriented. (C++ is OO)• Code is directly translated into binary thatCode is directly translated into binary that

can be directly executed by the machine. With C the programmer can directly accessWith C, the programmer can directly access machine resources (memory, processes).

• It’s not ‘safe’ (Java is ‘safe’)• It s not safe (Java is safe )• Full comparison of C vs. Java:

h //i i d /j /f / 2j h lhttp://introcs.cs.princeton.edu/java/faq/c2java.html59

Page 60: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

How to use it?

file?

file.c

source file executable(binary)(binary)

60

Page 61: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

How to use it?• ‘gcc’ is a program, and stands for Gnu C Compiler

gcc file.c –o file

• ‘gcc’ contains all standard libraries needed to compile a basic program

object file

filefile.ofile.c

source file executablelibc

standard C library61

Page 62: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Example: Hello World

class myclass {public static void main(String args[]) {

In Java

public static void main(String args[]) {System.out.println("Hello World!");

}}

#include <stdio h>

In C#include <stdio.h>

int main(int argc, char *args[]){printf(“Hello World!\n”);printf( Hello World!\n );return 0;

}62

Page 63: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Example: Hello World• #include <stdio h>

• int main(int argc, char *args[])

• #include <stdio.h>

• Includes the declaration of printf in our C code.

– That is the entry function of any C code.– This function is called first when the

t t dprogram gets executed. #include <stdio.h>

int main(int argc, char *args[]){printf(“Hello World!\n”);

• printf(“Hello World!\n”);

Thi f ti i i th lib return 0;}

– This function is in the libc.– It is declared in the stdio.h file.

• return 0;

– main always returns an int (integer value).– The convention is to return 0 when everything went ok. 63

Page 64: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Variables• Just like Java there are several types of yp

variables in C:– Integers: char, short, int, longg g

– Floating point: float, double– Characters: char– There is no Boolean type.

• Variables can be either signed or unsigned:• Variables can be either signed or unsigned:– Ex.: unsigned int, signed char

Ad d i f ifi i• Advanced: integers of a specific sizeint8_t, int16_t, int32_t 64

Page 65: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

VariablesV i bl d t b d l d b f th• Variables need to be declared before they are used.

• In correct ANSI C89, variables need to be declared at the beginning of a block (after the opening curly bracket “{”).int main() {

int a = 5;double b = 4.3;return (int)((double)a * b);

}}

Remark: A variable type can be modified with a cast.65

Page 66: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Controlling the execution flow

• Algorithms are all about controlling the execution flow.

• Algorithms are all about deciding how to proceed depending on some conditionalproceed depending on some conditional statements.

What are the tools we use to do this?

66

Page 67: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

ififif (condition) {

code;Def.:

;

} else if (another condition) {another code;

} l {} else {yet another code;

}

if (a >= b && a != c) {a = b;

Ex.:a b;

} else if (a == 3 || b == 3) {a = c;

} l {} else {b = 2*a;

} 67

Page 68: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

whilewhilewhile (condition) {( ) {

code;}

do {code;

} while (condition);

• At any time, you can quit the loop with the keyword b kbreak.

• You can also skip the rest of the code in the loop with continue.continue.

68

Page 69: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

forfor

for (initialization; condition; increment) {code;

}}

for (i = 0; i < i_max; i++) {a = a + i * a;

printf(“a is equal to: %d \n”, a);

}

ti d b k l b d• continue and break can also be used.

69

Page 70: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

C l iConclusion

70

Page 71: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Summary

• Basics in Linux:– How to navigate, how to manipulate filesHow to navigate, how to manipulate files– How to combine commands– Where to look for information (man pages)Where to look for information (man pages)

• Introduction to C:V i bl d i f ti– Variables and main function

– Basic control structures (if, while, for)

71

Page 72: Signals Instruments and Signals, Instruments, and Systems€¦ · • Good traininggy for your written exam • Deadline: 12h00 on Monday after the last lab of the three-week series,

Additional Literature – Week 1

• Nice summary on linux shell usage:http://linuxcommand.org/learning_the_shell.php

• Classical book for C programming:‘C Programming Language’, Prentice HallBrian W. Kernighan , Dennis M. Ritchie

• Popular C link:http://www.c-faq.com/

• And many more – Google is your friend

72