|
如何改变复信号的相位_仿真
- # -*- coding: utf-8 -*-
- __author__ = u'东方耀 微信:dfy_88888'
- __date__ = '2021/9/17 上午11:41'
- __product__ = 'PyCharm'
- __filename__ = '00_重新理解一下复信号'
- from scipy.fftpack import fft, ifft, fftshift
- import numpy as np
- import random
- import matplotlib.pyplot as plt
- import matplotlib.ticker as mticker
- from matplotlib.font_manager import FontProperties
- font_fname = "/usr/share/fonts/wps-office/simfang.ttf"
- font = FontProperties(fname=font_fname)
- # plt.rcParams['font.sans-serif']=['simfang']#设置作图中文显示
- # 如何改变复信号的相位_仿真
- continue_time_per_freq = 1e-6
- fs = 400e6
- f = 10e6
- sample_num_per_freq = int(np.ceil(continue_time_per_freq * fs))
- print("每个子脉冲的采样点数(采样速率有关)=", sample_num_per_freq)
- print("一个周期的采样点数(采样速率有关)=", fs/f)
- print("一共多少个周期=", continue_time_per_freq * f)
- x_time = np.linspace(0, continue_time_per_freq, sample_num_per_freq, endpoint=True)
- Rx_signal = []
- Rx_signal_phase = []
- RCS = 1
- Rx_signal.extend(list(RCS * np.exp(1j * 2 * np.pi * f * x_time)))
- # phase_random_array = np.random.uniform(-np.pi, np.pi, 100)
- # phase_random = random.choice(phase_random_array)
- phase = - np.pi / 2
- # print("随机选择一个相位:", phase_random)
- # 我的:
- Rx_signal_phase.extend(list(RCS * np.exp(1j * (2 * np.pi * f * x_time + phase))))
- # 闫博:
- # Rx_signal_phase.extend(list(RCS * np.exp(1j * (2 * np.pi * f * x_time) + phase)))
- Rx_signal = np.array(Rx_signal)
- Rx_signal_phase = np.array(Rx_signal_phase)
- Rx_y_fft = fftshift(fft(Rx_signal))
- x_f = np.linspace(0, int(fs), len(Rx_signal), endpoint=True) - int(fs/2)
- Rx_abs_y = np.abs(Rx_y_fft)
- Rx_angle_y = np.angle(Rx_y_fft)
- Rx_y_fft_phase = fftshift(fft(Rx_signal_phase))
- Rx_abs_y_phase = np.abs(Rx_y_fft_phase)
- Rx_angle_y_phase = np.angle(Rx_y_fft_phase)
- # 画图展示
- plt.figure(figsize=(14, 12))
- # seen_point_num = 600 # 刚好是2个子脉冲的 600=2*300 sample_num_per_freq
- plt.figure(1)
- plt.subplot(4, 1, 1)
- x1 = np.arange(sample_num_per_freq) # 0 299
- plt.plot(x1, Rx_signal.real[:sample_num_per_freq], marker='o', markersize=6, markerfacecolor='r')
- plt.title('信号_时域(实部)', fontproperties=font, fontsize=16)
- # plt.axis([0, 500, -3, 3])
- plt.xlabel('time/sample_num')
- plt.subplot(4, 1, 2)
- plt.plot(x1, Rx_signal.imag[:sample_num_per_freq], marker='o', markersize=6, markerfacecolor='b')
- plt.title('信号_时域(虚部)', fontproperties=font, fontsize=16)
- # plt.axis([0, 500, -3, 3])
- plt.xlabel('time/sample_num')
- plt.subplot(4, 1, 3)
- plt.plot(x1, Rx_signal_phase.real[:sample_num_per_freq], marker='o', markersize=6, markerfacecolor='r')
- plt.title('信号(phase)_时域(实部)', fontproperties=font, fontsize=16)
- # plt.axis([0, 500, -3, 3])
- plt.xlabel('time/sample_num')
- plt.subplot(4, 1, 4)
- plt.plot(x1, Rx_signal_phase.imag[:sample_num_per_freq], marker='o', markersize=6, markerfacecolor='b')
- plt.title('信号(phase)_时域(虚部)', fontproperties=font, fontsize=16)
- # plt.axis([0, 500, -3, 3])
- plt.xlabel('time/sample_num')
- plt.figure(2)
- plt.subplot(2, 2, 1)
- plt.plot(x_f, Rx_abs_y, 'blue')
- plt.title('信号的幅度谱(未归一化)', fontproperties=font, fontsize=16)
- plt.xlabel('freq')
- plt.subplot(2, 2, 2)
- plt.plot(x_f, Rx_angle_y, 'violet')
- plt.title('信号的相位谱', fontproperties=font, fontsize=16)
- plt.xlabel('freq')
- plt.subplot(2, 2, 3)
- plt.plot(x_f, Rx_abs_y_phase, 'blue')
- plt.title('信号_phase的幅度谱(未归一化)', fontproperties=font, fontsize=16)
- plt.xlabel('freq')
- plt.subplot(2, 2, 4)
- plt.plot(x_f, Rx_angle_y_phase, 'violet')
- plt.title('信号_phase的相位谱', fontproperties=font, fontsize=16)
- plt.xlabel('freq')
- plt.show()
复制代码
|
|