Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet292/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   288   289   290   291   292   293   294   295   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

FFT using NumPy

Because  this  is  a  numerical  problem,  the  fast  Fourier  transform  (or  FFT,  for  short)  is

normally  implemented  in  a  fast  compiled  language  like  Fortran  or  C.

7

 But  fortunately



NumPy provides a Python wrapper around a C implementation of the FFT:

from numpy.fft import fft

freqs = fft(sig)

Also, SciPy provides two implementations of the FFT, one actually being the same as

the NumPy one, and the alternative being:

from scipy.fftpack import fft

freqs = fft(sig)

They both accept either a NumPy array or an ordinary Python list or tuple as input, and

return a NumPy array as output.

As  an  example,  we  can  continue  the  code  from  the  first  section,  which  simulated  a

signal,  sig,  and  calculate  its  Fourier  transform.  We  can  then  save  plots  of  the  real  and

imaginary parts of the Fourier transform, and also the magnitude squared of that, which is

called the power spectrum.

freqs = fft(sig)

freqReal = [f.real for f in freqs]

savePlot(times, freqReal, 'freq', 'FT real')

freqImag = [f.imag for f in freqs]

savePlot(times, freqImag, 'freq', 'FT imag')

powerSpec = [abs(f)**2 for f in freqs]

savePlot(times, powerSpec, 'freq', FT power')

In the example above we have assumed the intensities we require are represented by the

real component of the complex numbers, which is why the frequencies from the imaginary

part  of  the  transform  fluctuate  about  zero.  In  general,  however,  the  real  and  imaginary

parts  of  the  transform  are  affected  by  phasing.  Multiplying  the  signal  by  a  complex

number with magnitude 1 can be thought of as a ‘rotation’ of the real into the imaginary

part  and  vice  versa,  hence  the  term  phase,  which  describes  the  angle  of  rotation.  This

multiplication  has  the  same  effect  on  the  Fourier  transform.  But  the  power  spectrum

remains  unchanged,  because  it  is  the  magnitude  squared,  which  is  one  reason  it  is  often

used  for  analysis.  However,  in  some  areas  of  science,  for  example,  NMR  (nuclear



magnetic resonance), it is important to understand the phasing because it turns out that you

can get sharper (narrower) peaks with the real part of a suitably phased transformed signal,

versus the power spectrum.


Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   288   289   290   291   292   293   294   295   ...   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