简易数字基带信号系统仿真设计的matlab实现(带眼图)
作者:互联网
数字基带传输系统的输入信号是由终端设备或编码设备产生的二进制脉冲序列,通常是单极性的矩形脉冲信号(NRZ 码)。为了使这种信号适合于信道的传输,一般要经过码形变换器,把单极性的二进制脉冲变成双极性脉冲(如AMI 码或HDB3码)。发送滤波器对码脉冲进行波形变换,以减小信号在基带传输系统中传输时产生的码间串扰。信号在传输过程中,由于信道特性不理想及加性噪声的影响,会使接收到的信号波形产生失真,为了减小失真对信号的影响,接收信号首先进入接收滤波器滤波,然后再经均衡器对失真信号进行校正,最后由取样判决器恢复数字基带脉冲序列。
代码如下:
Ts = 1; % 码元周期
dt = Ts / 1; % 抽样时间间隔
N = 100; % 码元数
t = 0 : dt : (N * 1 - 1) * dt; % 序列传输时间
se_sign = sign( randn(1,N));%双极性NRZ
se_yuanxiaoxima = (se_sign + ones(1,100))*1/2;%原消息码
t_se2 = -25*Ts:0.5:25*Ts-0.5*dt;
subplot(11,1,1);stem(t_se2,se_yuanxiaoxima,'filled');axis([0 5 -1 1]);xlabel('time');ylabel('level');%输入的双极性NRZ演示
M_sample = 1000;
dtt = Ts/M_sample;
t_fangbo1 = -25:dtt/2:25-dtt/2;
se_fangbo = [];
gt1 = ones(1,M_sample);
gt0 = zeros(1,M_sample);
for i = 1:100
if se_yuanxiaoxima(i) == 1
se_fangbo = [se_fangbo gt1];
else
se_fangbo = [se_fangbo gt0];
end
end
subplot(11,1,2);plot(t_fangbo1,se_fangbo);axis([0 5 -1 1]);xlabel('time');ylabel('level');%输入波形的方波演示
se_sample = zeros(10,N);
se_sample(1,:) = se_sign;
se_sample = reshape(se_sample,1,10*N);
%插入9个0方便接下来的时域卷积
%fvtool(se_yuanxiaoxima,'Analysis','impulse');
t=-25*Ts:0.1*dt:25*Ts-0.1*dt;%经过上采样的数列,单次采样间隔为为0.1s
ht=sinc(t/Ts).*(cos(0.5*pi*t/Ts))./(1-4*0.5^2*t.^2/Ts^2+eps);
waveout = conv(se_sample,ht);
t1 = linspace(-25*Ts,25*Ts,length(waveout));
subplot(11,1,3);plot(t1,waveout);axis([0 5 -2 2]);xlabel('time');ylabel('level');%经过理想低通滤波器(发送滤波器)输出之后的波形
%此处取滚降系数为0.5,waveout为发送滤波器输出波形
wave_channel = awgn(waveout,20);
subplot(11,1,4);plot(t1,wave_channel);axis([0 5 -2 2]);xlabel('time');ylabel('level');%在信道中传输(添加噪声之后)的波形
%为理想波形添加噪声信号,此处为20db
wav_channel = zeros(10,length(waveout));
wav_channel(1,:)=wave_channel;
wav_channel = reshape(wav_channel,1,10*length(waveout));
ht=sinc(t/Ts).*(cos(0.5*pi*t/Ts))./(1-4*0.5^2*t.^2/Ts^2+eps);
wave_rec = conv(wav_channel,ht);
t3 = linspace(-25*Ts,25*Ts,length(wave_rec));
subplot(11,1,5);plot(t3,wave_rec);axis([0 5 -2 2]);xlabel('time');ylabel('level');%经过理想低通滤波器(接收滤波器)输出之后的波形
x_res = [];
x_res_mark = 1:length(wave_rec)/N:length(wave_rec);%将总的索引进行标记,在指定点对电平信号进行抽样
for i = 1:N
x_res = [x_res wave_rec(round(x_res_mark(i)))];
end
x_out = sign(x_res);
t_se_out = -25*Ts:0.5:25*Ts-0.5;
subplot(11,1,6);stem(t_se_out,x_out,'filled');axis([0 5 -1 1]);xlabel('time');ylabel('level');%抽样结果
O_sample = 1000;
dttt = Ts/O_sample;
t_fangbo1 = -25:dttt/2:25-dttt/2;
se_fangbo1 = [];
gtt1 = ones(1,O_sample);
gtt0 = zeros(1,O_sample);
for i = 1:N
if x_out(i) == 1
se_fangbo1 = [se_fangbo1 gtt1];
else
se_fangbo1 = [se_fangbo1 gtt0];
end
end
subplot(11,1,7);plot(t_fangbo1,se_fangbo1);axis([0 5 -1 1]);xlabel('time');ylabel('level');
subplot(11,1,[8 9]);
eye_num=2;
P_sample = 20;
ss=zeros(1,eye_num*P_sample) ;
ttt=0: dt: eye_num*P_sample*dt-dt ;
for k=3: 50
ss=waveout(k*P_sample+1:(k+eye_num) *P_sample) ;
drawnow ;
plot (ttt,ss); hold on;
end
wave_rec1 = [wave_rec,zeros(1,11)];
subplot(11,1,[10 11]);
eye_num=2;
Q_sample = 210;
ss=zeros(1,eye_num*Q_sample) ;
ttt=0: dt: eye_num*Q_sample*dt-dt ;
for k=3: 50
ss=wave_rec(k*Q_sample+1:(k+eye_num) *Q_sample) ;
drawnow ;
plot (ttt,ss); hold on;
end
运行结果如上图所示
标签:25,眼图,Ts,信号系统,wave,sample,matlab,dt,se 来源: https://blog.csdn.net/qq_45471796/article/details/123217234