Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet288/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   284   285   286   287   288   289   290   291   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Displaying a signal

It is easy enough to write a sample test script to run the code, but rather than just look at

lists of numbers it is more useful to draw plots of the signals and Fourier transforms. We

will use the pyplot module from the matplotlib library (available with SciPy) to do this. As

illustrated in earlier chapters, it can show a graphical plot on the screen as well as save it

to a file, although below we will just do the latter. We combine the graph-generating code

into one function for convenience:

from matplotlib import pyplot

def savePlot(x, y, xlabel, ylabel):

pyplot.plot(x, y, color='k') # k means BlacK

pyplot.xlabel(xlabel)

pyplot.ylabel(ylabel)

fileName = ylabel.replace(' ', '')

pyplot.savefig(fileName)

pyplot.close()

The pyplot xlabel() function sets the label for the x axis, and similarly for ylabel(). The

savefig()  function  saves  the  figure  to  a  file  with  the  specified  name  (well,  a  suffix  is

appended, e.g. ‘.png’).

In this simple example we assume that there are two pure frequency components of the

signal,  the  first  with  amplitude  1.0,  frequency  0.1  and  decay  0.01,  and  the  second  with

amplitude  2.5,  frequency  0.7  and  decay  0.05.  A  signal  is  created  with  100  points  and

appropriate time step and noise values.

sigParams = ((1.0, 0.1, 0.01), # Amplitude, frequency, decay

(2.5, 0.7, 0.05))

nPoints = 100

tStep = 1.0

noise = 0.5

sig = createSignal(sigParams, tStep, nPoints, noise)

The above plotting function can then be used to draw a graph using the time value for

each point on the x axis and the signal intensity on the y axis:

times = [i*tStep for i in range(npoints)]

savePlot(times, sig, 'time', 'signal')

In the signal plot (see

Figure 19.1

) we can see the two pure frequency signals (ω = 0.1

and ω = 0.7) fairly clearly. However, if we have lots of pure frequency signals it becomes

much  harder  to  see  what  is  going  on,  which  is  why  in  many  cases  we  would  go  on  to

investigate the Fourier transform.





Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   284   285   286   287   288   289   290   291   ...   514




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish