Fitsum
Fitsum
Fitsum
clc
clear all
close all
N = 750; %simulation length
M = 5; %channel length
T = 20; %number of independent trials
cir = zeros(1,2*M-1); %cascade impulse response
MSE_vec = zeros(T,N-3); %Mean Square Error vector
MSE_f=zeros(1,N-3); %final MSE vector
o_p=zeros(1,N); %output from the equalizer in Tth trial
for j = 1 : T
u = sign(randn(1,N)); %input signal
c = randn(M,1); %channel to be equalized
c = c / norm(c);
z = filter(c,1,u); %channel output
SNR = 30; %Signal to Noise Ratio
var_v = var(z) * 10^(-SNR/10); %additive noise to the channel output
v = var_v^0.5 * randn(1,N);
y = z + v; %input to the equalizer
%-----------------------------LMS channel equalization-----------------------
%
w = zeros(M,1);
y_d = zeros(1,M);
step =.12;
MSE=0;
for k = 4 : N
y_d = [y(k) y_d(1:M-1)];
e = u(k-3) - y_d * w;
w = w + step * y_d' * e ;
if j==T
o_p(1,k)=y_d * w;
end
MSE=MSE+(abs(e).^2);
MSE_avg=MSE/(k-3);
MSE_vec(j,:)=[MSE_avg MSE_vec(j,1:N-4)];%mse is calculated row wise,
%MSE_vec(j,1:N-4)(j=row no,elements
%are from 1st to N-4
end
MSE_vec(j,:)=fliplr(MSE_vec(j,:));%rows are inverted from left to right
q=[4:1:N];
figure(2);
plot(q,MSE_vec(j,:));
title('mean square error for different trial');
xlabel('No of iterations ');
ylabel('MSE');
hold on;
cir = cir + conv(w,c)';
end
hold off
figure(1);
subplot(2,1,1);
plot(q,MSE_vec(j,:));
title('MSE in Tth trial');
xlabel('No of iterations');
ylabel('MSE');
hold on;
o_p_b=sign(o_p); %converting to binary(+1/-1)
n=[1:N];
plot(n,v); %noise in the final trial
hold off;
temp=ones(T,1);
for j=1:N-3
MSE_f(1,j)=MSE_f(1,j)+((MSE_vec(:,j)'*temp)/T);
end
subplot(2,1,2);
plot(q,MSE_f);
title('MSE in final trial');
xlabel('No of iterations');
ylabel('MSE');
%-----------------------FOR SIGNALS IN FINAL TRIAL-------------------------%
figure(3);
subplot(3,1,1);
plot(c);
title('channel impulse response');
xlabel('time');
ylabel('magnitude');
subplot(3,1,2);
plot(w);
title('equalizer impulse response');
xlabel('time');
ylabel('magnitude');
subplot(3,1,3);
stem(cir/T);
title('cascade channel-equalizer impulse response');
ylabel('magnitude');
xlabel('taps');
figure(4);
subplot(2,2,1);
n_i=n(4:N);
stem(n_i,u(1:N-3));
xlabel('time');
title('input signal');
ylabel('magnitude');
subplot(2,2,2);
stem(n,z);
xlabel('time');
title('output after passing through channel');
ylabel('magnitude');
subplot(2,2,3);
n_o=n(1:N-3);
stem(n_o,o_p(1:N-3));
xlabel('time');
title('Final output');
ylabel('magnitude');
subplot(2,2,4);
stem(n_o,o_p_b(1:N-3));
xlabel('time');
title('Binary final output');
ylabel('magnitude');
16-QAM
% symbol error rate for 16-QAM modulation
clear
N = 2*10^5; % number of symbols
alpha16qam = [-3 -1 1 3]; % 16-QAM alphabets
Es_N0_dB = [0:20]; % multiple Es/N0 values
ipHat = zeros(1,N);
for ii = 1:length(Es_N0_dB)
ip = randsrc(1,N,alpha16qam) + j*randsrc(1,N,alpha16qam);
s = (1/sqrt(10))*ip; % normalization of energy to 1
n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % white guassian noise, 0dB
variance
% demodulation
y_re = real(y); % real part
y_im = imag(y); % imaginary part
simBer = nErr/N;
theoryBer = 3/2*erfc(sqrt(0.1*(10.^(Es_N0_dB/10))));
close all
figure
semilogy(Es_N0_dB,theoryBer,'b.-','LineWidth',2);
hold on
semilogy(Es_N0_dB,simBer,'mx-','Linewidth',2);
axis([0 20 10^-5 1])
grid on
legend('theory', 'simulation');
xlabel('Es/No, dB')
ylabel('Symbol Error Rate')
title('Symbol error probability curve for 16-QAM modulation')
OFDM
clear all
nFFT = 64; % fft size
nDSC = 52; % number of data subcarriers
nBitPerSym = 52; % number of bits per OFDM symbol (same as the number of
subcarriers for BPSK)
nSym = 10^4; % number of symbols
EbN0dB = [0:10]; % bit to noise ratio
EsN0dB = EbN0dB + 10*log10(nDSC/nFFT) + 10*log10(64/80); % converting to
symbol to noise ratio
for ii = 1:length(EbN0dB)
% Transmitter
ipBit = rand(1,nBitPerSym*nSym) > 0.5; % random 1's and 0's
ipMod = 2*ipBit-1; % BPSK modulation 0 --> -1, 1 --> +1
ipMod = reshape(ipMod,nBitPerSym,nSym).'; % grouping into multiple
symbolsa
% Assigning modulated symbols to subcarriers from [-26 to -1, +1 to +26]
xF = [zeros(nSym,6) ipMod(:,[1:nBitPerSym/2]) zeros(nSym,1)
ipMod(:,[nBitPerSym/2+1:nBitPerSym]) zeros(nSym,5)] ;
% Taking FFT, the term (nFFT/sqrt(nDSC)) is for normalizing the power of
transmit symbol to 1
xt = (nFFT/sqrt(nDSC))*ifft(fftshift(xF.')).';
% Appending cylic prefix
xt = [xt(:,[49:64]) xt]; % Concatenating multiple symbols to form a long
vector
xt = reshape(xt.',1,nSym*80);
% Gaussian noise of unit variance, 0 mean
nt = 1/sqrt(2)*[randn(1,nSym*80) + j*randn(1,nSym*80)];
% Adding noise, the term sqrt(80/64) is to account for the wasted energy
due to cyclic prefix
yt = sqrt(80/64)*xt + 10^(-EsN0dB(ii)/20)*nt;
% Receiver
yt = reshape(yt.',80,nSym).'; % formatting the received vector into
symbols
yt = yt(:,[17:80]); % removing cyclic prefix
% converting to frequency domain
yF = (sqrt(nDSC)/nFFT)*fftshift(fft(yt.')).';
yMod = yF(:,[6+[1:nBitPerSym/2] 7+[nBitPerSym/2+1:nBitPerSym] ]);
% BPSK demodulation +ve value --> 1, -ve value --> -1
ipModHat = 2*floor(real(yMod/2)) + 1;
ipModHat(find(ipModHat>1)) = +1;
ipModHat(find(ipModHat<-1)) = -1;
% converting modulated values into bits
ipBitHat = (ipModHat+1)/2;
ipBitHat = reshape(ipBitHat.',nBitPerSym*nSym,1).';
nErr(ii) = size(find(ipBitHat - ipBit),2); % counting the errors
end
simBer = nErr/(nSym*nBitPerSym);
theoryBer = (1/2)*erfc(sqrt(10.^(EbN0dB/10)));
close all; figure
semilogy(EbN0dB,theoryBer,'bs-','LineWidth',2);
hold on
semilogy(EbN0dB,simBer,'mx-','LineWidth',2);
axis([0 10 10^-5 1])
grid on
legend('theory', 'simulation');
xlabel('Eb/No, dB')
ylabel('Bit Error Rate')
title('Bit error probability curve for BPSK using OFDM')
Cyclic Coding