0% found this document useful (0 votes)
137 views67 pages

Umesh Sinha Communication System Lab

This document contains code to generate and analyze various types of modulated signals in communication systems. It includes code to: 1) Generate AM modulated and demodulated signals for critical (modulation index of 1) and over modulation (index of 1.5). 2) Generate a VSB modulated signal for a message signal of 50Hz and carrier of 500Hz. 3) Compare the modulated signals for DSB-SC, AM, SSB, and VSB for message signals of 50Hz and 100Hz. 4) Generate the message signal from an FM modulated signal using a 10Hz message and 200Hz carrier. 5) Generate the message signal from a PM modulated signal using

Uploaded by

Abhay Sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views67 pages

Umesh Sinha Communication System Lab

This document contains code to generate and analyze various types of modulated signals in communication systems. It includes code to: 1) Generate AM modulated and demodulated signals for critical (modulation index of 1) and over modulation (index of 1.5). 2) Generate a VSB modulated signal for a message signal of 50Hz and carrier of 500Hz. 3) Compare the modulated signals for DSB-SC, AM, SSB, and VSB for message signals of 50Hz and 100Hz. 4) Generate the message signal from an FM modulated signal using a 10Hz message and 200Hz carrier. 5) Generate the message signal from a PM modulated signal using

Uploaded by

Abhay Sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 67

Communication System Lab 1

211010252
Umesh sinha
Branch : electronics and communication

Q1. Generate continuous step signals of duration 0 to 10 sec ?

clc;
close
all;
% continous time form 0s to
10s t = (0:10);
% continous signal y = 1 for
0<=t<=10 y = 1 + 0*t;
% plotting y vs
t plot(t,y);
% plot
properties
xlim([-1,11]);
ylim([0,1.5]);
xlabel("Time");
ylabel("Amplitude");
title("Unit Step
Signal");
(2) Generate triangular signals of duration -5 to +5 sec of
unit peak amplitude.
clc;
close
all;
t1 = (-5:0.1:0);
t2 = (0:0.1:5);
% y = mx + c
% y = (1/5)t + 1 for -5<=t<=0
% y = -(1/5)t + 1 for
0<=t<=5 y1 = 0.2*t1 + 1;
y2 = -t2*0.2 + 1;
% t = [-5,0] U
[0,5] t = [t1,t2];
% y = y1 U
y2 y =
[y1,y2];
plot(t,y);
% plot
properties
ylim([0,1.5]);
xlim([-6,6]);
xlabel("Time");
ylabel("Amplitude");
title("Triangular signal with peak of
1"); OUTPUT
(3) Generate rectangular pulse of duration -3 to +6 sec of
unit magnitude using step signals.
CODE :
clc;
close
all;
t=-3:0.001:6;
y=ones(1,9001);
plot(t,y); hold on;
stem(-3,1,'color',[0 0.3 0.8]); hold on;
stem(6,1,'color',[0 0.3 0.8]);
% plot properties
ylim([0,1.5]); xlim([-5,8]);
xlabel("Time");
ylabel("Amplitude");
title("Rectangular
Signal"); OUTPUT

(4) Plot cosine signal multiplied with exponentially


decay signal.
CODE :
clc;
close
all;
% time 0<=t<=5
t = (0:0.025:5);
% y = cos(2πt).e^(-t) =
cos(2πt)/e^(t) y = cos(2*pi*t) .*
exp(-t); plot(t,y);
% plot
properties
xlim([-1,6]);
ylim([-1,1.5]);
xlabel("Time");
ylabel("Amplitude");
ch = sym('e t');
title("Signal y =
cos(t)/e^t") OUTPUT

(5) Plot convolution of step signal with ramp signal


of duration 10 sec.
CODE :
clc;
t = (0:1:9);
% y1 = unit step
signal y1 =
ones(1,10);
% y2 = ramp
signal y2 = t;
% y = convolution of y1 and
y2 y = conv(y1,y2);
% plot
figure;
subplot(3,1,1)
plot(y1);
title("Unit Step
Signal"); subplot(3,1,2);
plot(y2);
title("Ramp
Signal");
subplot(3,1,3)
plot(y);
xlim([0,20]);
ylim([0,50]);
title("Convolution of Unit Step And Ramp
Signal") OUTPUT

COMMUNICATION SYSTEM LAB2


1. Generate modulated and demodulated plots
of AM with modulation index
(kaAm) of 1 (Critical Modulated) and 1.5 (Over
Modulated).

clc;
fs=10000; % sampling frequency = 10kHz
fm=20; % message signal frequency = 20Hz
fc=500; % carrier signal frequency = 0.5Khz
Am=1; % message signal amplitude = 1
Ac=1; % carrier signal
t=(0:0.2*fs)/fs; m=Am*cos(2*pi*fm*t);
% message signal c=Ac*cos(2*pi*fc*t);
% carrier signal
ka=1; % amplitude sensitivity of modulator
u=ka*Am; % modulation index
s1=Ac*(1+u*cos(2*pi*fm*t)).*cos(2*pi*fc*t); % modulated signal
subplot(4,1,1);
plot(t,m);
title('Modulating or Message signal(fm=20Hz)');
xlabel("Time");
ylabel("Amplitude");
subplot(4,1,2);
plot(t,c);
xlabel("Time");
ylabel("Amplitude");
title('Carrier signal(fc=500Hz)');
subplot(4,1,3);
plot(t,s1);
xlabel("Time");
ylabel("Amplitude");
title('Critical Modulated signal(ka.Am=1)');
% demodulating the received signal
r1= s1.*c;
[b, a] = butter(2,0.01,'low');
mr1= filter(b,a,r1);
mr1a=sqrt(mr1.*mr1); % demodulated signal
subplot(4,1,4);
plot(t,mr1a);
xlabel("Time");
ylabel("Amplitude");
title('Demodulated Signal(ka.Am=1)');

FOR OVERMODULATED SIGNAL

% 1.5 (Over Modulated)


clc;
fs=10000; % sampling frequency = 10kHz
fm=20; % message signal frequency = 20Hz
fc=500; % carrier signal frequency = 0.5Khz
Am=1; % message signal amplitude = 1
Ac=1; % carrier signal
t=(0:0.2*fs)/fs; m=Am*cos(2*pi*fm*t);
% message signal c=Ac*cos(2*pi*fc*t);
% carrier signal
ka=1.5; % amplitude sensitivity of modulator
u=ka*Am; % modulation index
s1=Ac*(1+u*cos(2*pi*fm*t)).*cos(2*pi*fc*t); % modulated signal
subplot(4,1,1);
plot(t,m);
title('Modulating or Message signal(fm=20Hz)');
xlabel("Time");
ylabel("Amplitude");
subplot(4,1,2);
plot(t,c);
xlabel("Time");
ylabel("Amplitude");
title('Carrier signal(fc=500Hz)');
subplot(4,1,3);
plot(t,s1);
xlabel("Time");
ylabel("Amplitude");
title('Over Modulated signal(ka.Am=1.5)');
% demodulating the received signal
r1= s1.*c;
[b, a] = butter(2,0.01,'low');
mr1= filter(b,a,r1);
mr1a=sqrt(mr1.*mr1); % demodulated signal
subplot(4,1,4);
plot(t,mr1a);
xlabel("Time");
ylabel("Amplitude");
title('Demodulated Signal(ka.Am=1.5)');

2. Generate demodulated signal for DSBSC.


clc;
fs=8000;
fm=20;
fc=500;
Am=1;
Ac=1;
t=(0:0.2*fs)/fs;
m=Am*cos(2*pi*fm*t);
c=Ac*cos(2*pi*fc*t);
subplot(4,1,1);
plot(t,m);
xlabel("Time");
ylabel("Amplitude");
title('Original Signal');
s2=Ac*Am*cos(2*pi*fm*t).*cos(2*pi*fc*t);
subplot(4,1,2);
plot(t,s2);
xlabel("Time"); ylabel("Amplitude");
title('DSBSC Modulated Signal');
% multpling modulated signal with carrier having same frequency and phase.
ModProduct = c.*s2;
subplot(4,1,3);
plot(t,ModProduct);
xlabel("Time");
ylabel("Amplitude");
title('Multpling modulated signal with carrier having same frequency and
phase.');
%filter design
[bb,aa] = butter(2,0.01,'low');
sqrObt = 2.*filter(bb,aa,ModProduct);
% multipling 2 because obtained signal is (Ac^2/2)*cos(phi)*m(t) Obtsgn =
sqrt(sqrObt.*sqrObt);
subplot(4,1,4);
plot(t,sqrObt);
xlabel("Time");
ylabel("Amplitude");
title('Demodulating and getting back Original Signal');
Lab 3 Assignment Solution Report

1. Generate modulated and demodulated plots of USB SSB


for two added message signals of unit magnitude and
frequencies of 50 Hz and 100 Hz (where fc=500 Hz)
clc;
fs = 8000;
t=(0:0.2*fs)/fs;
fm1=50; fm2=100;
msignal1= sin(2*pi*fm1*t);
msignal2= sin(2*pi*fm2*t);
m = msignal2+msignal1;
subplot(4,1,1);
plot(t,m);
title("Message Signal with m1+m2 (sine waves with freq 50 & 100 Hz)");
xlabel("Time"); ylabel("Amplitude");
initialPhase = 0;
fc = 500;
carr = cos(2*pi*fc*t);
subplot(4,1,2);
plot(t,carr);
title("carrier with frequency 500Hz");
xlabel("Time");
ylabel("Amplitude");
upperSidebandSignal=ssbmod(m,fc,fs,initialPhase,'upper');
subplot(4,1,3);
plot(t,upperSidebandSignal);
title("USB SSB Modulated Signal");
xlabel("Time"); ylabel("Amplitude");
demodsignal=ssbdemod(upperSidebandSignal,fc,fs);
subplot(4,1,4);
plot(t,demodsignal);
title("Demodulated Signal");
xlabel("Time");
ylabel("Amplitude");

2. Generate VSB modulated signal for message signal


of frequency 50 Hz with carrier signal of frequency 500
Hz.
clc;
fs = 4000;
t=(0:0.1*fs)/fs;
fm=50; % frequency of the message signal
signal=sin(2*pi*fm*t); % Message signal
fc = 500;
initialPhase = 0;
subplot(3,1,1);
plot(t,signal);
title("Message Signal with fm=50 HZ");
xlabel("Time");
ylabel("Amplitude");
c=cos(2*pi*fc*t); % carrier signal
subplot(3,1,2);
plot(t,c);
title("Carrier Signal with fc=500 HZ");
xlabel("Time");
ylabel("Amplitude");
product=signal.*c; % DSB-SC Signal
ld=length(product);
f=linspace(-fs/2,fs/2,ld);
DSB_SC=fftshift(fft(product,ld)/ld); % DSB-SC in frequency domain
lf=fc-(0.25*fm);
uf=fc+fm;
filtered_signal=bandpass(DSB_SC, [lf uf], fs);
vsbModSignal=ifft(filtered_signal);
subplot(3,1,3);
plot(t,filtered_signal);
title("VSB-SC Modulated Signal");
xlabel("Time");
ylabel("Amplitude");
3. Compare DSB-SC, AM, SSB and VSB in a single figure for
the inputs given in Task 1.
CODE :
clc;
fs = 4000;
t=(0:0.1*fs)/fs;
fm1=100; % frequency of first message signal
fm2=50; % frequency of second message signal
signal1 = sin(2*pi*fm1*t); % Message signal 1
signal2 = sin(2*pi*fm2*t); % Message signal 2
result_signal = signal1+signal2;
fc = 500;
initialPhase = 0;
subplot(3,2,1);
plot(t,result_signal);
title("Message Signal 50Hz+100Hz");
xlabel("Time");
ylabel("Amplitude");
c=cos(2*pi*fc*t); % carrier signal
subplot(3,2,2);
plot(t,c);
title("Carrier Signal with fc=500 HZ");
xlabel("Time");
ylabel("Amplitude");
% DSB-SC Modulation
dsbsc = result_signal.*c;
subplot(3,2,3);
plot(t,dsbsc);
title("DSB-SC Modulated Signal");
xlabel("Time");
ylabel("Amplitude");
% AM Modulation
mi=1; % Modulation index
am=c.*(1+(mi*result_signal));
subplot(3,2,4);
plot(t,am);
title("AM Modulated Signal");
xlabel("Time");
ylabel("Amplitude");
% USBSSB-SC Modulation
upperSidebandSignal=ssbmod(result_signal,fc,fs,initialPhase,'upper');
subplot(3,2,5);
plot(t,upperSidebandSignal);
title("USB SSB Modulated Signal");
xlabel("Time");
ylabel("Amplitude");
% VSB-SC Modulation
ld=length(dsbsc);
f=linspace(-fs/2,fs/2,ld);
DSB_SC=fftshift(fft(dsbsc,ld)/ld); % DSB-SC in frequency domain
% bandpass Filter Frequencies
lf=fc-(0.25*fm);
uf=fc+fm;
filtered_signal=bandpass(DSB_SC, [lf uf], fs);
%vsbModSignal=ifft(filtered_signal);
subplot(3,2,6);
plot(t,filtered_signal);
title("VSB-SC Modulated Signal");
xlabel("Time");
ylabel("Amplitude");
Lab 4 communication System
211010252

1. Generate the message signal from the FM modulated signal.

clc;
clear;
fs = 8000;
fm=10;
fc = 200;
t=(0:0.2*fs)/fs;
Am = 1;
Ac = 1;
kf = 2;
% message signal
m = Am*cos(2*pi*fm*t);
subplot(4,1,1);
plot(t,m);
title('Message Input Signal');
xlabel('Time');
ylabel('Amplitude')
% carrier signal
c = Ac*cos(2*pi*fc*t); subplot(4,1,2);
plot(t,c); title('Carrier Signal'); xlabel('Time'); ylabel('Amplitude');
% FM signal n=cumsum(m)/max(cumsum(m));
s_fm = Ac*cos(2*pi*fc*t+2*pi*kf*n); subplot(4,1,3);
plot(t,s_fm);
title('Frequency Modulated Signal'); xlabel('Time');
ylabel('Amplitude')
% Demodulated FM signal
demod = fmdemod(s_fm, fc, 8000, max(cumsum(m))); subplot(4,1,4);
plot(t,demod); title('Demodulated FM Signal'); xlabel('Time'); ylabel('Amplitude');
2. Generate the message signal from the PM modulated signal.

clc;
fs = 8000;
fm=10;
fc = 200;
t=(0:0.2*fs)/fs;
Am = 1;
Ac = 1;
kp = 2;
% message signal
m = Am*cos(2*pi*fm*t);
subplot(4,1,1);
plot(t,m);
title('Message Signal');
xlabel('Time');
ylabel('Amplitude')
% carrier signal
c = Ac*cos(2*pi*fc*t); subplot(4,1,2);
plot(t,c); title('Carrier Signal'); xlabel('Time'); ylabel('Amplitude');
% PM signal
s_pm = Ac*cos(2*pi*fc*t+m.*kp ); subplot(4,1,3);
plot(t,s_pm);
title('Phase Modulated Signal'); xlabel('Time'); ylabel('Amplitude')
% Demodulated PM signal
demod = pmdemod(s_pm, fc, fs, kp*Am); subplot(4,1,4);
plot(t,demod); title('Demodulated PM Signal'); xlabel('Time'); ylabel('Amplitude');
3. Add the Noise in the channel, and then performed the demodulation in case of FM and PM.
clc;
clear;
fs = 8000;
fm = 10;
fc = 200;
t=(0:0.2*fs)/fs;
Am = 1;
Ac = 1;
kf = 100
kp =10
Wm =2*pi*fm;
m = Am*cos(Wm*t);
subplot(3,2,1);
plot(t,m);
title('Message Input Signal');
xlabel('Time --->');
ylabel('Amplitude --->')
Wc= 2*pi*fc;
c = Ac*cos(Wc*t);
subplot(3,2,2);
plot(t,c);
title('Carrier Signal');
xlabel('Time --->');
ylabel('Amplitude --->');
nMean = 0 ;
nSigma = 0.1 ;
n = nMean + nSigma*randn(size(t));
% Frequency Modulation
s_fm = Ac*cos(Wc*t+((2*pi*kf*Am)/Wm)*sin(Wm*t)) + n;
subplot(3,2,3);
plot(t,s_fm);
title('Frequency Modulated Signal With Noise');
xlabel('Time --->');
ylabel('Amplitude --->');
% Frequency Demodulation ;
s = Ac*(Wc +2*pi*kf*Am*cos(Wm*t)).*sin(Wc*t+((2*pi*kf*Am)/Wm)*sin(Wm*t)) +
n;
x = abs(hilbert(s));
y = x/(2*pi*kf) - 2 + n;
subplot(3,2,4) ;
plot(t,y + 0.4) ;
title('Frequency Demodulated Signal');
xlabel('Time --->');
ylabel('Amplitude --->');
% Phase Modulation
s_pm = Ac*cos(Wc*t+kp*Am.*cos(Wm*t)) + n;
subplot(3,2,5);
plot(t,s_pm);
title('Phase Modulated Signal With Noise');
xlabel('Time --->');
ylabel('Amplitude --->');
% Phase Demodulation
x = hilbert(s_pm);
z = unwrap(angle(x));
y = z - 2*pi*fc*t;
subplot(3,2,6) ;
plot(t,y/kp + 1.25 + n) ;
ylim([-1 1]) ;
title('Phase Demodulated Signal');
xlabel('Time --->');
ylabel('Amplitude --->');

LAB 5 Communication System

1. Generate Sampled signal for a unit amplitude sinusoidal signal of frequency


20 Hz sampled with 10 times of Nyquist rate and quantize with 6 quantization
levels.
clc;
close all;
L=6;

n=400;
% Sampling Operation
x=0:2*pi/n:0.5*pi; % n1 number of samples have to be selected
Am=1;
s=Am*sin(20*x);
subplot(3,1,1);
plot(s);grid on;
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(3,1,2);
stem(s);grid on; title('Sampled Signal'); ylabel('Amplitude--->');
xlabel('Time--->');

% Quantization Process
vmax=Am;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax with difference of
del
code=vmin-(del/2):del:vmax+(del/2); % Contaion Quantized values
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value in between the levels
q(i)=vmin+(del/2);

end
end
subplot(3,1,3);
stem(q);grid on; % Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

Output:

2. Reconstruct the Original signal from the above output.


clc;
close all;
L = 6;
n = 400;
% Sampling Operation
x=0:2*pi/n:0.5*pi; % n1 number of samples have to be selected
Am = 1;
s=Am*sin(20 * x);
subplot(3,1,1);
plot(s);grid on;
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Quantization Process
vmax=Am;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax with difference of
del
code=vmin-(del/2):del:vmax+(del/2); % Contaion Quantized values
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value in between the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,2);
stem(q);
grid on; % Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
y = lowpass(q,16000,1/400);
subplot(3,1,3);
plot(y);
grid on; % Display the Quantize values
title('Reconstructed Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

Output:

3. Show the digital data using Encoding for above sampled and quantized
output for one cycle duration.

clc;
close all;
L=6;
n=400;
% Sampling Operation
x=0:2*pi/n:0.5*pi; % n1 number of samples have to be selected
Am = 1;
s=Am*sin(20 * x);
% Quantization Process
vmax=Am;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax with difference of
del
code=vmin-(del/2):del:vmax+(del/2); % Contaion Quantized values
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value in between the levels
q(i)=vmin+(del/2);
end
end
%encoding
quant=max(q)/(2^3-1);
y=round(q/quant);
signe=uint8((sign(y)+1)/2);
out = dec2bin(abs(y)); % The first bit represents the sign of the number

Output :
LAB 6 communication System
Q1.Generate the ASK modulated signal for the
binary data [1 0 1 0 0 1 0 1 0
0] and demodulate.

clc; clear
all; close
all;
%GENERATE CARRIER SIGNAL
Tb=1; fc=10;
t=0:Tb/100:1;
c=sqrt(2/Tb)*sin(2*pi*fc*t);
%generatemessage signal
N=10;
m=[1 0 1 0 0 1 0 1 0 0];
t1=0;
t2=Tb for
i=1:N
t=[t1:.01:t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
else
m(i)=0;
m_s=zeros(1,length(t));
end
message(i,:)=m_s;
%product of carrier andmessage
ask_sig(i,:)=c.*m_s; t1=t1+
(Tb+.01); t2=t2+(Tb+.01);
%plot the messageand ASK signal
subplot(5,1,2);axis([0 N -2 2]);plot(t,message(i,:),'r');
title('message signal');xlabel('t--->');ylabel('m(t)');grid on
hold on
subplot(5,1,4);plot(t,ask_sig(i,:));
title('ASK signal');xlabel('t--->');ylabel('s(t)');grid on
hold on
end hold
off
%Plot the carrier signal and input binarydata
subplot(5,1,3);plot(t,c);
title('carrier signal');xlabel('t--->');ylabel('c(t)');grid on
subplot(5,1,1);stem(m);
title('binary data bits');xlabel('n--->');ylabel('b(n)');grid on
2
% ASK Demodulation
t1=0;t2=Tb
for i=1:N
t=[t1:Tb/100:t2]
%correlator
x=sum(c.*ask_sig(i,:));
%decision device
if x>0
demod(i)=1; else
demod(i)=0;
end t1=t1+
(Tb+.01);
t2=t2+(Tb+.01);
end
%plot demodulated binarydata bits
subplot(5,1,5);stem(demod);
title('ASK demodulated signal'); xlabel('n--->');ylabel('b(n)');
grid on;
2. Add the noise then perform the demodulation
and compute the BER, eye
pattern and I-Q characteristics.
clc; close
all;
num_bit=10; %number of bit
data=[1, 0, 1, 0, 0, 1, 0, 1, 0, 0]; %random bit generation (1 or 0)
SNRdB=0:10; % SNR in dB
SNR=10.^(SNRdB/10);
for k = 1:length(SNRdB); %BER (error/bit) calculation for different SNR%
y=awgn(complex(data),SNRdB(k));
error=0;
R = 0;
M = [];
for c = 1:1:num_bit
if (y(c) > .5 && data(c) == 0) || (y(c) < .5 && data(c) == 1)
%logicaccording to BASK
error = error+1;
M = [M ~data(c)];
else
M = [M data(c)];
end
end
error = error / num_bit; %Calculate error/bit
M(k) = error;
end
semilogy(SNRdB,M,'o','linewidth',2.5),grid on,hold on;
BER_th=(1/2)*erfc(.5*sqrt(SNR));
semilogy(SNRdB,BER_th,'r','linewidth',2.5),grid on,hold on;
title("Curve for Bit Error Rate verses SNR for Binary ASK modulation");
xlabel('SNR(dB)');
ylabel('BER');
legend('Simulation','Theoritical')
axis([0 10 10^-5 1]);
% Binary-ASK modulation
A1=10; % Amplitude of carrier signal for information 1
A2=5; % Amplitude of carrier signal for information 0
bp=.000001;
br=1/bp; % bit rate
f=br*10; % carrier frequency
t2=bp/99:bp/99:bp;
ss=length(t2);
n1=[];
for i=1:1:length(data)
if (data(i)==1)
y=A1*cos(2*pi*f*t2);
else
y=A2*cos(2*pi*f*t2);
end n1=[n1
y];
end
t3=bp/99:bp/99:bp*length(data);
% eye-diagram
data = repmat([1 0 1 0 0 1 0 1 0 0], 1, 100);
modSig = awgn(modSig, 35);
sps=1;
txfilter = comm.RaisedCosineTransmitFilter('OutputSamplesPerSymbol',sps);
txSig = txfilter(modSig);
eyediagram(txSig,2*sps);
data=[1 0 1 0 0 1 0 1 0 0]; % information
figure(5)
stem(data, 'linewidth',3),
grid on;
title('Information before Transmiting');
axis([ 0 11 0 1.5]);
data_NZR=2*data-1; % Data Represented at NZR form for ASK modulation
s_p_data=reshape(data_NZR,2,length(data)/2); % S/P convertion of data
br=10.^6; %Let us transmission bit rate 1000000
f=br; % minimum carrier frequency
T=1/br; % bit duration
t=T/99:T/99:T; % Time vector for one bit information
y=[];
y_in=[];
y_qd=[];
for(i=1:length(data)/2)
y1=s_p_data(1,i)*cos(2*pi*f*t); % inphase component
y2=s_p_data(2,i)*sin(2*pi*f*t) ;% Quadrature component
y_in=[y_in y1]; % inphase signal vector
y_qd=[y_qd y2]; %quadrature signal vector
y=[y y1+y2]; % modulated signal vector
end
Tx_sig=awgn(y, 10); % transmitting signal after modulation and added noise
tt=T/99:T/99:(T*length(data))/2;
figure(3)
subplot(3,1,1);
plot(tt,y_in,'linewidth',3),
grid on;
title('Wave form for inphase component in ASK modulation');
xlabel('Time(sec)-->');
ylabel('Amplitude(V)');
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3),
grid on;
title('Wave form for Quadrature component in ASK modulation');
xlabel('Time(sec)-->');
ylabel('Amplitude(V)-->');
subplot(3,1,3);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title('ASK modulated signal (sum of inphase and Quadrature phase signal)');
xlabel('Time(sec)');
ylabel('Amplitude(V)');
Rx_data=[];
Rx_sig=Tx_sig; % Received signal
for(i=1:1:length(data)/2)
%%XXXXXX inphase coherent dector XXXXXXX
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
% above line indicat multiplication of received &amp; inphase carred signal
Z_in_intg=(trapz(t,Z_in))*(2/T);% integration using trapizodial rull
if(Z_in_intg>0) % Decession Maker
Rx_in_data=1;
else
Rx_in_data=0;
end
%%XXXXXX Quadrature coherent dector XXXXXX
Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
%above line indicat multiplication ofreceived &amp; Quadphase carred signal
Z_qd_intg=(trapz(t,Z_qd))*(2/T);%integration using trapizodial rull
if (Z_qd_intg>0)% Decession Maker
Rx_qd_data=1;
else
Rx_qd_data=0;
end
Rx_data=[Rx_data Rx_in_data Rx_qd_data]; % Received Data vector
end
figure(4)
stem(Rx_data,'linewidth',3)
title('Information after Receiveing');
axis([ 0 11 0 1.5]),
grid on;
% Amplitude of carrier signal for information 0
bp=.000001;
br=1/bp; % bit rate
f=br*10; % carrier frequency
t2=bp/99:bp/99:bp;
ss=length(t2);
n1=[];
for i=1:1:length(data)
if (data(i)==1)
y=A1*cos(2*pi*f*t2);
else
y=A2*cos(2*pi*f*t2);
end n1=[n1
y];
end
t3=bp/99:bp/99:bp*length(data);
% eye-diagram
data = repmat([1 0 1 0 0 1 0 1 0 0], 1, 100);
modSig = pskmod(data,4,pi/4);
sps=1;
txfilter = comm.RaisedCosineTransmitFilter('OutputSamplesPerSymbol',sps);
txSig = txfilter(modSig);
eyediagram(txSig,2*sps);
data=[1 0 1 0 0 1 0 1 0 0]; % information
figure(5)
stem(data, 'linewidth',3),
grid on;
title('Information before Transmiting');
axis([ 0 11 0 1.5]);
data_NZR=2*data-1; % Data Represented at NZR form for ASK modulation
s_p_data=reshape(data_NZR,2,length(data)/2); % S/P convertion of data
br=10.^6; %Let us transmission bit rate 1000000
f=br; % minimum carrier frequency
T=1/br; % bit duration
t=T/99:T/99:T; % Time vector for one bit information
y=[];
y_in=[];
y_qd=[];
for(i=1:length(data)/2)
y1=s_p_data(1,i)*cos(2*pi*f*t); % inphase component
y2=s_p_data(2,i)*sin(2*pi*f*t) ;% Quadrature component
y_in=[y_in y1]; % inphase signal vector
y_qd=[y_qd y2]; %quadrature signal vector
y=[y y1+y2]; % modulated signal vector
end
Tx_sig=y; % transmitting signal after modulation tt=T/99:T/99:
(T*length(data))/2;
figure(3)
subplot(3,1,1);
plot(tt,y_in,'linewidth',3),
grid on;
title('Wave form for inphase component in ASK modulation');
xlabel('Time(sec)-->');
ylabel('Amplitude(V)');
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3),
grid on;
title('Wave form for Quadrature component in ASK modulation');
xlabel('Time(sec)-->');
ylabel('Amplitude(V)-->');
subplot(3,1,3);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title('ASK modulated signal (sum of inphase and Quadrature phase signal)');
xlabel('Time(sec)');
ylabel('Amplitude(V)');
Rx_data=[];
Rx_sig=Tx_sig; % Received signal
for(i=1:1:length(data)/2)
%%XXXXXX inphase coherent dector XXXXXXX
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
% above line indicat multiplication of received &amp; inphase carred signal
Z_in_intg=(trapz(t,Z_in))*(2/T);% integration using trapizodial rull
if(Z_in_intg>0) % Decession Maker
Rx_in_data=1;
else
Rx_in_data=0;
end
%%XXXXXX Quadrature coherent dector XXXXXX
Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
%above line indicat multiplication ofreceived &amp; Quadphase carred signal
Z_qd_intg=(trapz(t,Z_qd))*(2/T);%integration using trapizodial rull
if (Z_qd_intg>0)% Decession Maker
Rx_qd_data=1;
else
Rx_qd_data=0;
end
Rx_data=[Rx_data Rx_in_data Rx_qd_data]; % Received Data vector
end
figure(4)
stem(Rx_data,'linewidth',3)
title('Information after Receiveing');
axis([ 0 11 0 1.5]),
grid on;
Q3.Compare the BER, eye pattern and I-Q
characteristics for with and
without noise cases.
clc; close
all;
data=[1 0 1 0 0 1 0 1 0 0]; % information
figure(1)
stem(data, 'linewidth',3), grid on;
title(' Information before Transmiting ');
axis([ 0 11 0 1.5]);
data_NZR=2*data-1; % Data Represented at NZR form for ASK modulation
s_p_data=reshape(data_NZR,2,length(data)/2); % S/P convertion of data
br=10.^6; %Let us transmission bit rate 1000000
f=br; % minimum carrier frequency
T=1/br; % bit duration
t=T/99:T/99:T; % Time vector for one bit information
y=[];
y_in=[];
y_qd=[];
for i=1:length(data)/2
y1=s_p_data(1,i)*cos(2*pi*f*t); % inphase component
y2=s_p_data(2,i)*sin(2*pi*f*t) ;% Quadrature component
y_in=[y_in y1]; % inphase signal vector
y_qd=[y_qd y2]; %quadrature signal vector
y=[y y1+y2]; % modulated signal vector
end
Tx_sig=y; % transmitting signal after modulation tt=T/99:T/99:
(T*length(data))/2;
figure(2)
subplot(4,1,1);
plot(tt,y_in,'linewidth',3), grid on;
title(' Wave form for Inphase component in ASK modulation (SNR = 10) ');
xlabel('Time(sec)-->');
ylabel(' Amplitude(V)-->');
subplot(4,1,2);
plot(tt,y_qd,'linewidth',3), grid on;
title(' Wave form for Quadrature component in ASK modulation (SNR = 10)');
xlabel('Time(sec)-->');
ylabel(' Amplitude(V)-->');
subplot(4,1,3);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title('ASK without Noise');
xlabel('Time(sec)-->');
ylabel(' Amplitude(V)-->');
Tx_sig=awgn(y, 10); % transmitting signal after modulation and noise
subplot(4,1,4);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title('ASK with Noise');
xlabel('Time(sec)-->');
ylabel(' Amplitude(V)-->');
data = repmat([1 0 1 0 0 1 0 1 0 0], 1, 100);
modSig = pskmod(data,4,pi/4);
sps=1;
txfilter = comm.RaisedCosineTransmitFilter('OutputSamplesPerSymbol',sps);
txSig = txfilter(modSig);
eyediagram(txSig,2*sps);
Lab 7 communication System

1. Generate the BPSK modulated signal for the


binary data [1 0 1 0 0 1 0 1
0 0] and demodulate.

clc; clear
all; close
all;
% Transmitted signal
x_inp = [1 0 1 0 0 1 0 1 0 0];
N = length(x_inp);
Tb = 0.0001;
disp('Binary Input Information at Transmitter: ');
disp(x_inp);
% Represent transmitted signal as digital signal
x_bit=[];
nb=100;
for n=1:1:N
if x_inp(n)==1;
x_bitt=ones(1,nb);
else x_inp(n)==0;
x_bitt=zeros(1,nb);
end
x_bit=[x_bitx_bitt];
end
t1=Tb/nb:Tb/nb:nb*N*(Tb/nb);
f1 = figure(1);
set(f1,'color',[1 1 1]);
subplot(3,1,1);
plot(t1,x_bit,'lineWidth',2, 'color', 'black');
grid on;
axis([ 0 Tb*N -0.5 1.5]);
ylabel('Amplitude(volt)');
xlabel(' Time(sec)');
title('Digitalized Input Signal');
% BPSK Modulation
Ac=5;
mc=4;
fc=mc*(1/Tb);
fi1=0;
fi2=pi;
t2=Tb/nb:Tb/nb:Tb;
t2L=length(t2);
x_mod=[];
for (i=1:1:N)
if (x_inp(i)==1)
x_mod0=Ac*cos(2*pi*fc*t2+fi1);
else
x_mod0=Ac*cos(2*pi*fc*t2+fi2);
end
x_mod=[x_mod x_mod0];
end
t3=Tb/nb:Tb/nb:Tb*N;
subplot(3,1,2);
plot(t3,x_mod, 'color', 'red');
xlabel('Time(sec)');
ylabel('Amplitude(volt)');
title('Signal of BPSK modulation ');
x=x_mod;
h=1;
w=0;
y=h.*x+w;
% BPSK Demodulation
y_dem=[];
for n=t2L:t2L:length(y)
t=Tb/nb:Tb/nb:Tb;
c=cos(2*pi*fc*t);
y_dem0=c.*y((n-(t2L-1)):n);
t4=Tb/nb:Tb/nb:Tb;
z=trapz(t4,y_dem0);
A_dem=round((2*z/Tb));
if(A_dem>Ac/2)
A=1;
else
A=0;
end y_dem=[y_dem
A]; end
x_out=y_dem;
xx_bit=[];
for n=1:length(x_out);
if x_out(n)==1;
xx_bitt=ones(1,nb);
else x_out(n)==0;
xx_bitt=zeros(1,nb);
end
xx_bit=[xx_bitxx_bitt];
end
t4=Tb/nb:Tb/nb:nb*length(x_out)*(Tb/nb);
subplot(3,1,3)
plot(t4,xx_bit,'LineWidth',2);grid on;
axis([ 0 Tb*length(x_out) -0.5 1.5]);
ylabel('Amplitude(volt)');
xlabel(' Time(sec)');
title('Output signal as digital signal');
2. Add the noise to BPSK then perform the
demodulation and compute the BER, eye
pattern and I-Q characteristics.
clc; clear
all; close
all;
% Transmitted signal
x_inp = [1 0 1 0 0 1 0 1 0 0];
N = length(x_inp);
Tb = 0.0001;
disp('Binary Input Information at Transmitter: ');
disp(x_inp);
% Represent transmitted signal as digital signal
x_bit=[];
nb=100;
for n=1:1:N
if x_inp(n)==1;
x_bitt=ones(1,nb);
else x_inp(n)==0;
x_bitt=zeros(1,nb);
end
x_bit=[x_bitx_bitt];
end
t1=Tb/nb:Tb/nb:nb*N*(Tb/nb);
f1 = figure(1);
set(f1,'color',[1 1 1]);
subplot(3,1,1);
plot(t1,x_bit,'lineWidth',2, 'color', 'black');
grid on;
axis([ 0 Tb*N -0.5 1.5]);
ylabel('Amplitude(volt)');
xlabel(' Time(sec)');
title('Digitalized Input Signal');
% BPSK Modulation
Ac=5;
mc=4;
fc=mc*(1/Tb);
fi1=0;
fi2=pi;
t2=Tb/nb:Tb/nb:Tb;
t2L=length(t2);
x_mod=[];
for (i=1:1:N)
if (x_inp(i)==1)
x_mod0=Ac*cos(2*pi*fc*t2+fi1);
else
x_mod0=Ac*cos(2*pi*fc*t2+fi2);
end
x_mod = awgn([x_mod x_mod0], 1);
end
t3=Tb/nb:Tb/nb:Tb*N;
subplot(3,1,2);
plot(t3,x_mod, 'color', 'red');
% axis([0 1 -5 5]);
xlabel('Time(sec)');
ylabel('Amplitude(volt)');
title('Signal of BPSK modulation ');
x = x_mod;
h=1;
w=0;
y=h.*x+w;
% BPSK Demodulation
y_dem=[];
for n=t2L:t2L:length(y)
t=Tb/nb:Tb/nb:Tb;
c=cos(2*pi*fc*t);
y_dem0=c.*y((n-(t2L-1)):n);
t4=Tb/nb:Tb/nb:Tb;
z=trapz(t4,y_dem0);
A_dem=round((2*z/Tb));
if(A_dem>Ac/2)
A=1;
else
A=0;
end
y_dem = [y_dem A];
end
x_out=y_dem;
xx_bit=[];
for n=1:length(x_out);
if x_out(n)==1;
xx_bitt=ones(1,nb);
else x_out(n)==0;
xx_bitt=zeros(1,nb);
end
xx_bit=[xx_bitxx_bitt];
end
t4=Tb/nb:Tb/nb:nb*length(x_out)*(Tb/nb);
subplot(3,1,3)
plot(t4,xx_bit,'LineWidth',2);grid on;
axis([ 0 Tb*length(x_out) -0.5 1.5]);
ylabel('Amplitude(volt)');
xlabel(' Time(sec)');
title('Output signal as digital signal');
num_bit=10;
data=[1 0 1 0 0 1 0 1 0 0];
s=2*data-1;
SNRdB=0:10;
SNR=10.^(SNRdB/10);
for(k=1:length(SNRdB))
y=awgn(complex(s),SNRdB(k));
error=0;
for(c=1:1:num_bit)
if (y(c)>0&&data(c)==0)||(y(c)<0&&data(c)==1)
error=error+1;
end
end
error=error/num_bit;
m(k)=error;
end
figure(1)
semilogy(SNRdB,m,'o','linewidth',2.5),gridon,hold on;
BER_th=(1/2)*erfc(sqrt(SNR));
semilogy(SNRdB,BER_th,'r','linewidth',2.5);
title(' curve for Bit Error Rate verses SNR for Binary PSK modulation');
xlabel(' SNR(dB)');
ylabel('BER');
legend('simulation','theorytical')
axis([0 10 10^-5 1]);
clc; close
all;
data=[1 0 1 0 0 1 0 1 0 0]; % information
figure(1)
stem(data, 'linewidth',3), grid on;
title(' Information before Transmiting ');
axis([ 0 11 0 1.5]);
data_NZR=2*data-1; % Data Represented at NZR form for modulation
s_p_data=reshape(data_NZR,2,length(data)/2); % S/P convertion of data
br=10.^6; %Let us transmission bit rate 1000000
f=br; % minimum carrier frequency
T=1/br; % bit duration
t=T/99:T/99:T; % Time vector for one bit information
y=[];
y_in=[];
y_qd=[];
for(i=1:length(data)/2)
y1=s_p_data(1,i)*cos(2*pi*f*t); % inphase component
y2=s_p_data(2,i)*sin(2*pi*f*t) ;% Quadrature component
y_in=[y_in y1]; % inphase signal vector
y_qd=[y_qd y2]; %quadrature signal vector
y=[y y1+y2]; % modulated signal vector
end
Tx_sig=y; % transmitting signal after modulation tt=T/99:T/99:
(T*length(data))/2;
figure(2)
y_in = awgn(y_in, 10);
subplot(3,1,1);
plot(tt,y_in,'linewidth',3), grid on;
title('BPSK wave form for inphase component in modulation (SNR = 10)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
y_qd = awgn(y_qd, 10);
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3), grid on;
title('BPSK wave form for Quadrature component in modulation (SNR = 10)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
Tx_sig = awgn(Tx_sig, 10);
subplot(3,1,3);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title('BPSK modulated signal (sum of inphase and Quadrature phase signal) (SNR
=
10)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
Rx_data=[];
Rx_sig=Tx_sig; % Received signal
for(i=1:1:length(data)/2)
%%XXXXXX inphase coherent dector XXXXXXX
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
% above line indicat multiplication of received &inphasecarred signal
Z_in_intg=(trapz(t,Z_in))*(2/T);% integration using trapizodialrull
if(Z_in_intg>0) % Decession Maker
Rx_in_data=1;
else
Rx_in_data=0;
end
%%XXXXXX Quadrature coherent dector XXXXXX
Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
%above line indicat multiplication ofreceived&Quadphasecarred signal
Z_qd_intg=(trapz(t,Z_qd))*(2/T);%integration using trapizodialrull
if (Z_qd_intg>0)% Decession Maker
Rx_qd_data=1;
else
Rx_qd_data=0;
end
Rx_data=[Rx_dataRx_in_dataRx_qd_data]; % Received Data vector
end
% figure(3)
% stem(Rx_data,'linewidth',3)
% title('Information after Receiveing ');
% axis([ 0 11 0 1.5]), grid on;
3. Compare the BER, eye pattern and I-Q
characteristics for with and without noise
cases.
Code
data = repmat([1 0 1 0 0 1 0 1 0 0], 1, 100);
modSig = pskmod(data,4,pi/4);
modSig = awgn(modSig, 100);
sps=1;
txfilter = comm.RaisedCosineTransmitFilter('OutputSamplesPerSymbol',sps);
txSig = txfilter(modSig);
eyediagram(txSig,2*sps, 'label');
clc;
close all;
data=[1 0 1 0 0 1 0 1 0 0]; % information
figure(1)
stem(data, 'linewidth',3), grid on;
title(' Information before Transmiting ');
axis([ 0 11 0 1.5]);
data_NZR=2*data-1; % Data Represented at NZR form for QPSK modulation
s_p_data=reshape(data_NZR,2,length(data)/2); % S/P convertion of data
br=10.^6; %Let us transmission bit rate 1000000
f=br; % minimum carrier frequency
T=1/br; % bit duration
t=T/99:T/99:T; % Time vector for one bit information
y=[];
y_in=[];
y_qd=[];
for(i=1:length(data)/2)
y1=s_p_data(1,i)*cos(2*pi*f*t); % inphase component
y2=s_p_data(2,i)*sin(2*pi*f*t) ;% Quadrature component
y_in=[y_in y1]; % inphase signal vector
y_qd=[y_qd y2]; %quadrature signal vector
y=[y y1+y2]; % modulated signal vector
end
Tx_sig=awgn(y, 10); % transmitting signal after modulation tt=T/99:T/99:
(T*length(data))/2;
figure(2)
subplot(3,1,1);
plot(tt,y_in,'linewidth',3), grid on;
title(' wave form for inphase component in QPSK modulation (SNR = 10) ');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3), grid on;
title(' wave form for Quadrature component in QPSK modulation (SNR = 10)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
subplot(3,1,3);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title('QPSK modulated signal (sum of inphase and Quadrature phase signal) (SNR
=
10)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
Rx_data=[];
Rx_sig=Tx_sig; % Received signal
for(i=1:1:length(data)/2)
%%XXXXXX inphase coherent dector XXXXXXX
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
% above line indicat multiplication of received &inphasecarred signal
Z_in_intg=(trapz(t,Z_in))*(2/T);% integration using trapizodialrull
if(Z_in_intg>0) % Decession Maker
Rx_in_data=1;
else
Rx_in_data=0;
end
%%XXXXXX Quadrature coherent dector XXXXXX
Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
%above line indicat multiplication ofreceived&Quadphasecarred signal
Z_qd_intg=(trapz(t,Z_qd))*(2/T);%integration using trapizodialrull
if (Z_qd_intg>0)% Decession Maker
Rx_qd_data=1;
else
Rx_qd_data=0;
end
Rx_data=[Rx_dataRx_in_dataRx_qd_data]; % Received Data vector
end
figure(3)
stem(Rx_data,'linewidth',3)
title('Information after Receiveing ');
axis([ 0 11 0 1.5]), grid on;
4. Generate the FSK modulated signal for the
binary data [1 0 1 0 0 1 0 1 0 0] and
demodulate.
clc; clear
all; close
all;
x=[ 1 0 1 0 0 1 0 1 0 0];
bp=.000001;
% Transmitted Signal
bit=[];
for n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1,bit,'lineWidth',2.5, 'color', 'red');
grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('transmitted information');
% Binary-FSK modulation
A=5;
br=1/bp;
f1=br*8;
f2=br*2;
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for (i=1:1:length(x))
if (x(i)==1)
y=A*cos(2*pi*f1*t2);
else
y=A*cos(2*pi*f2*t2);
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m, 'color', 'black');
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('FSK modulated signal');
% Binary FSK demodulation
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y1=cos(2*pi*f1*t);
y2=cos(2*pi*f2*t);
mm=y1.*m((n-(ss-1)):n);
mmm=y2.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z1=trapz(t4,mm) % integration
z2=trapz(t4,mmm) % integration
zz1=round(2*z1/bp)
zz2= round(2*z2/bp)
if(zz1>A/2) % logic lavel= (0+A)/2 or (A+0)/2 or 2.5 ( in this case)
a=1;
else(zz2>A/2)
a=0;
end mn=[mn
a]; end
% digital signal after demodulation
bit=[];
for n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('received information ');
5. Add the noise to FSK then perform the
demodulation and compute the BER, eye
pattern and I-Q characteristics.
clc; clear
all; close
all;
x=[ 1 0 1 0 0 1 0 1 0 0];
bp=.000001;
bit=[];
for n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1,bit,'lineWidth',2.5, 'color', 'red');
grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('transmitted information');
A=5;
br=1/bp;
f1=br*8;
f2=br*2;
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for (i=1:1:length(x))
if (x(i)==1)
y=A*cos(2*pi*f1*t2);
else
y=A*cos(2*pi*f2*t2);
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
t3 = awgn(t3, 160);
subplot(3,1,2);
plot(t3,m, 'color', 'black');
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('FSK modulated signal');
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y1=cos(2*pi*f1*t);
y2=cos(2*pi*f2*t);
mm=y1.*m((n-(ss-1)):n);
mmm=y2.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z1=trapz(t4,mm);
z2=trapz(t4,mmm);
zz1=round(2*z1/bp);
zz2= round(2*z2/bp);
if(zz1>A/2)
a=1;
else(zz2>A/2)
a=0;
end mn=[mn
a]; end
bit=[];
for n=1:length(mn)
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('received information ');
clc;
clear all;
close all;
num_bit=10;
data=[1 0 1 0 0 1 0 1 0 0];
s=2*data-1;
SNRdB=0:10;
SNR=20.^(SNRdB/10);
for(k=1:length(SNRdB))
y=awgn(complex(s),SNRdB(k));
error=0;
for(c=1:1:num_bit)
if (y(c)>0&&data(c)==0)||(y(c)<0&&data(c)==1)
error=error+1;
end
end
error=error/num_bit;
m(k)=error;
end
figure(1)
semilogy(SNRdB,m,'o','linewidth',2.5),grid on,hold on;
BER_th=(1/2)*erfc(sqrt(SNR));
semilogy(SNRdB,BER_th,'r','linewidth',2.5);
title(' curve for Bit Error Rate verses SNR for Binary FSK modulation');
xlabel(' SNR(dB)');
ylabel('BER');
legend('simulation','theorytical')
axis([0 10 10^-5 1]);
axis([0 10 10^-5 1]);
clc; close
all;
data=[1 0 1 0 0 1 0 1 0 0]; % information
figure(1)
stem(data, 'linewidth',3), grid on;
title(' Information before Transmiting ');
axis([ 0 11 0 1.5]);
data_NZR=2*data-1; % Data Represented at NZR form for modulation
s_p_data=reshape(data_NZR,2,length(data)/2); % S/P convertion of data
br=10.^6; %Let us transmission bit rate 1000000
f=br; % minimum carrier frequency
T=1/br; % bit duration
t=T/99:T/99:T; % Time vector for one bit information
y=[];
y_in=[];
y_qd=[];
for(i=1:length(data)/2)
y1=s_p_data(1,i)*cos(2*pi*f*t); % inphase component
y2=s_p_data(2,i)*sin(2*pi*f*t) ;% Quadrature component
y_in=[y_in y1]; % inphase signal vector
y_qd=[y_qd y2]; %quadrature signal vector
y=[y y1+y2]; % modulated signal vector
end
Tx_sig=y; % transmitting signal after modulation tt=T/99:T/99:
(T*length(data))/2;
figure(2)
y_in = awgn(y_in, 10);
subplot(3,1,1);
plot(tt,y_in,'linewidth',3), grid on;
title(FSK wave form for inphase component in modulation (SNR = 10)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
y_qd = awgn(y_qd, 10);
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3), grid on;
title(FSK wave form for Quadrature component in modulation (SNR = 10)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
Tx_sig = awgn(Tx_sig, 10);
subplot(3,1,3);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title(FSK modulated signal (sum of inphase and Quadrature phase signal) (SNR =
10)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
Rx_data=[];
Rx_sig=Tx_sig; % Received signal
for(i=1:1:length(data)/2)
%%XXXXXX inphase coherent dector XXXXXXX
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
% above line indicat multiplication of received &inphasecarred signal
Z_in_intg=(trapz(t,Z_in))*(2/T);% integration using trapizodialrull
if(Z_in_intg>0) % Decession Maker
Rx_in_data=1;
else
Rx_in_data=0;
end
%%XXXXXX Quadrature coherent dector XXXXXX
Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
%above line indicat multiplication ofreceived&Quadphasecarred signal
Z_qd_intg=(trapz(t,Z_qd))*(2/T);%integration using trapizodialrull
if (Z_qd_intg>0)% Decession Maker
Rx_qd_data=1;
else
Rx_qd_data=0;
end
Rx_data=[Rx_dataRx_in_dataRx_qd_data]; % Received Data vector
end
% figure(3)
% stem(Rx_data,'linewidth',3)
% title('Information after Receiveing ');
% axis([ 0 11 0 1.5]), grid on;
6. Compare the BER, eye pattern and I-Q
characteristics for with and without noise cases.
Code
% eye diagram from fsk modulation with noise
data = repmat([1 0 1 0 0 1 0 1 0 0], 1, 100);
modSig = fskmod(data,4,pi/4);
modSig = awgn(modSig, 100);
sps=1;
txfilter = comm.RaisedCosineTransmitFilter('OutputSamplesPerSymbol',sps);
txSig = txfilter(modSig);
eyediagram(txSig,2*sps, 'label');
% eye diagram from fsk modulation without noise
data = repmat([1 0 1 0 0 1 0 1 0 0], 1, 100);
modSig = fskmod(data,4,pi/4);
modSig = awgn(modSig, 100);
sps=1;
txfilter = comm.RaisedCosineTransmitFilter('OutputSamplesPerSymbol',sps);
txSig = txfilter(modSig);
eyediagram(txSig,2*sps, 'label');
clc;
clear all;
close all;
num_bit=10;
data=[1 0 1 0 0 1 0 1 0 0];
s=2*data-1;
SNRdB=0:10;
SNR=20.^(SNRdB/10);
for(k=1:length(SNRdB))
y=awgn(complex(s),SNRdB(k));
error=0;
for(c=1:1:num_bit)
if (y(c)>0&&data(c)==0)||(y(c)<0&&data(c)==1)
error=error+1;
end
end
error=error/num_bit;
m(k)=error;
end
figure(1)
semilogy(SNRdB,m,'o','linewidth',2.5),grid on,hold on;
BER_th=(1/2)*erfc(sqrt(SNR));
semilogy(SNRdB,BER_th,'r','linewidth',2.5);
title(' curve for Bit Error Rate verses SNR for Binary FSK modulation');
xlabel(' SNR(dB)');
ylabel('BER');
legend('simulation','theorytical')
axis([0 10 10^-5 1 ]);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy