import matplotlib.pyplot as plt import numpy as np signal = list(map(float, open('./data/signal.txt', 'r').readlines())) import numpy as np import matplotlib.pyplot as plt # 读取并处理信号数据 with open('./data/signal_filtered.txt', 'r') as file: signal_filtered = [complex(line.strip().replace(' ', '')) for line in file] # 获取实部和虚部 signal_filtered_real = [z.real for z in signal_filtered] signal_filtered_imag = [z.imag for z in signal_filtered] # 绘制复平面 plt.figure(figsize=(8, 8)) # 原始信号复平面展示 plt.scatter(signal_filtered_real, signal_filtered_imag, color='b', label='Filtered Signal') plt.axhline(0, color='grey', lw=0.5) plt.axvline(0, color='grey', lw=0.5) plt.grid(True, which='both', linestyle='--', lw=0.5) plt.xlabel('Real Part') plt.ylabel('Imaginary Part') plt.title('Filtered Signal on Complex Plane') plt.legend() # 保存图表 plt.savefig('./img/signal_filtered_complex_plane.png') plt.clf() signal_compressed = open('./data/signal_compressed.txt', 'r').readlines() signal_compressed = map(lambda x: x.replace(' ', '').replace('\n', ''), signal_compressed) signal_compressed = list(map(complex, signal_compressed)) plt.plot(np.abs(signal_compressed), label='abs',mfc='w',color='b') plt.legend() plt.savefig('./img/signal_compressed.png') plt.clf() signal_reduced = open('./data/signal_reduced.txt', 'r').readlines() signal_reduced = map(lambda x: x.replace(' ', '').replace('\n', ''), signal_reduced) signal_reduced = list(map(complex, signal_reduced)) plt.plot(np.abs(signal_reduced), label='abs',mfc='w',color='b') plt.legend() plt.savefig('./img/signal_reduced.png') plt.clf() hilbert_coefficients = open('./data/hilbert_coefficients.txt', 'r').readlines() hilbert_coefficients = map(lambda x: x.replace(' ', '').replace('\n', ''), hilbert_coefficients) hilbert_coefficients = list(map(complex, hilbert_coefficients)) plt.xlim(0, 10) plt.ylim(-1.2, 1.2) plt.plot(np.real(hilbert_coefficients), label='real', marker='x', mfc='w',color='r') plt.plot(np.imag(hilbert_coefficients), label='imag', marker='x', mfc='w',color='b') plt.legend() plt.savefig('./img/hilbert_coefficients.png') plt.clf() reference_signal = open('./data/reference_signal.txt', 'r').readlines() reference_signal = map(lambda x: x.replace(' ', '').replace('\n', ''), reference_signal) reference_signal = list(map(complex, reference_signal)) plt.ylim(-1.2, 1.2) plt.plot(np.real(reference_signal), label='real' ,mfc='w',color='b') plt.legend() plt.savefig('./img/reference_signal.png') plt.clf()