**MATLAB CODE:**

clc;

clear all;

close all;

N = 10^5; % number of symbols

%modulation with noise————————————————————————————-

pam4 = [-3 -1 1 3]; % order of PAM. Here, its 4th order or 4-PAM alphabets

Es_N0_dB = [-3:20]; % multiple Eb/N0 values

ip = randsrc(1,N,pam4);

for v = 1:length(Es_N0_dB)

s = (1/sqrt(5))*ip; % normalization of energy to 1

n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % white guassian noise, 0dB variance

b=10^(-Es_N0_dB(v)/20);

y = s + b*n; % additive white gaussian noise

% demodulation—————————————————————————————————–

r = real(y); % taking only the real part

i(find(r< -2/sqrt(5))) = -3;

i(find(r>= 2/sqrt(5))) = 3;

i(find(r>=-2/sqrt(5) & r<0)) = -1;

i(find(r>=0 & r<2/sqrt(5))) = 1;

nErr(v) = size(find([ip- i]),2); % couting the number of errors

end

%error count————————————————————————————–

simBer = nErr/N;

theoryBer = 0.75*erfc(sqrt(0.2*(10.^(Es_N0_dB/10)))); %theoritical BER

close all;

%plotting———————————————————————————————-

figure

semilogy(Es_N0_dB,theoryBer,’b.-‘);

hold on

semilogy(Es_N0_dB,simBer,’mx-‘);

axis([-3 20 10^-5 1])

grid on;

legend(‘theory’, ‘simulation’);

xlabel(‘Es/No, dB’);

ylabel(‘Symbol Error Rate’);

title(‘Symbol error probability curve for 4-PAM modulation’);

**RESULT:**

### Like this:

Like Loading...

*Related*

## Leave a Reply