Lab 7
Lab 7
Abstract:
Introduction:
Radix 2 (DIT):
At each stage of the algorithm, the input sequence is divided into 2^(k-1) pairs of
numbers, where k is the stage number (starting from 1). Each pair of numbers
corresponds to a butterfly operation. The complex exponential used in the
butterfly operation is determined by the index of the pair and the stage number.
The butterfly operation is performed by multiplying the second number in the pair
by the complex exponential, and adding or subtracting the result to the first
number in the pair, depending on whether the index of the pair is even or odd.
The result is then stored in the first number of the pair. The algorithm continues
until the input sequence is divided into individual numbers, at which point the
DFT has been computed. The final output is a sequence of n complex numbers,
which represent the frequency-domain representation of the input sequence.
The Radix-2 DIT algorithm has a computational complexity of O(n log n), which is
much faster than the brute-force O(n^2) algorithm for computing the DFT
Radix 2 (DIF):
At each stage of the algorithm, the input sequence is divided into 2^(k-1) blocks
of 2^k samples each, where k is the stage number (starting from 1). Each block
corresponds to a butterfly operation, which involves adding and subtracting the
values of the sub-DFTs multiplied by complex exponentials.
The Radix-2 DIF algorithm also has a computational complexity of O(n log n),
which is much faster than the brute-force O(n^2) algorithm for computing the DFT
Procedure:
DIT:
If "N" is 2, compute and return the DFT of "x" directly as [x[0]+x[1], x[0]-x[1]].
Otherwise, split "x" into its even and odd-indexed samples, i.e., xe = x[::2] and xo
= x[1::2].
Compute the DFT of x by combining the results obtained from the previous step
for xe and xo. Specifically, compute the DFT of x[k] by the formula: X[k] = Xe[k] +
W(N)^k * Xo[k], where Xe and Xo are the DFTs of xe and xo, respectively, and
W(N) is the twiddle factor defined as W(N) = e^(-2pij/N).
DIF:
If the length of the input signal is not a power of two, add zeros to the end of the
signal until its length becomes a power of two.
Combine the results of the two sub-transforms using the butterfly structure:
Add the even-indexed and odd-indexed sub-transforms to get the sum and
difference, respectively.
Multiply the difference by the twiddle factor of the current stage, which is given by
exp(-j2pi*k/N), where k is the index of the current element and N is the length of
the signal.
Combine the sum and the modified difference to get the final result for the current
element.
Results:
Discussions:
Conclusion:
References:
Appendice:
import numpy as np
from matplotlib import pyplot as plt
def W(N):
return np.exp(-2j*np.pi/N)
Xe = ganni_radix2dif(X1)
Xo = ganni_radix2dif(X2)
l = []
for i in range(len(Xe)):
l.append(Xe[i])
l.append(Xo[i])
return l
x = [np.cos(20*np.pi*i) for i in t]
x = np.array(x) + np.random.normal(0, 1, len(x))
Y = harry_dft(x)
Y1 = ganni_radix2dit(x, N)
Y2 = ganni_radix2dif(x, N)
Ya = [np.angle(i) for i in Y]
Ym = [abs(i) for i in Y]
Y1a = [np.angle(i) for i in Y1]
Y1m = [abs(i) for i in Y1]
Y2a = [np.angle(i) for i in Y2]
Y2m = [abs(i) for i in Y2]
plt.figure()
plt.subplot(3, 1, 1)
pm = plt.stem(f, Ym)[0].axes
pm.set_ylabel('ang(Y)')
pm.set_title('ang(Y) vs f')
plt.subplot(3, 1, 2)
p1m = plt.stem(f, Y1m)[0].axes
p1m.set_ylabel('ang(Y1)')
p1m.set_title('ang(Y1) vs f')
plt.subplot(3, 1, 3)
p2m = plt.stem(f, Y2m)[0].axes
p2m.set_ylabel('ang(Y2)')
p2m.set_title('ang(Y2) vs f')
plt.figure()
plt.subplot(3, 1, 1)
pa = plt.stem(f, Ya)[0].axes
pa.set_ylabel('|Y|')
pa.set_title('|Y| vs f')
plt.subplot(3, 1, 2)
p1a = plt.stem(f, Y1a)[0].axes
p1a.set_ylabel('|Y1|')
p1a.set_title('|Y1| vs f')
plt.subplot(3, 1, 3)
p2a = plt.stem(f, Y2a)[0].axes
p2a.set_ylabel('|Y2|')
p2a.set_title('|Y2| vs f')
plt.show()