%- 2DPSK 调制与解调
%---------------------------------------------------
%>>>>>>>>>>>>>>>>>>Initial_Part>>>>>>>>>>>>>>>>>>>>>
%---------------------------------------------------
function y=dpsk2()
fs =72000000;
Time_Hold_On = 1/24000;
Num_Unit = fs * Time_Hold_On;
High_Level = ones ( 1, Num_Unit );
Low_Level = zeros ( 1, Num_Unit );
w = 250000;
A = 1;
%---------------------------------------------------
%>>>>>>>>>>>>>>>>>>Initial_The_Signal>>>>>>>>>>>>>>>
%---------------------------------------------------
Sign_Set = [1,0,0,1,0,0,1,0]
Lenth_Of_Sign = length ( Sign_Set );
st = zeros ( 1, Num_Unit * Lenth_Of_Sign );
sign_orign = zeros ( 1, Num_Unit * Lenth_Of_Sign );
sign_result = zeros ( 1, Num_Unit * Lenth_Of_Sign );
t = 0 : 1/fs : Time_Hold_On * Lenth_Of_Sign - 1/fs;
%---------------------------------------------------
%>>>>>>>>>>>Generate_The_Original_Signal>>>>>>>>>>>>
%---------------------------------------------------
for I = 1 : Lenth_Of_Sign
if Sign_Set(I) == 1
sign_orign( (I-1)*Num_Unit + 1 : I*Num_Unit) = High_Level;
else
sign_orign( (I-1)*Num_Unit + 1 : I*Num_Unit) = Low_Level;
end
end
%---------------------------------------------------
%>>>>>>>>>>>>>>>>>>Modulation_Part>>>>>>>>>>>>>>>>>>
%---------------------------------------------------
for I = 1 : Lenth_Of_Sign
if Sign_Set(I) == 1
st( (I-1)*Num_Unit + 1 : I*Num_Unit) = A * cos ( 2 * pi * w * t( (I-1)*Num_Unit + 1 : I*Num_Unit ) + ( pi / 2 ) );
else
st( (I-1)*Num_Unit + 1 : I*Num_Unit) = A * cos ( 2 * pi * w * t( (I-1)*Num_Unit + 1 : I*Num_Unit ) );
end
end
figure(1)
subplot ( 2, 1, 1 )
plot(t, sign_orign);
axis( [ 0 , Time_Hold_On *( Lenth_Of_Sign + 1), - (A / 2), A + (A / 2) ] );
title ( '原始信号' );
grid
subplot ( 2, 1, 2 );
plot ( t, st );
axis( [ 0 , Time_Hold_On *( Lenth_Of_Sign + 1), - 3*(A / 2), 3*(A / 2) ] );
title ( '调制后的信号' );
grid
%---------------------------------------------------
%>>>>>>>>>>>>>>>>>>相乘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%---------------------------------------------------
dt = st .* cos ( 2 * pi * w * t );
figure(2)
subplot(3,1,1)
plot ( t, dt );
axis( [ 0 , Time_Hold_On *( Lenth_Of_Sign + 1), - 3*(A / 2), 3*(A / 2) ] );
title ( '相乘后的波形' );
grid
%%频域分析
f1=600000;N2=2^13;
n2=0:N2-1;t2=n2/f1;
DT=fft(dt,N2);mag=abs(DT);
f3=n2*f1/N2;
figure(3)
subplot(211);
plot(f3(1:N2/2),mag(1:N2/2))
title('相乘后频谱')
%%--------
figure(2)
subplot(3,1,2)
dt=awgn(dt,1) ;
plot(dt);
title('加入高斯白噪声后波形')
%---------------------------------------------------
%>>>>>>>>>>>>>>>>>>>低通滤波部分>>>>>>>>>>>>>>>>>>>>
%---------------------------------------------------
[N,Wn] = buttord( 2*pi*150000, 2*pi*250000,3,30,'s'); %临界频率采用角频率表示
[b,a]=butter(N,Wn,'s');
[bz,az]=impinvar(b,a,fs); %映射为数字的
dt = filter(bz,az,dt);
subplot(3,1,3)
plot ( t, dt );
axis( [ 0 , Time_Hold_On *( Lenth_Of_Sign + 1), - 3*(A / 2), 3*(A / 2) ] );
title ( '低通滤波后的波形' );
grid
figure(3)
%%频域分析--------------------
DT=fft(dt,N2);mag=abs(DT);
f5=n2*f1/N2;
subplot(212);
plot(f5(1:N2/2),mag(1:N2/2));
title('低通滤波后频谱')
%---------------------------------------------------
%>>>>>>>>>>>>>抽样判决 & 逆码变换部分>>>>>>>>>>>>>>>
%---------------------------------------------------
for I = 1 : Lenth_Of_Sign
if dt((2*I-1)*Num_Unit/2) < 0.25
sign_result( (I-1)*Num_Unit + 1 : I*Num_Unit) = High_Level;
else
sign_result( (I-1)*Num_Unit + 1 : I*Num_Unit) = Low_Level;
end
end
figure(4)
plot ( t, sign_result );
axis( [ 0 , Time_Hold_On *( Lenth_Of_Sign + 1), - 2*(A / 2), 3*(A / 2) ] );
title ( '逆码变换后的波形' );
grid