Documente Academic
Documente Profesional
Documente Cultură
EE14RESCH11005
DSP lab:MATLAB CODES AND OUTPUTS
1. BPSK_modulation
Code:
clc;close all;clear all;
%assuming Number of bits to be sent
N=10^6;
%data in 1s and 0s
data=rand(1,N)>0.5;
%modulating the data
bpsk=2*data-1;
%assuming snr
SNR=0:10;
for i=1:length(SNR)
%calculating sigma;
sigma=(10.^(-SNR(i)/20));%with asumption of Eb=1;
noise=sigma*randn(1,N);
%noise addition awgn
bpsk_rx=bpsk+noise;
h=randn(1,N)+1i*randn(1,N);
h=h/sqrt(2);
bpsk_rx_ch=bpsk.*h+noise;
%demodulation
for j=1:N
if bpsk_rx(j)>0
bpsk_est(j)=1;
else
bpsk_est(j)=-1;
end
end
bpsk_rx_ch=bpsk_rx_ch./h;
for j=1:N
if bpsk_rx_ch(j)>0
bpsk_est_ch(j)=1;
else
bpsk_est_ch(j)=-1;
end
end
%errors
errors=bpsk-bpsk_est;
errors_ch=bpsk-bpsk_est_ch;
ber(i)=length(find(abs(errors)))/length(data);
ber_ch(i)=length(find(abs(errors_ch)))/length(data);
i
end
SNR_L=10.^(SNR/10);
semilogy(SNR,qfunc(sqrt(SNR_L)),'b');
hold on
semilogy(SNR,ber,'r*');
legend('theoretical awgn','simulated bpsk w/o channel')
axis([1 10,10^-4 1]);
figure;
semilogy(SNR,ber_ch,'r*');
hold on;
semilogy(SNR,0.5*(1-sqrt(SNR_L./(SNR_L+1))),'b');
% axis([1 10,10^-3 10^-1]);
legend('theoretical awgn','simulated bpsk with channel')
Simulated for awgn channel and compared with theoretical equation Q(sqrt(SNR));
Simulated for flat fading channel and compared with Rayleigh equation for single
tap 0.5(1-sqrt(SNR/SNR+1))
Outputs:
Simulated graph for QPSK without channel awgn and theoretical comparision of
qpsk(sqrt(SNR));
Simulated graph for QPSK with channel flat fading and theoretical comparisision of
Rayleigh flat fading equation 0.5(1-sqrt(snr/snr+2))
qpsk_demod=QPSK_DEMOD(serial_tx);
qpsk_demod_n=QPSK_DEMOD(serial_tx_n);
errors=qpsk_demod(1:N)-data;
%errors
errors_n=qpsk_demod_n(1:N)-data;
ber(SNR)=length(find(abs(errors)))./length(data);
ber_n(SNR)=length(find(abs(errors_n)))./length(data);
SNR
end
SNR=1:10;
semilogy(ber,'r');
hold on;
SNR_L=10.^(SNR/10);
semilogy(0.5*(1-sqrt(SNR_L./(2+SNR_L))),'k*');
semilogy(qfunc(sqrt(SNR_L)),'g*');
semilogy(ber_n,'m');
legend('simulated ofdm qpsk Rayleigh','Theoretical ofdm qpsk
rayleigh','theoretical ofdm qpsk w/o channel','simulated ofdm qpsk w/o
channel');
H=H_cp(i,:);
%parallel conversion
parallel_rx_n=[data_tx_n((i-1)*(N_car)+1:i*N_car)];
parallel_rx_cp=[data_tx_cp((i-1)*(N_car+N_taps-1)+1:i*(N_car+N_taps1))];
parallel_rx_cp=parallel_rx_cp(N_taps:end);
%channel equalising ofdm demodulation
parallel_out_n=fft(ifft(fft(parallel_rx_n)./fft(H,length(parallel_rx_n))))./
(sqrt(N_car));
serial_tx_n=[serial_tx_n parallel_out_n];
parallel_out_cp=fft(ifft(fft(parallel_rx_cp)./fft(H,length(parallel_rx_cp))))./
(sqrt(N_car));
serial_tx_cp=[serial_tx_cp parallel_out_cp];
end
%qpsk demodulation
qpsk_demod_cp=QPSK_DEMOD(serial_tx_cp);
qpsk_demod_n=QPSK_DEMOD(serial_tx_n);
%errors
errors_n=qpsk_demod_n(1:N)-data;
errors_cp=qpsk_demod_cp(1:N)-data;
ber_n(SNR)=length(find(abs(errors_n)))./length(data);
ber_cp(SNR)=length(find(abs(errors_cp)))./length(data);
SNR
end
SNR=1:10;
% semilogy(ber,'r*');
% hold on;
SNR_L=10.^(SNR/10);
semilogy(0.5*(1-sqrt(SNR_L./(2+SNR_L))),'k*');
hold on;
semilogy(ber_n,'m');
semilogy(ber_cp,'r')
legend('theoretical ofdm qpsk Rayleigh_flat fading','simulated ofdm qpsk
with multipathchannel ','simulated ofdm qpsk with multipath channel with
cp');
Outputs:
OFDM without cp and flat fading comparision:
QPSK DEMODULATION:
function out=QPSK_DEMOD(data)
for i=1:length(data)
if real(data(i))>0
if imag(data(i))>0
out(2*i-1:2*i)=[1 1];
else
out(2*i-1:2*i)=[1 0];
end
else
if imag(data(i))<0
out(2*i-1:2*i)=[0 0];
else
out(2*i-1:2*i)=[0 1];
end
end
end
end