% 生成单个码元
Ts = 1;% 码元周期
N_sample = 128;% 单个码元抽样点数
dt = Ts / N_sample;% 抽样时间间隔
N = 20;% 码元个数
t = 0 : dt : (N * N_sample - 1) * dt;% 序列传输时间
duty1 = ones(1, N_sample);% 占空比100%
duty2 = [ones(1, N_sample/2), zeros(1, N_sample/2)];% 占空比50%
duty3 = [ones(1, N_sample/4), ones(1, N_sample/4), ones(1, N_sample/4), zeros(1, N_sample/4)];% 占空比75%
% 生成随机序列
RAN = randi([0,1],1,N);% 随机0 1整数序列
% 单极性归零码
code1 = [];
code2 = [];
code3 = [];
for i = 1 : N % 生成序列
if RAN(i) == 1
code1 = [code1 duty1];
code2 = [code2 duty2];
code3 = [code3 duty3];
else
code1 = [code1 zeros(1, N_sample)];
code2 = [code2 zeros(1, N_sample)];
code3 = [code3 zeros(1, N_sample)];
end
end
% 双极性归零码
code4 = [];
code5 = [];
code6 = [];
for i = 1 : N % 生成序列
if RAN(i) == 1
code4 = [code4 duty1];
code5 = [code5 duty2];
code6 = [code6 duty3];
else
code4 = [code4 -duty1];
code5 = [code5 -duty2];
code6 = [code6 -duty3];
end
end
% 绘制波形
figure (1)
subplot(3, 1, 1);plot(t, code1);title('占空比100%单极性归零码');
xlabel('t/s');ylabel('幅度');axis([0 25 -2 2]);
subplot(3, 1, 2);plot(t, code2);title('占空比50%单极性归零码');
xlabel('t/s');ylabel('幅度');axis([0 25 -2 2]);
subplot(3, 1, 3);plot(t, code3);title('占空比75%单极性归零码');
xlabel('t/s');ylabel('幅度');axis([0 25 -2 2]);
figure (2)
subplot(3, 1, 1);plot(t, code4);title('占空比100%双极性归零码');
xlabel('t/s');ylabel('幅度');axis([0 25 -2 2]);
subplot(3, 1, 2);plot(t, code5);title('占空比50%双极性归零码');
xlabel('t/s');ylabel('幅度');axis([0 25 -2 2]);
subplot(3, 1, 3);plot(t, code6);title('占空比75%双极性归零码');
xlabel('t/s');ylabel('幅度');axis([0 25 -2 2]);
% 功率谱绘制与计算
fft_code1 = fftshift(fft(code1));% 求序列频谱
fft_code2 = fftshift(fft(code2));
fft_code3 = fftshift(fft(code3));
fft_code4 = fftshift(fft(code4));
fft_code5 = fftshift(fft(code5));
fft_code6 = fftshift(fft(code6));
PE1 = 10 * log10(abs(fft_code1) .^ 2 / (N * Ts));% 公式法求功率谱密度
PE2 = 10 * log10(abs(fft_code2) .^ 2 / (N * Ts));
PE3 = 10 * log10(abs(fft_code3) .^ 2 / (N * Ts));
PE4 = 10 * log10(abs(fft_code4) .^ 2 / (N * Ts));
PE5 = 10 * log10(abs(fft_code5) .^ 2 / (N * Ts));
PE6 = 10 * log10(abs(fft_code6) .^ 2 / (N * Ts));
PEL1 = (-length(fft_code1) / 2 : length(fft_code1) / 2 - 1) / N;% 转换成对应频率
PEL2 = (-length(fft_code2) / 2 : length(fft_code2) / 2 - 1) / N;
PEL3 = (-length(fft_code3) / 2 : length(fft_code3) / 2 - 1) / N;
PEL4 = (-length(fft_code4) / 2 : length(fft_code4) / 2 - 1) / N;
PEL5 = (-length(fft_code5) / 2 : length(fft_code5) / 2 - 1) / N;
PEL6 = (-length(fft_code6) / 2 : length(fft_code6) / 2 - 1) / N;
figure (3)
subplot(3, 1, 1);plot(PEL1, PE1);title('占空比100%单极性归零码功率谱');
xlabel('频率/Hz');axis([-20 20 -50 50]);ylabel('P/dB');
subplot(3, 1, 2);plot(PEL2, PE2);title('占空比50%单极性归零码功率谱');
xlabel('频率/Hz');axis([-20 20 -50 50]);ylabel('P/dB');
subplot(3, 1, 3);plot(PEL3, PE3);title('占空比75%单极性归零码功率谱');
xlabel('频率/Hz');axis([-20 20 -50 50]);ylabel('P/dB');
figure (4)
subplot(3, 1, 1);plot(PEL4, PE4);title('占空比100%双极性归零码功率谱');
xlabel('频率/Hz');axis([-20 20 -50 50]);ylabel('P/dB');
subplot(3, 1, 2);plot(PEL5, PE5);title('占空比50%双极性归零码功率谱');
xlabel('频率/Hz');axis([-20 20 -50 50]);ylabel('P/dB');
subplot(3, 1, 3);plot(PEL6, PE6);title('占空比75%双极性归零码功率谱');
xlabel('频率/Hz');axis([-20 20 -50 50]);ylabel('P/dB');
基于matlab仿真占空比为50%、75%以及100%的单、双极性归零码波形以及其功率谱。
需积分: 50 60 浏览量
2020-05-31
19:56:51
上传
评论 8
收藏 3KB ZIP 举报
芷年若相依
- 粉丝: 100
- 资源: 8
最新资源
- Windows 常见运行运行库32+64
- 基于3KW光伏并网单相逆变器设计(TMS320F28035控制板+显示板+STM32F103功率板)硬件(原理图+PCB)工程
- 正点原子HAL库 STM32F4 外部中断(学习自用附源码)
- delphi rzcombobox DropDownList 灰色背景改为白色
- sap sd.docsap sd.doc
- torch-1.10.2-cp38-cp38-win-amd64.whl
- 菜单栏实现增加数据,修改数据,查询数据,删除数据
- 全国省市区三级联动json文件,带code
- C8_全局&局部&static.zip
- Unity和安卓交互插件Unity调Android Native Goodies PRO
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈