⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 untitled.m

📁 一个16PSK的调制与解调的程序
💻 M
字号:
%%16PSK的调制与解调,programmed by阿哲
clear all
clc
N = 2*10^3;
M = 16;
K = 4;
Err_bits = 0;

%%16psk modu
Tx_values = rand(1,N)-0.5;
for i=1:length(Tx_values)
    if Tx_values(i)>=0
        Tx_bits(i)=1;
    else
        Tx_bits(i)=0;
    end
end

for i=1:4:length(Tx_bits)
    bin_data = Tx_bits(i:i+3);
    dec_data = (8*Tx_bits(i))+(4*Tx_bits(i+1))+(2*Tx_bits(i+2))+Tx_bits(i+3);
    Mpsk_modu((i-1)/4+1) = exp(j*dec_data*2*pi/M);
    dec_data = 0;
end


%%IQ modu
Mpsk_modu_real = real(Mpsk_modu);
Mpsk_modu_imag = imag(Mpsk_modu);

scatterplot(Mpsk_modu)
title('16PSK信号的星座图(发送端)')

figure
subplot(211)
plot(Mpsk_modu_real)
xlabel('同相路信号')
ylabel('幅度')
title('发送端的16PSK信号')
subplot(212)
plot(Mpsk_modu_imag)
xlabel('正交路信号')
ylabel('幅度')
title('发送端的16PSK信号')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Channel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Mpsk_modu = awgn(complex(Mpsk_modu_real,Mpsk_modu_imag),25);

scatterplot(Mpsk_modu)
title('16PSK信号的星座图(接收端)')

%%16psk demodu
for j = 1:length(Mpsk_modu)
    ang_Mpsk(j) = angle(Mpsk_modu(j));
    if ang_Mpsk(j)>=pi/16&&ang_Mpsk(j)<pi*3/16
        Demapper_output((j-1)*K+1) = 0;
        Demapper_output((j-1)*K+2) = 0;
        Demapper_output((j-1)*K+3) = 0;
        Demapper_output((j-1)*K+4) = 1;
    elseif ang_Mpsk(j)>=pi*3/16&&ang_Mpsk(j)<pi*5/16
        Demapper_output((j-1)*K+1) = 0;
        Demapper_output((j-1)*K+2) = 0;
        Demapper_output((j-1)*K+3) = 1;
        Demapper_output((j-1)*K+4) = 0;
    elseif ang_Mpsk(j)>=pi*5/16&&ang_Mpsk(j)<pi*7/16
        Demapper_output((j-1)*K+1) = 0;
        Demapper_output((j-1)*K+2) = 0;
        Demapper_output((j-1)*K+3) = 1;
        Demapper_output((j-1)*K+4) = 1;
    elseif ang_Mpsk(j)>=pi*7/16&&ang_Mpsk(j)<pi*9/16
        Demapper_output((j-1)*K+1) = 0;
        Demapper_output((j-1)*K+2) = 1;
        Demapper_output((j-1)*K+3) = 0;
        Demapper_output((j-1)*K+4) = 0;
    elseif ang_Mpsk(j)>=pi*9/16&&ang_Mpsk(j)<pi*11/16
        Demapper_output((j-1)*K+1) = 0;
        Demapper_output((j-1)*K+2) = 1;
        Demapper_output((j-1)*K+3) = 0;
        Demapper_output((j-1)*K+4) = 1;
    elseif ang_Mpsk(j)>=pi*11/16&&ang_Mpsk(j)<pi*13/16
        Demapper_output((j-1)*K+1) = 0;
        Demapper_output((j-1)*K+2) = 1;
        Demapper_output((j-1)*K+3) = 1;
        Demapper_output((j-1)*K+4) = 0;
    elseif ang_Mpsk(j)>=pi*13/16&&ang_Mpsk(j)<pi*15/16
        Demapper_output((j-1)*K+1) = 0;
        Demapper_output((j-1)*K+2) = 1;
        Demapper_output((j-1)*K+3) = 1;
        Demapper_output((j-1)*K+4) = 1;
    elseif ang_Mpsk(j)>=pi*15/16||ang_Mpsk(j)<-pi*15/16
        Demapper_output((j-1)*K+1) = 1;
        Demapper_output((j-1)*K+2) = 0;
        Demapper_output((j-1)*K+3) = 0;
        Demapper_output((j-1)*K+4) = 0;
    elseif ang_Mpsk(j)>=-pi*15/16&&ang_Mpsk(j)<-pi*13/16
        Demapper_output((j-1)*K+1) = 1;
        Demapper_output((j-1)*K+2) = 0;
        Demapper_output((j-1)*K+3) = 0;
        Demapper_output((j-1)*K+4) = 1;
    elseif ang_Mpsk(j)>=-pi*13/16&&ang_Mpsk(j)<-pi*11/16
        Demapper_output((j-1)*K+1) = 1;
        Demapper_output((j-1)*K+2) = 0;
        Demapper_output((j-1)*K+3) = 1;
        Demapper_output((j-1)*K+4) = 0;
    elseif ang_Mpsk(j)>=-pi*11/16&&ang_Mpsk(j)<-pi*9/16
        Demapper_output((j-1)*K+1) = 1;
        Demapper_output((j-1)*K+2) = 0;
        Demapper_output((j-1)*K+3) = 1;
        Demapper_output((j-1)*K+4) = 1;
    elseif ang_Mpsk(j)>=-pi*9/16&&ang_Mpsk(j)<-pi*7/16
        Demapper_output((j-1)*K+1) = 1;
        Demapper_output((j-1)*K+2) = 1;
        Demapper_output((j-1)*K+3) = 0;
        Demapper_output((j-1)*K+4) = 0;
    elseif ang_Mpsk(j)>=-pi*7/16&&ang_Mpsk(j)<-pi*5/16
        Demapper_output((j-1)*K+1) = 1;
        Demapper_output((j-1)*K+2) = 1;
        Demapper_output((j-1)*K+3) = 0;
        Demapper_output((j-1)*K+4) = 1;
    elseif ang_Mpsk(j)>=-pi*5/16&&ang_Mpsk(j)<-pi*3/16
        Demapper_output((j-1)*K+1) = 1;
        Demapper_output((j-1)*K+2) = 1;
        Demapper_output((j-1)*K+3) = 1;
        Demapper_output((j-1)*K+4) = 0;
    elseif ang_Mpsk(j)>=-pi*3/16&&ang_Mpsk(j)<-pi*1/16
        Demapper_output((j-1)*K+1) = 1;
        Demapper_output((j-1)*K+2) = 1;
        Demapper_output((j-1)*K+3) = 1;
        Demapper_output((j-1)*K+4) = 1;
    elseif ang_Mpsk(j)>=-pi*1/16&&ang_Mpsk(j)<pi*1/16
        Demapper_output((j-1)*K+1) = 0;
        Demapper_output((j-1)*K+2) = 0;
        Demapper_output((j-1)*K+3) = 0;
        Demapper_output((j-1)*K+4) = 0;
    end
end

Rv_bits = Demapper_output;

%%Compare BER
for l = 1:length(Rv_bits)
    if Rv_bits(l)~=Tx_bits(l)
        Err_bits = Err_bits+1;
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -