basics of matlab

38
September 23, 2010 NIT DGP Student Branch Aniruddha Chandra ECE Department, NIT Durgapur, WB, India. [email protected] Simulating Communication Simulating Communication Systems with MATLAB : An Systems with MATLAB : An Introduction Introduction

Upload: pavan-k-sarma

Post on 04-Sep-2015

16 views

Category:

Documents


1 download

DESCRIPTION

Matlab Basics

TRANSCRIPT

Slide [email protected]
*
*
*
Write your own Matlab Script
Make a Analog/ Digital Communication Link
Compare your Results with Theoretical Values
*
*
Basics of Communication (modulation)
*
*
*
Source
Channel
Destination
Demodulator
Modulator
*
tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;
t = tmin:step:tmax;
Vm = 1; % Amplitude
Construct the Signal
View the Signal
*
t = tmin:step:tmax;
plot(t,m,'r');
*
*
phi_deg = 45;
What happens if the message is not sinusoidal?
tmin = 0; tmax = 1; step = (tmax-tmin)/1000;
t = tmin:step:tmax;
f = 2;
plot(t,m,'r');
*
WYSIWYG?? No
*
fs = 8000; % Sampling rate is 8000 samples per second
fc = 300; % Carrier frequency in Hz
t = [0:0.1*fs]'/fs; % Sampling times for 0.1 second
m = sin(20*pi*t); % Representation of the signal
v = ammod(m,fc,fs); % Modulate m to produce v
figure(1)
subplot(2,1,2); plot(t,v); % Plot v below
mr = amdemod(v,fc,fs); % Demodulate v to produce m
figure(2);
subplot(2,1,2); plot(t,mr); % Plot mr below
Source: Introduction to Communications Toolbox in MATLAB 7.6.0 (R2008) by Amit Degada
*
*
*
Define message signal, (as done earlier)
tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;
t = tmin:step:tmax;
Vm = 1;
Define carrier,
*
View Modulated Wave
plot(t,v); % Modulated Wave
hold on;
hold off ;
*
tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;
t = tmin:step:tmax; % Time
fm = 2*10^3; fc = 10^4; % Frequency
m = Vm*sin(2*pi*fm*t); % Message
c = Vc*sin(2*pi*fc*t); % Carrier
v = (1+m/Vc).*c; % Modulated Wave
plot(t,v); hold on;
Amplitude Modulation
*
*
tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;
t = tmin:step:tmax;
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;
Amplitude Modulation
*
tmin = 0; tmax = 10^(-3); step = (tmax-tmin)/1000;
t = tmin:step:tmax;
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
*
tmin = 0; tmax = 1; step = (tmax-tmin)/(10^3);
t = tmin:step:tmax;
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);
*
*
fs = 10^5; N = 10^5;
t = 1/fs:1/fs:N/fs;
v = m.*c;
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)
*
*
Source
Channel
Destination
Demodulator
Modulator
*
t = 1/fs:1/fs:N/fs;
v = m.*c;
vn = var(v)/SNR;
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)
*
*
*
*
clear all; close all; clc;
num_bit=100000; %Signal length
max_run=20; %Maximum number of iterations for a single SNR
Eb=1; %Bit energy
SNR=10.^(SNRdB/10);
avgError=0;
*
waitbar((((count-1)*max_run)+run_time-1)/(length(SNRdB)*max_run));
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 error
if ((Y(k)>0 && data(k)==0)||(Y(k)<0 && data(k)==1))
Error=Error+1;
end %Termination of loop for different runs
*
end %Termination of loop for different SNR
BER_th=(1/2)*erfc(sqrt(SNR)); %Calculate analytical BER
close(hand);
hold off
*
*
[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.
*