• 大小: 6KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: Matlab
  • 标签: 通信原  课程设  

资源简介

通信原理课程代码仅供参考,欢迎建议意见。

资源截图

代码片段和文件信息

%%FileName:signal_test1.m
%%DesignedBy:
%%Date:10.22.2018
%%O_data :原始数据
%%N_sample :采样次数
function [] = signal_test1(power)
%% 生成伪随机序列(原码)
pngen = commsrc.pn(‘NumBitsOut‘2^power);        % 产生 PN (伪随机噪声)信号包
data = generate(pngen);           % 产生 2^power PRBS 随机序列
fs = 1e6;       % 信号频率为 1MHz
Ts=1/fs;        % 信号周期
N_sample = 128;       % 采样次数为128个
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 生成NRZ RZ码
NRZ = [];       % NRZ波形存放
RZ = [];        % RZ波形存放
for i=1:length(data)      % 采样的同时也是对信号进行NRZ与RZ变换         
    for j=1:N_sample        % NRZ变换
        NRZ((i-1)*N_sample+j)=data(i);
    end
    for j=1:(N_sample/2)        % RZ变换
        RZ((i-1)*N_sample+j)=data(i);
        RZ((i-1)*N_sample+j+N_sample/2)=0;
    end    
end 
figure(1)       % 绘制NRZ,RZ波形图
subplot(2 2 1);plot((0:1:N_sample*length(data)-1)*Ts/N_sample RZ);grid on;axis([0 length(data)*Ts -2 2]);title(‘RZ波形‘);xlabel(‘S‘)
subplot(2 2 2);plot((0:1:N_sample*length(data)-1)*Ts/N_sample NRZ);grid on;axis([0 length(data)*Ts -2 2]);title(‘NRZ波形‘);xlabel(‘S‘)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 生成AMI码
AMI = zeros(size(data));
% number1记录原码中1的数量
number1 = 0;
% number0记录原码中0的数量
number0 = 0;
% 生成AMI码
for i=1:length(data)
    if data(i)==1
        number1 = number1+1;
        if mod(number12)==0
            AMI(i) = +1;        % 原码中偶数个1为-1
        end
        if mod(number12)==1
            AMI(i) = -1;        % 原码中奇数个1为+1
        end
    end
    if data(i)==0
        number0 = number0+1;        % 原码中的0保持不变
        AMI(i) = 0;
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 生成并绘制HDB3码
HDB = zeros(size(data));
% 给每个0000小节加V

for i= 1:length(data)
    % AMI中的-1和+1保持不变
        if abs(AMI(i))==1
            HDB(i) = AMI(i);
        end
    %
end
for j= 1: (length(data)-3)      %连续的四个0第三个0设为V,V用2表示
        if  ((AMI(j) == 0) && (AMI(j+1) == 0) && (AMI(j+2) == 0) && (AMI(j+3) == 0))
            HDB(j+3) = 2;
            HDB(j+2) = 0;
            HDB(j+1) = 0;
            HDB(j) = 0;
            j = j+3;
        end
end


% 每两个V极性相反
number2 = 0;
for i=1:length(data)
    if HDB(i)==2
        number2 = number2+1;
        if mod(number22)==0
            HDB(i) = +2;
        end
        if mod(number22)==1
            HDB(i) = -2;
        end
    end
end

% 统计每2个V之间非零脉冲个数,若偶数,则第2个V所在小节的第1个0变为B
firstV=0;
secondV=0;
number3=0;
for i=1:length(data)
    % 找到第一个V
    if abs(HDB(i)) == 2
        firstV = i;
     

评论

共有 条评论