Diskret Furye transformatsiyasini (DFT) o'rganing
Raqamli signalni qayta ishlash (DSP) - signal ma'lumotlarini manipulyatsiya qilish uchun
ishlatiladigan matematik usullarni hisoblash [1] . Raqamli signallarni qayta ishlashning eng
muhim vositalaridan biri bu Diskret Furye Transformatsiyasi (DFT). Odatda signalning
chastota-domen (spektral) tasvirini ishlab chiqarish uchun ishlatiladi [2] .
Ushbu postda biz DFT qanday ishlashini va signallar spektrini chiqarish uchun uni qanday
amalga oshirishni muhokama qilamiz.
Diskret Furye transformatsiyasi (DFT)
Furye transformatsiyasi DFT ning matematik asosi va spektral parchalanishning asosiy
g'oyasi bo'lib, signal turli chastotali komponentlarning sinusoidlari yig'indisidan boshqa
narsa emas degan xulosaga keladi [3] . Biz ishlayotgan barcha signal ma'lumotlari raqamli
shaklda bo'lganligi sababli, signal vaqt domenidagi namunalar to'plamidir. Bunday diskret
signallarda Furye transformatsiyasi DFT yordamida amalga oshirilishi mumkin, bu vaqt va
chastota domenlari o'rtasida oldinga va orqaga o'tish uchun ishlatilishi mumkin. Vaqt sohasi
signal namunalarini o'z ichiga oladi, chastota maydoni esa signalni tuzadigan sinusoidlar
spektrini ifodalaydi [4] . Quyidagi rasmda DFT va IDFT yordamida vaqt va chastota
domenlari o'rtasidagi munosabat tasvirlangan.
Vaqt va chastota sohalari o'rtasidagi bog'liqlik [4] . [Muallifning rasmi]
Matematik jihatdan aytadigan bo'lsak, agar bizda N namunali signal (xn) bo'lsa, bu
signalning DFT si quyidagicha aniqlanadi: [5] :
DFT tenglamasi [5]
Qayerda:
N : namunalar soni n : joriy namuna k : k
∈ [0, N -1]bo'lgan oqim chastotasi xn : n
namunadagi sinus qiymati
Xk : amplituda va faza haqida ma'lumotni o'z ichiga olgan DFT
DFT (Xk) ning chiqishi - kirish signalini tuzadigan sinusoidlarning chastotalari,
amplitudalari va fazalari haqidagi ma'lumotlarni o'z ichiga olgan murakkab raqamlar
majmuasi. DFT massivining birinchi yarmi (Xk) musbat chastota atamalarini o'z ichiga
oladi, ikkinchi yarmi esa salbiy chastota atamalarini o'z ichiga oladi. Bundan tashqari, kirish
signali faqat haqiqiy qiymatli signal bo'lsa, birinchi yarmi chastota atamalarining ikkinchi
yarmining konjugati va spektr nosimmetrikdir. Shunday qilib, biz haqiqiy qiymatli signallar
holatida faqat birinchi yarmiga (musbat chastota shartlari) e'tibor qaratamiz [5] . Quyidagi
rasm, agar kirish namunalari soni (N) toq yoki juft bo'lsa, har bir ijobiy va salbiy chastota
atamalarini ifodalaydi.
# Generate the three signals using Signal class and its method sine()
signal_1hz = Signal(amplitude=
3
, frequency=
1
, sampling_rate=
200
, duration=
2
)
sine_1hz = signal_1hz.sine()
signal_20hz = Signal(amplitude=
1
, frequency=
20
, sampling_rate=
200
,
duration=
2
) sine_20hz = signal_20hz.sine()
signal_10hz = Signal(amplitude=
0.5
, frequency=
10
, sampling_rate=
200
,
duration=
2
sine_10hz = signal_10hz.sine()
# Sum the three signals to output the signal we want to analyze
signal = sine_1hz + sine_20hz + sine_10hz
# Plot the signal
plt.plot(signal_1hz.time_axis, signal,
'b'
) plt.xlabel(
'Time [sec]'
)
plt.ylabel(
'Amplitude'
) plt.title(
'Sum of
three signals'
) plt.show()
def
IDFT(
dft
):
# Number of frequencies, 200 components in our example
N =
len
(dft)
# The frequencies from 0 to N-1, [0, 1, 2, ..., 199] in our
example
k = np.arange(N)
# Generate the samples, [[0], [1], [2], ..., [199]] in our
example
n = k.reshape((N,
1
))
# If your input was a first half spectrum, 2j should be 1j to retrieve the
si
e = np.exp(
2j
* np.pi * k * n / N)
# dft is a matrix of complex numbers with a shape of (N,), (200,) in our
exam
signal = np.dot(e,dft)/N
return
signal
# Apply the Inverse Fourier Transform on the spectrum [dft]
sig = IDFT(dft)
# Generate the time axis from sampling rate and length of
dft
N =
len
(dft)
duration = N/signal_1hz.sampling_rate
time_axis = np.arange(
0
,
2
,
1
/
200
)
# Plot the results of IDFT along with the original
signal
plt.plot(time_axis, sig,
'b'
)
plt.plot(time_axis, signal,
'r'
) plt.xlabel(
'Time
[sec]'
) plt.ylabel(
'Amplitude'
) plt.title(
'Output of
the IDFT'
) plt.show()
# Import the scipy package
from
scipy.fftpack
import
fft
# Estimate the execution time of DFT using the function we've
built
print
(
'Execution time of DFT Function:'
)
%timeit DFT(signal)
# Estimate the execution time of DFT using FFT from numpy package
print
(
'\nExecution time of FFT using Numpy pacakge:'
)
%timeit np.fft.fft(signal)
# Estimate the execution time of DFT using FFT from scipy package
print
(
'\nExecution time of FFT using Scipy package:'
)
%timeit scipy.fftpack.fft(signal)
Execution time of DFT Function:
17.3 ms ± 2.65 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)
Execution time of FFT using Numpy pacakge:
8.72 µs ± 2.2 µs per loop (mean ± std. dev. of 7 runs, 100000 loops each)
Execution time of FFT using Scipy package:
8.27 µs ± 137 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
|