|
python与matlab实现升余弦滚降滤波器与sinc对比
还有python导入matlab的数据文件*.mat
- %%%%%%%%%程序说明
- %%% b = rcosdesign(beta,span,sps,shape)
- %%% beta:滚降因子
- %%% span: 表示截断的符号范围,对滤波器取了几个Ts的长度
- %%% sps:每个符号的采样数
- %%% shape:可选择'normal'或者'sqrt'
- %%% b:1*(sps*span)的行向量,升余弦或余弦滤波器的系数
- %**************************** 程序主体 ****************%
- clear all;close all;clc;
- h1 = rcosdesign(0.8,8,16,'sqrt');
- save('h1.mat', 'h1');
- fvtool(h1,'Analysis','impulse'); %将脉冲响应可视化
- % freqz(h1,1);
- %**************************** 仿真结论 ***************%
- %%%%%成型滤波器rcosdesign的使用
- %%%新增freqz使用
复制代码
- # -*- 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.8
- 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])
- fig = plt.figure(figsize=(18, 20)) # H=2000 W=1800像素
- plt.figure(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.suptitle('rcosfilter升余弦滚降滤波器(滚降因子beta=%.1f)对比' % Roll_off_factor,
- fontproperties=font, fontsize=18)
- plt.show()
复制代码
|
|