Skip to main content

MATLAB code for QAM constellation

 

Visit Main Website [Click Here ↗]


MATLAB Script


%%% Code starts here %%%

clc;clear all;close all;

M = 4;  % Number of levels after quantization / size of signal constellation

k = log2(M);  % Number of bits per symbol

rng(1)  %assaining the value of seed integer

N =5000;  % Number of bits to process

dataIn = randi([0 1],1,N);   % Generating randon bits

dataInMatrix = reshape(dataIn,length(dataIn)/k,k); % Reshape data into binary k-tuples, k = log2(M)

dataSymbolsIn = bi2de(dataInMatrix);  % Convert binary to decimal

for n= 1:N/k

    if dataSymbolsIn(n)==0

        QAM(n)= complex(1,1);

    elseif dataSymbolsIn(n)==1

        QAM(n)= complex(-1,1);

    elseif dataSymbolsIn(n)==2

        QAM(n)= complex(1,-1);

    else

        QAM(n)= complex(-1,-1);

    end

  

end

display(dataIn,'First fifty bits');

display(QAM,'first twenty-five4-QAM symbols');


%Transmission of 4QAM data over AWGN channel

snrdB =8;

Y=awgn(QAM,snrdB); %received signal


%Threshold Detection

    for n= 1:N/k

        if (real(Y(n))>0 && imag(Y(n))>0)

            Z(n)=complex(1,1);

    elseif (real(Y(n))>0 && imag(Y(n))<0)

            Z(n)=complex(1,-1);

    elseif (real(Y(n))<0 && imag(Y(n))>0)

            Z(n)=complex(-1,1);

        else

            Z(n)=complex(-1,-1);

        end

    end

sPlotFig = scatterplot(Y,1,0,'g.');

hold on

scatterplot(QAM,1,0,'k*',sPlotFig)

legend('received','transmitted')


%%% Code Ends here %%%

Output



Comments

Popular posts from this blog

MATLAB code for ask fsk and psk

Visit Main Website [Click Here ↗]   MATLAB Script %%% Code starts here %%% clc; clear all; close all; carrier_frequency=5; %Hz carrier_frequency2=7; %Hz This will be utilized for FSK's second carrier x=[1 0 0 1 1 0 0 1] % input signal ; length=size(x,2);   i=1; while i<length+1      t = i:0.001:i+1;     if x(i)==1        ask=sin(2*pi*carrier_frequency*t);        fsk=sin(2*pi*carrier_frequency*t);        psk=sin(2*pi*carrier_frequency*t);     else         ask=0;         fsk=sin(2*pi*carrier_frequency2*t);         psk=sin(2*pi*carrier_frequency*t+pi);     end              subplot(3,1,1);     plot(t,ask);     hold on;     grid on;     axis([1 10 -1 1]);  title('Amplitude Shift Key')     subplot(3,1,2);     plot(t,fs...

SSC Previous Year Question Papers with Solutions - (4)

  Q. The computer program that converts assembly language to machine language is called ............. 1) Complier 2) Interpreter 3) Assembler 4) Comparator Answer: Option 3 Q. In which communication mode, data can be transmitted in both directions at same time? 1) Simplex 2) Full duplex 3) Half duplex 4) Multiplex Answer: Option 2 Next>> <<Previous Go back