티스토리 뷰
Numpy FFT Example
@2018.12.11
Summary
python
numpy
signal
fft
티스토리
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
#Sin Signal Class
class SinSample():
def __init__(self, **kwargs):
self.amp = kwargs.get('amp',1)
self.time = kwargs.get('time',t)
self.freq = kwargs.get('freq',3)
self.sample = np.sin(2*np.pi*self.freq*self.time)
def calSignal(self, freq):
return np.sin(2*np.pi*freq*self.time)
def addSample(self, freq):
self.sample = self.sample + (self.calSignal(freq))
#Init
Fs = 1000#1KHz
Ts = 1/Fs
t = np.arange(0.0, 1.0, Ts)
#Make Signal
Mysample = SinSample(amp=1, time=t, freq=3)
Mysample.addSample(50)
Mysample.addSample(100)
#Plot Signal
plt.figure(figsize=(12,5))
plt.plot(t, Mysample.sample)
plt.xlabel('Time(s)')
plt.title('Test Signal in Continuous')
plt.grid(True)
plt.show()
Y = np.fft.fft(Mysample.sample)
freq = np.fft.fftfreq(len(Y), d=Ts)
plt.figure(figsize=(12,5))
plt.plot(freq, np.abs(Y), 'r')
plt.xlabel('Freq (Hz)')
plt.ylabel('|Y(freq)|')
plt.grid(True)
###Delete 3hz signal don't use ifft ==> Error###
#check fft.freq function index -> not continuous
###############################################
Y = np.fft.fft(Mysample.sample)
freq = np.fft.fftfreq(len(Y), d=Ts)
#target hz
fg = 3
for i in range(0, len(Y)):
Y[i] *= (1 if abs(freq[i]) > fg else 0)
filterd_Y = np.fft.ifft(no_shift_Y)
plt.figure(figsize=(12,5))
plt.plot(freq, filterd_Y)
###Delete 3hz signal use ifft###
Y = np.fft.fft(Mysample.sample)
freq = np.fft.fftfreq(len(Y), d=Ts)
#shift x index (freq)
freq = np.fft.fftshift(freq)
#target hz
fg = 3
for i in range(0, len(Y)):
Y[i] *= (1 if abs(freq[i]) > fg else 0)
filterd_Y = np.fft.ifft(no_shift_Y)
plt.figure(figsize=(12,5))
plt.plot(freq, filterd_Y)
###Get FTT & Plot###
Y = np.fft.fft(filterd_Y)
freq = np.fft.fftfreq(len(f_Y), d=Ts)
plt.figure(figsize=(12,5))
plt.plot(freq, np.abs(f_Y), 'r')
plt.xlabel('Freq (Hz)')
plt.ylabel('|Y(freq)|')
plt.grid(True)
코드
https://github.com/LazyerIJ/ECG_Analysis/blob/master/study/Numpy_fft_example.ipynb
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- butterworth
- style transfer
- VPN
- filter
- AWS
- database
- FFT
- tacotron
- scipy
- Computer science
- numpy
- 터널링
- IRR
- PYTHON
- detrend
- deep learning
- TensorFlow
- signal
- Rolling
- pandas
- Machine Learning
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함