+ All Categories
Home > Documents > Matlab Communication

Matlab Communication

Date post: 04-Oct-2014
Category:
Upload: harini-vemu
View: 111 times
Download: 6 times
Share this document with a friend
Popular Tags:
38
September 23, 2010 NIT DGP Student Branch Simulating Communication Systems Simulating Communication Systems with MATLAB : An Introduction with MATLAB : An Introduction Aniruddha Chandra ECE Department, NIT Durgapur, WB, India. [email protected]
Transcript
Page 1: Matlab Communication

September 23, 2010

NIT DGP Student Branch

Simulating Communication Systems Simulating Communication Systems with MATLAB : An Introductionwith MATLAB : An Introduction

Aniruddha ChandraECE Department, NIT Durgapur, WB, India.

[email protected]

Page 2: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 2

Sep. 23, 2010Presentation OutlinePresentation Outline

Objective of the Lecture

Expected Background

Simulating Analog Communication Systems Amplitude Modulation (AM)

Simulating Digital Communication SystemsBinary Phase Shift Keying (BPSK)

Page 3: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 3

Sep. 23, 2010Presentation OutlinePresentation Outline

Objective of the Lecture

Expected Background

Simulating Analog Communication Systems Amplitude Modulation (AM)

Simulating Digital Communication SystemsBinary Phase Shift Keying (BPSK)

Page 4: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 4

Sep. 23, 2010Objective of the LectureObjective of the Lecture

After the Lecture … You’ll be able to

Write your own Matlab Script

Make a Analog/ Digital Communication Link

Compare your Results with Theoretical Values

Page 5: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 5

Sep. 23, 2010Presentation OutlinePresentation Outline

Objective of the Lecture

Expected Background

Simulating Analog Communication Systems Amplitude Modulation (AM)

Simulating Digital Communication SystemsBinary Phase Shift Keying (BPSK)

Page 6: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 6

Sep. 23, 2010Expected BackgroundExpected Background

I assume that …You understand

Basic MATLAB Operations (function, matrix)

Basics of Communication (modulation)

Performance Metrics (BER)

Page 7: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 7

Sep. 23, 2010Presentation OutlinePresentation Outline

Objective of the Lecture

Expected Background

Simulating Analog Communication Systems Amplitude Modulation (AM)

Simulating Digital Communication SystemsBinary Phase Shift Keying (BPSK)

Page 8: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 8

Sep. 23, 2010Analog Communication SystemsAnalog Communication Systems

Source

Channel

Destination Demodulator

Modulator

Page 9: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 9

Sep. 23, 2010Simulate a SourceSimulate a Source

Source

Channel

Destination Demodulator

Modulator

Produces message signal … e.g. a simple Sine wave

Page 10: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 10

Sep. 23, 2010Simulate a SourceSimulate a Source

Generate message signal (simple sine wave)( ) ( )tfVtm mm π= 2sin

Define time instants (1000 sample points)tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;t = tmin:step:tmax;

Define amplitude and frequency (initial phase is zero)Vm = 1; % Amplitudefm = 2*10^3; % Frequency

Construct the Signalm = Vm*sin(2*pi*fm*t);

View the Signalplot(t,m,'r');

Page 11: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 11

Sep. 23, 2010Simulate a SourceSimulate a Source

Complete MATLAB Script [Prog1.m]

tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;t = tmin:step:tmax; fm = 2*10^3; Vm = 1; m = Vm*sin(2*pi*fm*t); plot(t,m,'r');

Page 12: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 12

Sep. 23, 2010Simulate a SourceSimulate a Source

Page 13: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 13

Sep. 23, 2010Simulate a SourceSimulate a Source

Assignment #1 [Prog2.m], [Prog3.m]

What happens if there is an initial phase?phi_deg = 45;phi_rad = phi_deg*pi/180;m = Vm*sin(2*pi*fm*t+phi_rad);

What happens if the message is not sinusoidal?tmin = 0; tmax = 1; step = (tmax-tmin)/1000;t = tmin:step:tmax;f = 2; m = sawtooth(2*pi*f*t);plot(t,m,'r');

Page 14: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 14

Sep. 23, 2010Simulate ModulationSimulate Modulation

Source

Channel

Destination Demodulator

Modulator

Built-in functions are available (ammod, amdemod etc.)

WYSIWYG?? No

Page 15: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 15

Sep. 23, 2010Amplitude ModulationAmplitude Modulation

Simulate with built-in functions [Prog4.m]

fs = 8000; % Sampling rate is 8000 samples per secondfc = 300; % Carrier frequency in Hzt = [0:0.1*fs]'/fs; % Sampling times for 0.1 secondm = sin(20*pi*t); % Representation of the signalv = ammod(m,fc,fs); % Modulate m to produce v

figure(1)subplot(2,1,1); plot(t,m); % Plot m on topsubplot(2,1,2); plot(t,v); % Plot v below

mr = amdemod(v,fc,fs); % Demodulate v to produce m

figure(2);subplot(2,1,1); plot(t,m); % Plot m on topsubplot(2,1,2); plot(t,mr); % Plot mr below

Source: Introduction to Communications Toolbox in MATLAB 7.6.0 (R2008) by Amit DegadaAvailable: http://amitdegada.weebly.com/download.html

Page 16: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 16

Sep. 23, 2010Amplitude ModulationAmplitude Modulation

Page 17: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 17

Sep. 23, 2010Amplitude ModulationAmplitude Modulation

Page 18: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 18

Sep. 23, 2010Amplitude ModulationAmplitude Modulation

Don’t have the feel??? …. Try this

Define message signal, (as done earlier)

tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;t = tmin:step:tmax;Vm = 1;fm = 2*10^3;m = Vm*sin(2*pi*fm*t);

Define carrier,

Vc = 2; % Amplitudefc = 10^4; % Frequencyc = Vc*sin(2*pi*fc*t); % Carrier signal

( ) ( )tfVtm mm π= 2sin

( ) ( )tfVtc cc π= 2sin

Page 19: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 19

Sep. 23, 2010Amplitude ModulationAmplitude Modulation

Continued ….

Modulate the Signal,

v = (1+m/Vc).*c; % DSB-FC modulation

View Modulated Wave

plot(t,v); % Modulated Wavehold on; plot(t,Vc*(1+m/Vc),'r:'); % Upper Envelopehold on; plot(t,-Vc*(1+m/Vc),'r:'); % Lower Envelopehold off ;

( ) ( ) ( )tftfVVVtv cm

c

mc π⎥

⎤⎢⎣

⎡π+= 2sin2sin1

Page 20: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 20

Sep. 23, 2010Amplitude ModulationAmplitude Modulation

Complete MATLAB Script [Prog5.m]

clear all; close all; clc;tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;t = tmin:step:tmax; % TimeVm = 1; Vc = 2; % Amplitude fm = 2*10^3; fc = 10^4; % Frequency

m = Vm*sin(2*pi*fm*t); % Messagec = Vc*sin(2*pi*fc*t); % Carrierv = (1+m/Vc).*c; % Modulated Wave

plot(t,v); hold on; plot(t,Vc*(1+m/Vc),'r:'); hold on; % Upper Envelopeplot(t,-Vc*(1+m/Vc),'r:'); hold off % Lower Envelope

Page 21: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 21

Sep. 23, 2010Amplitude ModulationAmplitude Modulation

Page 22: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 22

Sep. 23, 2010Amplitude ModulationAmplitude Modulation

Assignment #2 [Prog6.m]

How to view effect of changing modulation index? tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;t = tmin:step:tmax; Vm = 1; mu = 1.5; Vc = Vm/mu; fm = 2*10^3; fc = 10^4;

m = Vm*sin(2*pi*fm*t); c = Vc*sin(2*pi*fc*t); v = (1+m/Vc).*c;

plot(t,v); hold on; plot(t,Vc*(1+m/Vc),'r:'); hold on; plot(t,-Vc*(1+m/Vc),'r:'); hold off

Page 23: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 23

Sep. 23, 2010Amplitude ModulationAmplitude Modulation

Assignment #2 (Contd…) [Prog7.m]

How to simulate DSB-SC modulation?tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;t = tmin:step:tmax; Vm = 2; Vc = 1; fm = 2*10^3; fc = 10^4;

m = Vm*sin(2*pi*fm*t); c = Vc*sin(2*pi*fc*t); v = m.*c;

plot(t,v); hold on; plot(t,m,'r:'); hold on; plot(t,-m,'r:'); hold off

Page 24: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 24

Sep. 23, 2010DemodulationDemodulation

Demodulate DSB-SC with filter [Prog8.m]

clear all; close all; clc;tmin = 0; tmax = 1; step = (tmax-tmin)/(10^3);t = tmin:step:tmax; Vm = 2; Vc = 1; fm = 2; fc = 10^2;

m = Vm*sin(2*pi*fm*t); c = Vc*sin(2*pi*fc*t); v = m.*c;

r = v.*c;

[b a] = butter(1,0.01);mr = filter(b,a,r);

figure(1)subplot(2,1,1); plot(t,m);subplot(2,1,2); plot(t,mr);

Page 25: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 25

Sep. 23, 2010DemodulationDemodulation

Page 26: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 26

Sep. 23, 2010DemodulationDemodulation

Ideal Demodulation of DSB-SC [Prog9.m]

clear all; close all; clc;fs = 10^5; N = 10^5; t = 1/fs:1/fs:N/fs; fm = 2; fc = 10^3; m = sin(2*pi*fm*t); c = sin(2*pi*fc*t); v = m.*c;

r = zeros(1,N); n =f s/fc;for k = 1:fc

mr((k-1)*n+1:k*n) = 2*v((k-1)*n+1:k*n)*c((k-1)*n+1:k*n)'/n;end

figure(1)subplot(2,1,1); plot(t,m);subplot(2,1,2); plot(t,mr);

Page 27: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 27

Sep. 23, 2010DemodulationDemodulation

Page 28: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 28

Sep. 23, 2010Analog Communication SystemsAnalog Communication Systems

Source

Channel

Destination Demodulator

Modulator

Introduces noise … Additive White Gaussian Noise

Page 29: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 29

Sep. 23, 2010Simulate ChannelSimulate Channel

Introducing AWGN [Prog10.m]fs = 10^5; N = 10^5; t = 1/fs:1/fs:N/fs; fm = 2; fc = 10^3; m = sin(2*pi*fm*t); c = sin(2*pi*fc*t); v = m.*c;

SNRdB = 10; SNR = 10^(SNRdB/10);vn = var(v)/SNR;n = sqrt(vn)*randn(1,N);v = v + n;

r=zeros(1,N); n=fs/fc;for k=1:fc

mr((k-1)*n+1:k*n)=2*v((k-1)*n+1:k*n)*c((k-1)*n+1:k*n)'/n;end

figure(1)subplot(2,1,1); plot(t,m);subplot(2,1,2); plot(t,mr); axis([0 1 -1 1])

Page 30: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 30

Sep. 23, 2010Simulate ChannelSimulate Channel

Page 31: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 31

Sep. 23, 2010Presentation OutlinePresentation Outline

Objective of the Lecture

Expected Background

Simulating Analog Communication Systems Amplitude Modulation (AM)

Simulating Digital Communication SystemsBinary Phase Shift Keying (BPSK)

Page 32: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 32

Sep. 23, 2010Digital Communication SystemsDigital Communication Systems

Source

Channel

Destination Demodulator

Modulator

Page 33: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 33

Sep. 23, 2010Simulate BPSKSimulate BPSK

Simulation [Prog11.m]

%This program simulates BER of BPSK in AWGN channel%clear all; close all; clc;num_bit=100000; %Signal length max_run=20; %Maximum number of iterations for a single SNREb=1; %Bit energySNRdB=0:1:9; %Signal to Noise Ratio (in dB)SNR=10.^(SNRdB/10);

hand=waitbar(0,'Please Wait....');for count=1:length(SNR) %Beginning of loop for different SNR

avgError=0;No=Eb/SNR(count); %Calculate noise power from SNR

Page 34: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 34

Sep. 23, 2010Simulate BPSKSimulate BPSK

Simulation (Contd.) [Prog11.m]for run_time=1:max_run %Beginning of loop for different runs

waitbar((((count-1)*max_run)+run_time-1)/(length(SNRdB)*max_run));Error=0;

data=randint(1,num_bit); %Generate binary data sources=2*data-1; %Baseband BPSK modulation

N=sqrt(No/2)*randn(1,num_bit); %Generate AWGN

Y=s+N; %Received Signal

for k=1:num_bit %Decision device taking hard decision and deciding errorif ((Y(k)>0 && data(k)==0)||(Y(k)<0 && data(k)==1))

Error=Error+1;end

end

Error=Error/num_bit; %Calculate error/bitavgError=avgError+Error; %Calculate error/bit for different runs

end %Termination of loop for different runs

Page 35: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 35

Sep. 23, 2010Simulate BPSKSimulate BPSK

Simulation (Contd.) [Prog11.m]BER_sim(count)=avgError/max_run; %Calculate BER for a particular SNR end %Termination of loop for different SNR BER_th=(1/2)*erfc(sqrt(SNR)); %Calculate analytical BERclose(hand);

semilogy(SNRdB,BER_th,'k'); %Plot BERhold onsemilogy(SNRdB,BER_sim,'k*');legend('Theoretical','Simulation',3);axis([min(SNRdB) max(SNRdB) 10^(-5) 1]);hold off

Page 36: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 36

Sep. 23, 2010Simulate BPSKSimulate BPSK

Page 37: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 37

Sep. 23, 2010ReferencesReferences

[1] http://www.mathworks.com/matlabcentral/

[2] http://www.freewebs.com/acwebpage/teaching.htm

[3] B.P. Lathi and Z. Ding, Modern Digital and Analog Communication Systems, Oxford University Press, International 4th edition, 2010.

[4] J.G. Proakis, M. Salehi, and G. Bauch, Contemporary Communication Systems using MATLAB, Thomson/ CL-Engineering, 2nd edition, 2003.

Page 38: Matlab Communication

A. Chandra, ECE Deptt., NITD Simulating Communication Systems with MATLAB 38

Sep. 23, 2010

Thank You!

[email protected]


Recommended