如何在正弦波中进行相移?

时间:2018-07-22 19:39:11

标签: python-3.x signal-processing waveform phase

我有两个问题:

1-然后估算未知波的相位 2-通过加或减另一波的相位来校正/更改所研究信号的相位。

我使用以下代码创建了一个正弦波,并尝试了我的想法

import numpy as np
import scipy.optimize as optimize
import scipy.fftpack as fftpack
import matplotlib.pyplot as plt

pi = np.pi
##############
# generate a perfect sine wave
def mysine(time, amplitude, frequency, phase):
    return amplitude * np.sin(frequency * time + phase)

def sin_signal(time, amplitude, frequency, phase):
    return amplitude * np.sin(frequency * time + phase)

#****************************** Signal conditions ******************************
number_of_points = 200
time = np.linspace(0,0.002,number_of_points)
frequency = 2500
amplitude = 1
phase = 0
##############################################
sin1_signal = sin_signal(time, amplitude, frequency,phase)

Real_time = time
Real_signal = sin1_signal

# Get the frequency of signal
yhat = fftpack.rfft(Real_signal)
idx = (yhat**2).argmax()
freqs = fftpack.rfftfreq(number_of_points,d = (Real_time[1]-Real_time[0])/(2*pi))
frequency_est = freqs[idx]


# Get the amplitude of signal
amplitude_est = Real_signal.max()

# Guess amplitude_est, frequency_est and phase
guess = [amplitude_est, frequency_est, 0]

(amplitude_est, frequency_est, phase_est), pcov = optimize.curve_fit(mysine, Real_time, Real_signal, guess)

period = 2*pi/frequency_est
print(amplitude_est, frequency_est, phase_est)

这段代码为我提供了以下结果: 幅度= 1.0频率= 2500.0相位= 0

所以,第一个问题就解决了。

第二个问题:如何改变被调查信号的相位?

0 个答案:

没有答案