|
数字滤波器的频率响应(幅频特性与相频特性)
freqz 明白了 0-2*pi 那个是 归一化的数字域频率
- # -*- coding: utf-8 -*-
- __author__ = u'东方耀 微信:dfy_88888'
- __date__ = '2022/9/1 上午8:57'
- __product__ = 'PyCharm'
- __filename__ = '25_BPSK调制解调物理层仿真'
- from common.radar_common import *
- # 选择Mark Directory as,然后选择第一项:Sources Root 红线消失
- # pip3 install scikit-commpy https://github.com/veeresht/CommPy
- # https://blog.51cto.com/u_15127585/2670058
- from commpy.filters import rcosfilter, rrcosfilter
- mat_file = "/home/jiang/matlab_works/zhihu_tongxin/h1.mat"
- mat_data = scio.loadmat(mat_file)
- print("matlab数据的字典keys=", mat_data.keys())
- bit_rate = 1000 # 比特率
- symbol_rate = 1000 # 符号率
- sps = 16 #每个符号的采样点数
- fc = 2000 #载波频率
- fs = 16000 #采样频率 = sps * symbol_rate
- sample_num = 129
- Roll_off_factor = 0.6
- time_idx, h_rc = rcosfilter(sample_num, Roll_off_factor, Ts=1/symbol_rate, Fs=fs)
- h1 = mat_data["h1"][0]
- # -1 1 2*fs sinc怎么取 没懂
- h_sinc = np.sinc(np.linspace(-4, 4, sample_num))
- print("时刻(间隔是采样间隔,非符合间隔):", len(time_idx), time_idx[1] - time_idx[0], 1/symbol_rate, 1/fs, time_idx[:10])
- print("滤波器幅值:", len(h_rc), h_rc[:5])
- # Compute the frequency response of a digital filter 数字滤波器的频率响应
- # `w` is normalized to the range [0, pi) (radians/sample)
- # The frequency response, as complex numbers
- # https://vimsky.com/examples/usage/python-scipy.signal.freqz.html
- w, frequency_response = signal.freqz(h_sinc, a=1)
- fig = plt.figure(figsize=(18, 20)) # H=2000 W=1800像素
- plt.figure(1)
- plt.subplots_adjust(wspace=0, hspace=0.4)
- plt.subplot(2, 1, 1)
- plt.xlabel("采样点/时刻",
- fontproperties=font, fontsize=15)
- plt.ylabel("幅值", fontproperties=font, fontsize=15)
- plt.plot(time_idx, h_sinc, marker='o', markersize=4,
- markerfacecolor=my_color[0], color=my_color[0], label="sinc")
- plt.plot(time_idx, h_rc, marker='o', markersize=4,
- markerfacecolor=my_color[1], color=my_color[1], label="python")
- plt.plot(time_idx, h1, marker='o', markersize=4,
- markerfacecolor=my_color[2], color=my_color[2], label="matlab")
- plt.legend(loc="best")
- plt.title('rcosfilter升余弦滚降滤波器(滚降因子beta=%.1f)对比' % Roll_off_factor,
- fontproperties=font, fontsize=18)
- plt.subplot(2, 1, 2)
- plt.plot(w/np.pi, 20 * np.log10(np.abs(frequency_response)), marker='o', markersize=4,
- markerfacecolor=my_color[3], color=my_color[3], label="Amplitude-frequency")
- # plt.plot(w, np.unwrap(np.angle(h)), 'g')
- plt.plot(w/np.pi, np.unwrap(np.angle(frequency_response)), marker='o', markersize=4,
- markerfacecolor=my_color[4], color=my_color[4], label="Phase-frequency")
- plt.xlabel("归一化的频率(*pi radians/sample)",
- fontproperties=font, fontsize=15)
- plt.ylabel("幅值(db)", fontproperties=font, fontsize=15)
- plt.legend(loc="best")
- plt.title('数字滤波器的频率响应(幅频特性与相频特性)',
- fontproperties=font, fontsize=18)
- plt.show()
复制代码
|
|