【问题标题】:Chirping a sinusoid啁啾正弦曲线
【发布时间】:2018-06-21 12:58:48
【问题描述】:

下面是我的代码 我想在 -50Mhz 和 50Mhz 之间扫描 400MHz 音调。意思是 扫描范围应在 350MHz 和 450MHz 之间。但事实并非如此。别 了解这是什么原因。有人认为这是因为频率是相位的导数。我在“sweep_sine”函数的注释行中也给出了一个镜头,但这似乎也无济于事。任何帮助,将不胜感激。

添加了意外程序输出的图像。如您所见,我能够将我的 400MHz 音调转换为 300MHz。当我尝试以类似于 shift 的方式进行扫描时;输出不正确,因为它没有从 350MHz 扫描到 450MHz,中间是 400MHz 音调。

我现在可以正确扫描信号,如图 2 所示。当信号为 e^i2*pift 形式时,时域信号看起来也很好。但是,当我使用 sin(2*pift) 形式的真实信号时,时域版本看起来已损坏(图 3)。这可能是什么原因?谢谢。

https://i.stack.imgur.com/9H1Dk.png

https://i.stack.imgur.com/Ey3tQ.png

https://i.stack.imgur.com/FzmDS.png

import numpy as np
import matplotlib.pyplot as plt

def gen_sig(freq=380e6, fs=6080e6, n_samp=6400):
    ts = 1/fs
    t_arr = np.arange(0, n_samp)*ts
    sig = np.exp(2 * 1j * np.pi * freq * t_arr)
    #sig = np.sin(2 * np.pi * freq * t_arr)
    return sig,ts

def freq_shift_sine(sine, ts, shift_freq = 50e6):
    tx_sig_t = np.linspace(0, ts*sine.shape[-1], num=sine.shape[-1])
    #tx_sig_sqrd =  np.square(tx_sig_t)
    #hift the sine
    freq_shftd_sig = sine * np.exp(1.0j * 2 * np.pi * (shift_freq * tx_sig_t))
    #freq_shftd_sig = sine * np.exp(1.0j * np.pi * (shift_freq * tx_sig_sqrd))    
    return freq_shftd_sig

def sweep_sine(sine, ts, up_lim = 50e6, low_lim = -50e6):
    tx_sig_t = np.arange(0, sine.shape[-1])*ts
    tx_sig_sqrd =  np.square(tx_sig_t)
    phi = low_lim*tx_sig_t + (up_lim-low_lim)*(tx_sig_sqrd/(2*ts*sine.shape[-1]))
    dopp_shftd_sig = sine * np.exp(1.0j* 2 *np.pi * phi)
    return dopp_shftd_sig   

if __name__=='__main__':
    #generate a sine wave 16 times over sampled
    tx_sig, t_samp = gen_sig(freq=400e6, fs=6400e6, n_samp=6400)
    #do an fft
    tx_sig_fft = np.fft.fft(tx_sig)
    #generate freqency axis for fft
    freq_arr = np.fft.fftfreq(tx_sig.shape[-1], t_samp)
    #shift sine wave
    tx_sig_shifted = freq_shift_sine(tx_sig, t_samp, shift_freq = -100e6)
    #fft the shifted sine
    tx_sig_shftd_fft = np.fft.fft(tx_sig_shifted) 
    #sweep sine wave by up_lim+low_lim Hz
    tx_sig_swept = sweep_sine(tx_sig, t_samp, up_lim = 50e6, low_lim = -50e6)
    #fft the swept sine
    tx_sig_swept_fft = np.fft.fft(tx_sig_swept)    
    plt.figure()
    plt.plot(freq_arr, abs(tx_sig_fft))
    plt.plot(freq_arr, abs(tx_sig_shftd_fft))       
    plt.plot(freq_arr, abs(tx_sig_swept_fft))
    plt.axis([0,1e9, 0, 2e3])
    plt.figure()
    plt.plot(tx_sig)
    plt.plot(tx_sig_shifted)
    plt.plot(tx_sig_swept)    
    plt.axis([0,100, -1.2, 1.2])

【问题讨论】:

  • 我不清楚你想达到什么目标。只从dopp这个名字我终于意识到你想要一个音调的转变。转换应该模仿多普勒效应。对吗?
  • 我会有一个循环,我在其中合成曲线但是为了实现逐渐的频移,我会改变我应用到 theta 的 delta 的大小,这是我输入 sin 函数的值跨度>
  • 对缺乏清晰表示歉意,简单地说,我乘 sine_sig = np.sin(2 * np.pi * freq * t_arr) 将 sine_sig 从 freq - sweep_start 扫描到频率 + sweep_finish
  • @rth 是正确的。在原始帖子中的图像中,我可以看到扫描,但开始和结束频率与我在程序的主要功能中提供的频率不正确。
  • @zoulzubazz 请尝试绘制信号与时间的关系。你会发现,在你的两个函数之后:常数位移和多普勒变换,信号看起来不像一个正弦波。

标签: python numpy signal-processing fft complex-numbers


【解决方案1】:

我可能错了,但我认为问题出在你的信号上。你只有一个实部,在复平面中移动相位对实部没有太大帮助。

解决这个问题的可能方法是使信号变得复杂。最好的方法是进行希尔伯特变换并将其用作信号。

您的代码可能如下所示

import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert


def gen_sine(freq=380e6, fs=6080e6, n_samp=6400):
    ts = 1/fs
    t_arr = np.arange(0, n_samp)*ts
    #sine_sig = np.exp(2 * 1j * np.pi * freq * t_arr)
    sine_sig = np.sin(2 * np.pi * freq * t_arr)
    return sine_sig,ts

def freq_shift_sine(sine, ts, shift_freq = 50e6):
    tx_sig_t = np.linspace(0, ts*sine.shape[-1], num=sine.shape[-1])
    #tx_sig_sqrd =  np.square(tx_sig_t)
    #hift the sine
    freq_shftd_sig = hilbert(tx_sig) * np.exp(1.0j * 2 * np.pi * (shift_freq * tx_sig_t))
    #freq_shftd_sig = sine * np.exp(1.0j * np.pi * (shift_freq * tx_sig_sqrd))    
    return freq_shftd_sig

def sweep_sine(sine, ts, up_lim = 50e6, low_lim = -50e6):
    #tx_sig_t = np.arange(0, sine.shape[-1])*ts 
    tx_sig_t = np.linspace(0, ts*sine.shape[-1], num=sine.shape[-1])
    #tx_sig_sqrd =  np.square(tx_sig_t)   
    freq_step_arr = np.linspace(low_lim, up_lim, sine.shape[-1])
    dopp_shftd_sig = hilbert(tx_sig) * np.exp(1.0j * 2 * np.pi * (freq_step_arr * tx_sig_t))
    #dopp_shftd_sig = sine * np.exp(1.0j * np.pi * (freq_step_arr * tx_sig_sqrd))
    return dopp_shftd_sig

if __name__=='__main__':
    #generate a sine wave 16 times over sampled
    tx_sig, t_samp = gen_sine(freq=400e6, fs=6400e6, n_samp=6400)
    #do an fft
    tx_sig_fft = np.fft.fft(tx_sig)
    #generate freqency axis for fft
    freq_arr = np.fft.fftfreq(tx_sig.shape[-1], t_samp)
    #shift sine wave
    tx_sig_shifted = freq_shift_sine(tx_sig, t_samp, shift_freq = -100e6)
    #fft the shifted sine
    tx_sig_shftd_fft = np.fft.fft(tx_sig_shifted) 
    #sweep sine wave by up_lim+low_lim Hz
    tx_sig_swept = sweep_sine(tx_sig, t_samp, up_lim = 50e6, low_lim = -50e6)
     #fft the swept sine
    tx_sig_swept_fft = np.fft.fft(tx_sig_swept)    
    #plt.figure()
    #plt.plot(freq_arr, abs(tx_sig_swept_fft))    
    #plot sine wave fft
    #plt.figure()
    plt.figure(1)
    plt.plot(freq_arr, abs(tx_sig_fft))
    plt.plot(freq_arr, abs(tx_sig_shftd_fft))       
    plt.plot(freq_arr, abs(tx_sig_swept_fft))
    plt.axis([0,1e9, 0, 2e3])
    plt.figure(2)
    plt.specgram(tx_sig_swept, NFFT=80, Fs=6400e6, noverlap=16)
    #plt.axis([0,0.000001, 0, 5e6])
    plt.figure(3)
    plt.subplot(311)
    t_time = np.arange(0, tx_sig.shape[-1])*t_samp
    plt.plot(t_time, tx_sig)
    plt.plot(t_time, np.imag(hilbert(tx_sig)) )
    plt.subplot(312)
    plt.plot(t_time, tx_sig_shifted)
    plt.subplot(313)
    plt.plot(t_time, tx_sig_swept )
    plt.show()

它产生或多或少的频谱图并且不会破坏结果信号。希望对您有所帮助。

【讨论】:

    【解决方案2】:

    你犯了一个很常见的错误。在每个时间步增加频率和时间(当您将它们相乘以创建 exp 或 sine 函数的相位参数输入时)会使频率增加太多。而是计算出在该时间步中所需频率的每个新时间步的相位应该变化多少,然后添加该相位增量而不是进行乘法运算以获得新的相位输入到您的正弦或exp函数。

    【讨论】:

    • 如果信号不是音调(正弦波)怎么办?额外的阶段会起作用吗?
    • 如果信号是周期性的并且可以按相位索引或参数化
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多