SHIFT 개념 이해하기 예제 with SIN/COS/TAN

<개념>/기타|2021. 12. 30. 12:18
반응형
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from synthetic_tests_lib import crosscorr, compute_shift
from scipy import signal
# 완전다른 그래프랑 어케 나타나는지 
x = [0,1,2,3,4,5,6,7,8,9]
g1 = [1,2,3,4,5,6,7,8,9,10]
g2 = [10,9,8,7,6,5,4,3,2,1]
shift = compute_shift(g1,g2)
plt.plot(x,g1,label='g1')
plt.plot(x,g2,label='g2')
plt.legend(loc='upper right')
plt.title("compute_shift(g1,g2)")
print('shift : '+ str(shift))
print('shift 가 의미하는바 =  g1 그래프가 얼마만큼 움직여야 g2 그래프와 동일해는가')

from synthetic_tests_lib import crosscorr, compute_shift

# 완전다른 그래프랑 어케 나타나는지 
g1 = np.sin(x)
g2 = np.cos(x)
g3 = np.tan(x)
x1=[3,4,5,6,7,8,9,10,11,12]
g4 = np.sin(x1)
g5 = np.sin(x)*2
x2=[0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8]
g6 = np.sin(x2)

shift = compute_shift(g1,g2)
shift2 = compute_shift(g1,g3)
shift3 = compute_shift(g1,g5)
shift4 = compute_shift(g1,g6)

shift5 = compute_shift(g3,g5)
shift6 = compute_shift(g2,g4)

plt.plot(x,g1,label='g1 : sin(x)')
plt.plot(x,g2,label='g2 : cos(x)')
plt.plot(x,g3,label='g3 : tan(x)')
plt.plot(x,g4,label='g4 : sin(x+3)')
plt.plot(x,g5,label='g5 : sin(x)*2')
plt.plot(x,g6,label='g6 : sin(1/5*x)')



plt.legend(loc='upper right')
plt.title("compute_shift")
print('shift(sin,cos) : '+ str(shift))
print('shift2(sin,tan) : '+ str(shift2))
print('shift3(sin,sin*2) : '+ str(shift3))
print('shift4(sin,sin(1/5*x) : '+ str(shift4))
print('shift5(tan,sin*2) : '+ str(shift5))
print('shift6(cos,sin(x+3) : '+ str(shift6))

d1, d2 ,d3 = pd.Series(g1), pd.Series(g2),pd.Series(g3)
lags = np.arange(-(5), (5), 1)
rs = np.nan_to_num([crosscorr(d1, d2, lag) for lag in lags])
rs2 = np.nan_to_num([crosscorr(d1, d3, lag) for lag in lags])
#print('rs'+str(rs))
#print('rs2'+str(rs2))
#print(np.corrcoef(g1,g2))

# 높이는 상관없다.(sinx,sinx*2) shift=0

# 완전다른 그래프랑 어케 나타나는지 
x = [0,1,2,3,4,5,6,7,8,9]
g1 = [1,0,0,1,1,0,0,1,1,0]
g2 = [10,9,8,7,6,5,4,3,2,1]
shift = compute_shift(g1,g2)
plt.plot(x,g1,label='g1')
plt.plot(x,g2,label='g2')
plt.legend(loc='upper right')
plt.title("compute_shift(g1,g2)")
print('shift : '+ str(shift))
print('shift 가 의미하는바 =  g1 그래프가 얼마만큼 움직여야 g2 그래프와 동일해는가')

d1, d2 = pd.Series(g1), pd.Series(g2)
lags = np.arange(-(5), (5), 1)
rs = np.nan_to_num([crosscorr(d1, d2, lag) for lag in lags])
print('rs'+str(rs))
print(np.corrcoef(g1,g2))

반응형

'<개념> > 기타' 카테고리의 다른 글

FPGA, NPU 초간단 개념  (0) 2022.02.28
푸리에 변환 초간단 정리  (0) 2022.01.30
자주나오는 이산수학관련 내용  (0) 2021.11.28
RestfulAPI 개념정리  (0) 2021.08.14
AJAX,JSON 개념메모  (0) 2021.08.14

댓글()