Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
301 views

Qam Matlab Code

The document generates random binary data, converts it to symbols using 16-QAM modulation in both binary and gray coded formats, adds AWGN noise, and demodulates the noisy signal. It then calculates and displays the bit error rates for both binary and gray coded modulation. Additionally, it generates 16-QAM constellations and impulse responses of an RRC filter.

Uploaded by

PragnaShastry
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
301 views

Qam Matlab Code

The document generates random binary data, converts it to symbols using 16-QAM modulation in both binary and gray coded formats, adds AWGN noise, and demodulates the noisy signal. It then calculates and displays the bit error rates for both binary and gray coded modulation. Additionally, it generates 16-QAM constellations and impulse responses of an RRC filter.

Uploaded by

PragnaShastry
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

clear all;

clc

n=30000;
M=16;
k=log2(M);
nsps = 1;
rng default

din = randi([0 1],n,1);

figure(1)
stem(din(1:40),'filled');
title('Random Bits');
xlabel('Bit Index');
ylabel('Binary Value');

dinmat = reshape(din,length(din)/k,k);
dinsym = bi2de(dinmat);

figure(2)
stem(dinsym(1:10));
title('Random Symbols');
xlabel('Symbol Index');
ylabel('Integer Value');

dmod = qammod(dinsym,M,'bin');
dmodg = qammod(dinsym,M,'gray');

ebno = 10;
snr = ebno + 10*log10(k/nsps);

rs = awgn(dmod,snr,'measured');
rsg = awgn(dmodg,snr,'measured');

splotfig = scatterplot(rs,1,0,'g.');
hold on;
scatterplot(dmod,1,0,'k*',splotfig);

demod = qamdemod(rs,M,'bin');
demodg = qamdemod(rsg,M);

doutmat = de2bi(demod,k);
dout = doutmat(:);

doutmatg = de2bi(demodg,k);
doutg = doutmatg(:);

[numerr,ber] = biterr(din,dout);
fprintf('the binary bit error rate is %5.2e ,from %d error\n',ber,numerr);

[numerrg,berg] = biterr(din,doutg);
fprintf('the gray bit error rate is %5.2e ,from %d error\n',berg,numerrg);

m=16;
x=(0:15)';
y1 = qammod(x,m,'bin');
scatterplot(y1)
text(real(y1)+0.1, imag(y1), dec2bin(x))
title('16 qam binary distribution');
axis([-4 4 -4 4])

y2 = qammod(x,16,'gray');
scatterplot(y2)
text(real(y2)+0.1, imag(y2), dec2bin(x));
title('16 qam gray distribution');
axis([-4 4 -4 4])

rolloff = 0.25;
span = 10;
nsps = 4;

rcfilter = rcosdesign(rolloff,span,nsps);

fvtool(rcfilter,'Analysis','Impulse');

M = 16;
k = log2(M);
numbits = 3e5;

rng default;
datain = randi([0 1],numbits,1);

datainmat = reshape(datain,length(datain)/k,k);
datasym = bi2de(datainmat);

datamod = qammod(datasym,M);

txsignal = upfirdn(datamod,rcfilter,nsps,1);

eyediagram(txsignal(1:2000),nsps*2);

You might also like