-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFFT_iFFT.py
More file actions
34 lines (27 loc) · 756 Bytes
/
Copy pathFFT_iFFT.py
File metadata and controls
34 lines (27 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 2 08:03:56 2015
@author: arun
"""
import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import fft, ifft
# This is necessary!
N = 64 # Number of points
T = 1/64.0 # Spacing between points
# if T is time/distance, 1/T is frequency/wavenumber
x = np.linspace(0, 2*np.pi*N*T, N)
# Let's take X as time, so 1/X is frequency!
y1 = np.cos(20*x)
y2 = np.sin(10*x)
y3 = np.sin(5*x)
y = y1 + y2 + y3 # Produces a random signal
fy = fft(y) # Finds the FFT
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
# plt.figure(1)
# plt.plot(xf, (2.0/N)*np.abs(fy[0:N/2]))
# Only half is valid. The other half is replica!
plt.figure(2)
y4 = ifft(fy) # Gets the inverse FFT
plt.plot(x, y4, 'r')
plt.plot(x, y, 'b')