laboratorium 02 py id 261471 Nieznany

background image














SIGNAL PROCESSING

Laboratory #2:

Data visualization, array operations

and defining functions in Python







M. Kociński, P. Strumiłło, K. Kudryński



Medical Electronics Division

Institute of Electronics






background image



Signal Processing, Biomedical Engineering

M. Kociński, P. Strumiłło, K. Kudryński, Institute of Electronics, Lodz University of Technology


PURPOSE:


To get acquainted with basic data visualization techniques and defining functions in Python.

TASKS:


1. In this exercise we will use different NumPy and PyLab methods and functions:

2. In an interactive mode in the PyLab widow type the following series of commands:

dt=0.5
t=arange(0,10,dt)

# time scale

a=9.81

# acceleration

v=a*t

# velocity

s=(a*t**2)/2.

# distance


plot(t,v,’.’)

#plot distance in discrete time instances

title(

'Velocity’

)

xlabel(

't[s]'

)

ylabel(

'v[m/s]'

)


figure(2)
plot (t,s,

'.r'

)

#plot distance in discrete time instances

title(

'Distance'

)

xlabel(

't[s]'

)

ylabel(

's[m]'

)


figure(3),plot (t,s,label=’distance’)

# interpolated distance

legend()
grid()

By selecting

icon displayed at the bottom of the figure windows save (in your defined

directory) the displayed plots in the jpg format files.

background image



Signal Processing, Biomedical Engineering

M. Kociński, P. Strumiłło, K. Kudryński, Institute of Electronics, Lodz University of Technology

3. Enter the subplot commands (consult subplot? or help(subplot) commands)

figure()
subplot(2,1,1), plot (t,v)

# upper plot

subplot(2,1,2), plot (t,s)

# lower plot

4. Create a function motion(a,t) which returns the final velocity v and distance s of a

body moving with acceleration a, after time t. Use Notepad++ to define and type in your
function. Save the defined function under the name my_functions.py where all functions you
write are stored. Now you can import your library of functions by using command:

from my_functions import *

and then run the motion function.

5. Write and test a new function

my_sign(x) that

checks, whether variable x is positive,

negative or zero by printing appropriate texts, i.e. ‘positive’, ‘negative’, ‘zero’.

6. Write and test a new function

my_stat_1d(x) which

returns the minimum, average and

maximum values of vector x.

7. You can also import a single function form my_functions in two possible methods:

a. from my_functions import my_stat_1d
b. from my_functions import my_stat_1d as myst

If you use method a. you invoke the my_stat_1d function e.g. by a command:
my_stat_1d(x)
If you use method b. you invoke the my_stat_1d function e.g. by a command:
myst(x)


□ 2012-10-20


Wyszukiwarka

Podobne podstrony:
laboratorium 01 py id 261468 Nieznany
laboratorium 06 py id 261473 Nieznany
laboratorium 05 py id 261472 Nieznany
bns kalisz 02 06 id 90842 Nieznany (2)
Laboratorium z TM spr1 id 26189 Nieznany
na5 pieszak 03 02 10 1 id 43624 Nieznany
24 02 2011 2 id 30494 Nieznany (2)
lab 02 php id 258739 Nieznany
Laboratorium 2i3 zswier id 2615 Nieznany
ei 2005 01 02 s080 id 154144 Nieznany
gk 02 graphics2d id 191746 Nieznany
N 109 02 WnukLipinski id 311796 Nieznany
Informacja 12 02 2008 id 213373 Nieznany
Laboratorium 7 z TM spr2 id 261 Nieznany
HYDROSFERA 02 odpowiedzi id 207 Nieznany
312[01] 02 122 id 35063 Nieznany
Namar laboratoria 2012 13 id 31 Nieznany
Zestaw 02 InzB id 587902 Nieznany

więcej podobnych podstron