Ejemplo n.º 1
0
def IDFT(X):
    """
    Input:
        X (numpy array) = frequency spectrum (length N)
    Output:
        The function should return a numpy array of length N 
        x (numpy array) = The N point IDFT of the frequency spectrum X
    """
    x = np.array([])

    N = len(X)

    for i in range(N):
        idx = np.arange(0,N)
        # s = 1.0*np.exp(1j*(2.0*math.pi*i*idx/N))
        s = A2Part2.genComplexSine(-i, N)
        x = np.append(x,np.sum(X*s))

    return x/N


# X = np.array([1 ,1 ,1 ,1])
#
# print 'IDFT of X: '
# print IDFT(X)
Ejemplo n.º 2
0
def DFT(x):
    """
    Input:
        x (numpy array) = input sequence of length N
    Output:
        The function should return a numpy array of length N
        X (numpy array) = The N point DFT of the input sequence x
    """
    ## Your code here
    X=np.array([])
    N=np.size(x)
    for k in np.arange(N):
        X=np.append(X,  sum(x * a22.genComplexSine(k, N)))
    return (X)
Ejemplo n.º 3
0
def DFT(x):
    """
    Input:
        x (numpy array) = input sequence of length N
    Output:
        The function should return a numpy array of length N
        X (numpy array) = The N point DFT of the input sequence x
    """
    ## Your code here
    X = np.array([])
    N = np.size(x)
    for k in np.arange(N):
        X = np.append(X, sum(x * a22.genComplexSine(k, N)))
    return (X)
Ejemplo n.º 4
0
def genMagSpec(x):
    """
    Input:
        x (numpy array) = input sequence of length N
    Output:
        The function should return a numpy array
        magX (numpy array) = The magnitude spectrum of the input sequence x
                             (length N)
    """
    ## Your code here
    X=np.array([])
    N=np.size(x)
    for k in np.arange(N):
        X=np.append(X,  abs(sum(x * a22.genComplexSine(k, N))))
    return (X)    
def DFT(x):
	"""
    Input:
        x (numpy array) = input sequence of length N
    Output:
        The function should return a numpy array of length N
        X (numpy array) = The N point DFT of the input sequence x
	"""
	## Your code here
	N = x.size

	X = np.array([])
	
	for k in range(N):
		s = A2Part2.genComplexSine(k, N)
		X = np.append(X, sum(x*s))

	return X
Ejemplo n.º 6
0
def DFT(x):
    """
    Input:
        x (numpy array) = input sequence of length N
    Output:
        The function should return a numpy array of length N
        X (numpy array) = The N point DFT of the input sequence x
    """
    X = np.array([])

    N = len(x)

    for k in range(N):
        s = A2Part2.genComplexSine(k, N)
        X = np.append(X, np.sum(x * s))

    # bOutput = True
    # validationOutput(bOutput, X)

    return X
def IDFT(X):
    """
    Input:
        X (numpy array) = frequency spectrum (length N)
    Output:
        The function should return a numpy array of length N 
        x (numpy array) = The N point IDFT of the frequency spectrum X
	"""
    ## Your code here
    N = X.size

    x = np.array([])
    k = np.arange(N)
    print k

    for n in range(N):
        s = np.conjugate(A2Part2.genComplexSine(n, N))
        #s = np.exp(1j * 2 * np.pi * k * n / N)
        x = np.append(x, 1.0 / N * sum(X * s))

    return x
Ejemplo n.º 8
0
def IDFT(X):
    """
    Input:
        X (numpy array) = frequency spectrum (length N)
    Output:
        The function should return a numpy array of length N 
        x (numpy array) = The N point IDFT of the frequency spectrum X
    """
    ## Your code here
    # DFT = X[k] = 1/N * SUM (x[n] * e ^ 2pi*k*n/N)      k = 0 .. N-1
    
    N = len(X)
    x = np.zeros(N, complex)
    for k in range(0,N):
        # Find cross-correlation between the signal and a set of N complex sinusoids
        # Multiply each point in the signal with a complex sinusoid. Since sinusoids are orthogonal,
        # the result of the multiplication will be non-zero only if the sinusoid is present in the signal
    
        #x[k] = sum(X * genComplexISine(k,N)) / N
        x[k] = sum(X * A2Part2.genComplexSine(-k,N)) / N #IDFT is same as DFT but with -ve frequencies and a factor of 1/N
    return x
Ejemplo n.º 9
0
def IDFT(X):
    """
    Input:
        X (numpy array) = frequency spectrum (length N)
    Output:
        The function should return a numpy array of length N 
        x (numpy array) = The N point IDFT of the frequency spectrum X
    """
    ## Your code here

    N = len(X)

    x = np.empty(0, dtype=complex)

    for n in xrange(N):
        complexSine = np.conjugate(A2.genComplexSine(n, N))
        x = np.append(x, [X[0]])
        for k in xrange(1, N):
            x[n] = x[n] + X[k] * complexSine[k]

    return (x / N)
Ejemplo n.º 10
0
def DFT(x):
    """
    Input:
        x (numpy array) = input sequence of length N
    Output:
        The function should return a numpy array of length N
        X (numpy array) = The N point DFT of the input sequence x
    """
    ## Your code here
    N = len(x)
    
    X = np.empty(0,dtype = complex)
    
    for k in xrange(N):
        complexSine = A2.genComplexSine(k,N)
        X = np.append( X , [x[0] + 0 * 1j]) 
        for n in xrange(1,N):            
            X[k] = X[k] + x[n] * complexSine[n]
    
    return X
 
        
            
Ejemplo n.º 11
0
import A2Part1
import A2Part2
import A2Part3
import A2Part4
import A2Part5
import numpy

print ("Number 1: ", A2Part1.genSine(1.0, 10.0, 1.0, 50.0, 0.1))
print ("Number 2: ", A2Part2.genComplexSine(1,5))
print ("Number 3: ", A2Part3.DFT(numpy.array([1,2,3,4])))
print ("Number 4: ", A2Part4.IDFT(numpy.array([1,1,1,1])))
print ("Number 4a: ", A2Part4.IDFT(A2Part3.DFT(numpy.array([1,2,3,4]))))
print ("Number 4b: ", A2Part4.IDFT(A2Part3.DFT(A2Part4.IDFT(A2Part3.DFT(numpy.array([1,2,3,4]))))))
print ("Number 5: ", A2Part5.genMagSpec(numpy.array([1,2,3,4])))