加性高斯白噪声信道(AWGN)下的digital调制格式识别分类

%%--------------------------------------------------------------------------
%题目:加性高斯白噪声信道(AWGN)下的digital调制格式识别分类
%实现思路:函数对信号添加了高斯白噪声,并进行带限处理,模拟信道的作用
%输入:
%输出:不同调制格式下识别率关于SNR的函数
%%--------------------------------------------------------------------------



clear all;
close all;
clc;

% signal generation;如果想要进行100组独立的测试,可以建立100次循环,产生100组独立的数据
for j = 1:6  % bit per symbol: 1. PSK; 2. QPSK; 3.8QAM; 4. 16QAM; 5. 32QAM; 6.64QAM;
System.BitPerSymbol = j;
snr = -5:20;  %SNR信噪比的设置,单位dB
correct_rate = zeros(length(snr), 1); %识别正确率
for snrIndex= 1:length(snr)
    correct = 0;

    for i =1:100     %进行100组独立测试
        
        temp = randi([1 6], 1, 1);         %测试随机模式下的识别正确率,不测随机模式时请注释掉
        System.BitPerSymbol = temp(1,1);   %测试随机模式下的识别正确率,不测随机模式时请注释掉
        
        Tx.SampleRate = 32e9; %symbol Rate,信号的码元速率,可以自行定义
        Tx.Linewidth = 0;%发射信号的载波的线宽,一般与信号的相位噪声有关,大小可自行设置,这里暂时设置为0
        Tx.Carrier = 0;%发射信号的载波频率,可自行设置,这里暂设为0
        M = 2^System.BitPerSymbol;
        numberOfData = 10000;
        
        %测试不同数据点在随机模式下的识别正确率,不测时请注释掉
        
        if(j == 1)
            numberOfData = 10000;
        elseif(j == 2)
            numberOfData = 1000;
        elseif(j == 3)
            numberOfData = 100;
        end
        
        Tx.DataSymbol = randi([0 M-1],1,numberOfData);%每一次随机产生的数据量,这里暂时设为数据点个数为10000个

%数据的不同调制方式产生:这里把2^3(8QAM)的形式单独拿出来设置,是为了实现最优的星型8QAM星座图
        if M ~= 8;
            h = modem.qammod('M', M, 'SymbolOrder', 'Gray');
            Tx.DataConstel = modulate(h,Tx.DataSymbol);
        else
            tmp = Tx.DataSymbol;
            tmp2  = zeros(1,length(Tx.DataSymbol));
            for kk = 1:length(Tx.DataSymbol)

                switch tmp(kk)
                    case 0
                        tmp2(kk) = 1 + 1i;
                    case 1
                        tmp2(kk) = -1 + 1i;
                    case 2
                        tmp2(kk) = -1 - 1i;
                    case 3
                        tmp2(kk) = 1 - 1i;
                    case 4
                        tmp2(kk) = 1+sqrt(3);
                    case 5
                        tmp2(kk) = 0 + 1i .* (1+sqrt(3));
                    case 6
                        tmp2(kk) = 0 - 1i .* (1+sqrt(3));
                    case 7
                        tmp2(kk) = -1-sqrt(3);
                end
            end
            Tx.DataConstel = tmp2;
            clear tmp tmp2;
        end


        Tx.Signal = Tx.DataConstel;

        %数据的载波加载,考虑到相位噪声等
        N = length(Tx.Signal);
        dt = 1/Tx.SampleRate;
        t = dt*(0:N-1);
        Phase1 = [0, cumsum(normrnd(0,sqrt(2*pi*Tx.Linewidth/(Tx.SampleRate)), 1, N-1))];
        carrier1 = exp(1i*(2*pi*t*Tx.Carrier + Phase1));
        Tx.Signal = Tx.Signal.*carrier1;


        Rx.Signal = awgn(Tx.Signal,snr(snrIndex),'measured');%数据在AWGN信道下的接收

        CMAOUT = Rx.Signal;

        %normalization接收信号功率归一化
        CMAOUT=CMAOUT/sqrt(mean(abs(CMAOUT).^2));
       
        s = Rx.Signal;
        signalPower = mean(abs(s).^2);
        noisePower = signalPower/(10^(snr(snrIndex)/10));
        C20 = mean(s.^2);
        C21 = mean(abs(s).^2);
        C21 = C21-noisePower;
        C40 = mean(s.^4)-3*C20^2;
        C41=mean((s.^3).*conj(s))-3*C20*C21;
        C42=mean(abs(s).^4)-abs(C20)^2-2*C21^2;
        C40_p=C40/C21^2;
        
        %根据C40_p的取值范围来判断哪种调制格式
        if(abs(C40_p) >= 1.5)
            number = 1;
        elseif(abs(C40_p) >= 0.9 && abs(C40_p) < 1.1)
            number = 2;
        elseif(abs(C40_p) >= 1.1 && abs(C40_p) < 1.3)
            number = 3;
        elseif(abs(C40_p) >= 0.65 && abs(C40_p) < 0.9)
            number = 4;
        elseif(abs(C40_p)<=0.4)
            number = 5;
        elseif(abs(C40_p) > 0.4 && abs(C40_p) < 0.65)
            number = 6;
        end
        if(number == System.BitPerSymbol)
            correct = correct + 1;
        end
    end
    correct_rate(snrIndex) = correct;
 end

figure(j);
if(j == 1)
    plot(snr, correct_rate, 'r.-');
%测试不同数据点时随机模式下的识别正确率,不测时请注释掉
   hold on

elseif(j == 2)
     plot(snr, correct_rate, 'gv-');
elseif(j == 3)
     plot(snr, correct_rate, 'r*-');   
elseif(j == 4)
     plot(snr, correct_rate, 'r.-');
elseif(j == 5)
     plot(snr, correct_rate, 'gv-');
elseif(j == 6)
     plot(snr, correct_rate, 'r*-');
     hold off
end
 
axis([-5 20 0 110]);
xlabel('dB');
ylabel('识别正确率');

%测试不同数据点时随机模式下的识别正确率,不测时请注释掉
legend('N=10000','N=1000','N=100');
title('随机模式识别时不同数据点数量的识别正确率对比')


if(j == 1)
    title('PSK识别正确率');
elseif(j == 2)
    title('QPSK识别正确率');
elseif(j == 3)
    title('8QAM识别正确率');
elseif(j == 4)
    title('16QAM识别正确率');
elseif(j == 5)
    title('32QAM识别正确率');
elseif(j == 6)
    title('64QAM识别正确率');
end



%{
plot(real(Rx.Signal),imag(Rx.Signal),'.');
if(j == 1)
    title('PSK星座图');
elseif(j == 2)
    title('QPSK星座图');
elseif(j == 3)
    title('8QAM星座图');
elseif(j == 4)
    title('16QAM星座图');
elseif(j == 5)
    title('32QAM星座图');
elseif(j == 6)
    title('64QAM星座图');
end
xlabel('实部');
ylabel('虚部');
%}


title('随机模式识别时的识别正确率');%测试随机模式下的识别正确率,不测随机模式时请注释掉

end








你可能感兴趣的:(【MATLAB】)