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,fsk);     hold on;     grid on;     axis([1 10 -1 1]); title('Frequency Shift Key')       subplot(3,1,3);     plot(t,psk);     hold on;     grid on;     axis([1 10 -1 1]);  title('Phase Shift Key')       i=i+1;  end %%% Code ends here %%% Visi

JS Code to Add a Dropdown Menu to Your Google Blogger

HTML Code < link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /> < div class = "topnav" id = "myTopnav" > < div class = "dropdown" >     < button class = "dropbtn" >< b > Mechanism of wireless communication </ b >       < i class = "fa fa-caret-down" ></ i >     </ button >     < div class = "dropdown-content" > < a href = "https://www.salimwireless.com/2022/05/mechanism-of-wireless-communication.html" >< b > Mechanism of wireless communication - step by step </ b ></ a > < a href = "https://www.salimwireless.com/2021/11/pathloss-in-wireless-communication.html" >< b > Pathloss &amp; Delay spread in Modern Wireless Communication Systems </ b ></ a > < a href = "https://www.salimwireless.com/2