此博客供信息类专业的同学借鉴,搜集整理了网络上的资料,已经过调试。
题目要求:自己构造一时间函数-增量调制-Miller码-汉明码-PSK-AWGN
使用工具:MATLAB R2014a
1、主程序
%empty the processing-----------------------
close all;
clear all;%original signal-----------------------------
Ts=1e-3;
t=0:Ts:20*Ts;
x=sin(2*pi*50*t)+0.5*sin(2*pi*150*t);
figure(1)
plot(t,x,'-o');axis([0 20*Ts,-2 2]);
title('源信号');%delta modulation-----------------------------
y_DM = DM_coding(x,t) ;
figure(2)
stairs(t,y_DM);axis([0 20*Ts,-2 2]);
title('DM调制输出');%Miller modulation----------------------------
y_Miller = Miller_coding(y_DM) ;
t2 = 0:Ts:41*Ts;
figure(3)
stairs(t2,y_Miller);axis([0 40*Ts -2 2]);
title('Miller编码信号');%Hamming modulation----------------------------
y_Hamming=encode(y_Miller,7,4,'hamming') ;
figure(4)
stairs(y_Hamming);axis([0 length(y_Hamming) -2 2]);
title('Hamming编码');%2PSK modulaiton----------------------------
y_PSK = PSK_coding(y_Hamming);
figure(5)
plot(y_PSK);
axis([0 length(y_PSK) -2 2]);
title('2PSK调制信号');%AWGN-------------------------------------------
y_AWGN=awgn(y_PSK,30);
figure(6);
plot(y_AWGN);axis([0 length(y_AWGN) -2 2]);
title('加高斯白噪声'); %PSK demodulation------------------------------------
y_psk_d = PSK_decoding(y_AWGN);
figure(7)
stairs(y_psk_d);axis([0 length(y_psk_d) -2 2]);
title('PSK解调信号(Hamming)');%Hamming demodulation--------------------------------
y_Hamming_d=decode(y_psk_d,7,4,'hamming');
figure(8)
stairs(y_Hamming_d);axis([0 length(y_Hamming_d) -2 2]);
title('Hammming译码输出信号(Miller)');%Miller demodulation-------------------------------
y_Miller_d = Miller_decoding(y_Hamming_d);
figure(9)
stairs(y_Miller_d);axis([0 length(y_Miller_d) -2 2]);
title('Miller译码输出信号(DM信号)');%delta demodulation---------------------------------
y_DM_d = DM_decoding(y_Miller_d,t);
figure(10)
stairs(t,y_DM_d);axis([0 20*Ts -2 2]);
title('DM译码(原始模拟信号)');%original signal modulation--------------------------
figure(11)
X=[0:Ts/100:21*Ts];Y=spline(t,y_DM_d,X);
plot(X,Y,'r-');hold on;
plot(t,y_DM_d, 'rx');axis([0 21*Ts,-2 2]);
x=sin(2*pi*50*t)+0.5*sin(2*pi*150*t);
plot(t,x,'-o');axis([0 20*Ts,-2 2]);
title('发送和接收信号对比,蓝色为源信号,红色为接收信号');%signal distortion----------------------------------
di=0;
for k=1:length(t)d=(x(k)-y_DM_d(k))^2/length(t);di=di+d;
end
disp('失真度为 ');
disp(di);
2、子程序
2.1、增量调制
function y = DM_coding(input,t)delta = 0.4 ;
d(1+length(t)) = 0 ;for k = 1:length(t)e(k) = input(k) - d(k) ;e_q(k) = delta*(2*(e(k)>=0)-1) ;d(k+1) = e_q(k) + d(k) ; codeout(k) = (e_q(k)>0) ;
endy = reshape(codeout',1,length(codeout)) ;
2.2、增量解调
function y = DM_decoding(x,t) delta = 0.4 ;
Dr(1+length(t)) = 0 ; for k = 1:length(t)eq(k) = delta*(2*x(k)-1 ); codeout(k) = eq(k) + Dr(k) ;Dr(k+1) = codeout(k) ;
endy = reshape(codeout',1,length(codeout)) ;
2.3、Miller编码
function y = Miller_coding(x)m = length(x) ;
codeout = zeros(1,2*m) ;
f = 0;
d = 1;for i = 1:mif x (i) == 1 ;codeout (2*i-1) = f ;codeout (2*i) = not(f) ;f = not(f) ;d = 1 ;elseif d == 1 ;codeout (2*i-1) = f ;codeout (2*i) = f ;d = 0 ;elsef = not(f);codeout (2*i-1) = f ;codeout (2*i) = f ;d = 0 ;endend
endy = reshape(codeout',1,length(codeout)) ;
2.4、Miller解码
function y = Miller_decoding(x)m=length(x);
codeout=[];
for k=1:m/2if x(2*k-1)== x(2*k)codeout=[codeout 0];elsecodeout=[codeout 1];end
endy = reshape(codeout',1,length(codeout)) ;
2.5、2PSK调制
function y = PSK_coding(x)f=4*pi;
t=0:2*pi/199:2*pi;A=[];
codeout=[];for n=1:length(x)if x(n)==0 B=ones(1,200);c=cos(f*t); elseif x(n)==1B=ones(1,200); c=cos(f*t+pi); endA=[A B]; codeout=[codeout c];
endy = reshape(codeout',1,length(codeout)) ;
2.6、2PSK解调
function y = PSK_decoding(x)fs=1024;
[b,a]=butter(2,[10,15]*2/fs);
sg1=filter(b,a,x); t=0:2*pi/199:2*pi;
f=4*pi;
mod=[];for n=1:length(x)/200c=cos(f*t);mod=[mod c];
end
sg2=mod.*x;[b,a]=butter(2,10*2/fs);
jt=filter(b,a,sg2); for m=1:length(x); if jt(m)<0;jt(m)=1;else jt(m)>=0;jt(m)=0;end
endm2=100;
codeout=[];
while m2<length(jt)if jt(m2)==0codeout=[codeout 0];elseif jt(m2)==1codeout=[codeout 1];endm2=m2+200;
endy = reshape(codeout',1,length(codeout)) ;
3、此部分代码为扩展内容-ADM自适应增量调制(未找到解调代码)
function y = Delta_Modulation(input_signal,N_point)
%增量调制函数,输出自适应增量调制adm_outstep_min=0.125; %自适应增量调制最小步长为1/8
step_adm=zeros(1,N_point); %自适应增量调制步长序列
codeout=zeros(1,N_point); %量化输出
codeout(1)=1;
adm_out(N_point)=0; %初始化序列for i=2:1:N_point %进行自适应增量调制codeout(i)=sign( input_signal(i-1)-adm_out(i-1));%将上一时刻的输出与实际输入进行比较,如果输出小于输入,量化为1,%该时刻上升一个台阶,否则量化为-1,该时刻下降一个台阶if step_adm(i-1)<step_min%如果上一时刻步长比最小步长要小,则使此时刻步长等于最小步长step_adm(i)=step_min;elsestep_adm(i)=step_adm(i-1)*(1+0.5*codeout(i-1)/codeout(i));%如果本时刻与前一时刻量化比较结果同号,则将步长增加50%,异号则将步长减少50%endadm_out(i)=adm_out(i-1)+codeout(i)*step_adm(i);%该时刻的输出在上一时刻输出值的基础上增加或减少一个现有台阶步长的增量
endy = reshape(adm_out',1,length(adm_out));
4、调试图片
失真度为
0.0981
ADM增量调制