matlab examples

62
Exp No: 1 9/10/2013 DIGITAL MODULATION SCHEMES AIM To perform the BASK, BFSK, BPSK digital modulation schemes and compare the bit error rate of these modulation schemes. SOFTWARE USED Matlab 7.1 THEORY ASK refers to a type of amplitude modulation that assigns bit values to discrete amplitude levels. The carrier signal is then modulated among the members of a set of discrete values to transmit information. In Binary Amplitude Shift Keying the amplitude of carrier signal is varied to represent binary 0 or 1. FSK refers to a type of frequency modulation that assigns bit values to discrete frequency levels. FSK is divided into non-coherent and coherent forms. In non-coherent forms of FSK, the instantaneous frequency shifts between two discrete values termed the "mark" and "space" frequencies. In coherent forms of FSK, there is no phase discontinuity in the output signal. Binary Frequency Shift Keying (BFSK), the frequency of a constant amplitude carrier signal is switched between two values according to the two possible message states (called high and low tones) corresponding to a binary 1 or 0. PSK in a digital transmission refers to a type of angle modulation in which the phase of the carrier is discretely varied either in relation to a reference phase or to the phase of the immediately preceding signal element to represent data being transmitted. Binary Phase Shift Keying (BPSK) is a type of phase modulation using 2 distinct carrier phases to signal COMMUNICATION SYSTEM ENGINEERING LABPage 1

Upload: annachithysalu

Post on 20-Jul-2016

115 views

Category:

Documents


5 download

DESCRIPTION

It is useful for mtech(communication) students doing their lab.It contains many experiments with explanation.

TRANSCRIPT

Federal Institute of Science And Technology (FISAT)

Exp No: 19/10/2013DIGITAL MODULATION SCHEMESAIMTo perform the BASK, BFSK, BPSK digital modulation schemes and compare the bit error rate of these modulation schemes. SOFTWARE USEDMatlab 7.1THEORYASK refers to a type of amplitude modulation that assigns bit values to discrete amplitude levels. The carrier signal is then modulated among the members of a set of discrete values to transmit information. In Binary Amplitude Shift Keying the amplitude of carrier signal is varied to represent binary 0 or 1.FSK refers to a type of frequency modulation that assigns bit values to discrete frequency levels. FSK is divided into non-coherent and coherent forms. In non-coherent forms of FSK, the instantaneous frequency shifts between two discrete values termed the "mark" and "space" frequencies. In coherent forms of FSK, there is no phase discontinuity in the output signal. Binary Frequency Shift Keying (BFSK), the frequency of a constant amplitude carrier signal is switched between two values according to the two possible message states (called high and low tones) corresponding to a binary 1 or 0.PSK in a digital transmission refers to a type of angle modulation in which the phase of the carrier is discretely varied either in relation to a reference phase or to the phase of the immediately preceding signal element to represent data being transmitted. Binary Phase Shift Keying (BPSK) is a type of phase modulation using 2 distinct carrier phases to signal ones and zeros. BPSK is the simplest form of PSK. It uses two phases which are separated by 180 and so can also be termed 2-PSK. Here each change of phase carries one bit of information, that is, the bit rate equals the modulation rate. Bit Error RateIt is the number of bit errors divided by the total number of transferred bits during a studied time interval. It is used to quantify a channel carrying data by counting the rate of errors in a data string. It is used in telecommunications, networks and radio systems. It is a unit less performance measure often expressed as percentage. For BPSK system,

For BFSK system,

For BASK system,

FSK system has better BER than the PSK system for the same EIRP values. For smaller values of EIRP, the BER offered by the FSK and PSK systems are similar. However, as the EIRP increases, the BER of the FSK system drops at a much higher rate than the BER of the PSK system.PROCEDURE1. Read the input bit stream and plot it.2. Generate two carriers having different amplitudes and plot the corresponding waveform.3. Perform the amplitude modulation with the input bit stream by using the generated carriers.4. Calculate the bit error rate (BER) using the berawgn function.5. Plot the corresponding BER in the logarithmic scale.6. Repeat the above steps for BFSK with carriers having two different frequencies7. Repeat the above steps for BPSK with carriers having two different frequencies8. Compare the bit error rate of these modulation schemes and plot the performance curve.PROGRAM BASKx=input('enter the input stream ');n=length(x);a1=3;a2=5;f=3;t=0:0.01:1;time=[ ];ask_sig=[ ];dig_sig=[ ];for i=1:ndig_sig =[dig_sig (x(i)==0)*zeros(1,length(t))+(x(i)==1)*ones(1,length(t))];ask_sig=[ask_sig (x(i)==0)*a1*sin(2*pi*f*t)+(x(i)==1)*a2*sin(2*pi*f*t)];time=[time t]; t=t+1;end; %carriersubplot(5,1,1);plot(time,3*sin(2*pi*3*time));xlabel('time');ylabel('carrier 1');title('carrier1');axis([0 time(length(time)) -6 6]);subplot(5,1,2);plot(time,5*sin(2*pi*3*time));xlabel('time');ylabel('carrier 2');title('carrier 2');axis([0 time(length(time)) -6 6]);%input bit streamsubplot(5,1,3);plot(time,dig_sig);xlabel('time');ylabel('i/p');axis([0 time(length(time)) -1 2]);title('input bit stream');%modulated carriersubplot(5,1,4);plot(time,ask_sig);xlabel('time');ylabel('ask signal');axis([0 time(length(time)) -6 6]);title('ask with two amplitudes');%bit error rateEbn=[0:.5:15];BER= berawgn(Ebn,'pam',2);subplot(5,1,5);loglog(Ebn,BER,'r.-');axis([0 20 0 5*10^(-1)]);title('Eb/N0 vsber(bask)');xlabel('Eb/N0');ylabel('BER');

BFSKx=input('enter the input stream ');n=length(x);f1=3;f2=5;t=0:0.01:1;time=[];fsk_sig=[];dig_sig=[];for i=1:ndig_sig =[dig_sig (x(i)==0)*zeros(1,length(t))+(x(i)==1)*ones(1,length(t))];fsk_sig=[fsk_sig (x(i)==0)*sin(2*pi*f1*t)+(x(i)==1)*sin(2*pi*f2*t)];time=[time t]; t=t+1;end;%carriersubplot(5,1,1);plot(time,sin(2*pi*3*time));xlabel('time');ylabel('amplitude');title('carrier1');axis([0 time(length(time)) -2 2]);subplot(5,1,2);plot(time,sin(2*pi*5*time));xlabel('time');ylabel('amplitude');title('carrier 2');axis([0 time(length(time)) -2 2]);%input bit streamsubplot(5,1,3);plot(time,dig_sig);xlabel('time');ylabel('amplitude');axis([0 time(length(time)) -1 2]);title('input bit stream');%modulated carriersubplot(5,1,4);plot(time,fsk_sig);xlabel('time');ylabel('amplitude');axis([0 time(length(time)) -2 2]);title('bfsk modulated signal');%bit error rateEbn=[0:.5:15];BER= berawgn(Ebn,'fsk',2,'coherence');subplot(5,1,5);loglog(Ebn,BER,'r.-');axis([0 20 0 5*10^(-1)]);title('Eb/N0 vs BER(bfsk)');xlabel('Eb/N0');ylabel('BER');BPSKx=input('enter the input stream ');n=length(x);f=3;t=0:0.01:1;time=[];psk_sig=[];dig_sig=[];for i=1:ndig_sig =[dig_sig (x(i)==0)*zeros(1,length(t))+(x(i)==1)*ones(1,length(t))];psk_sig=[psk_sig (x(i)==0)*(-1)*sin(2*pi*f*t)+(x(i)==1)*sin(2*pi*f*t)];time=[time t]; t=t+1;end;%carriersubplot(4,1,1);plot(time,sin(2*pi*3*time));xlabel('time');ylabel('amplitude');title('carrier');%input bit streamsubplot(4,1,2);plot(time,dig_sig);xlabel('time');ylabel('amplitude');axis([0 time(length(time)) -1 2]);title('input bit stream');%modulated carriersubplot(4,1,3);plot(time,psk_sig);xlabel('time');ylabel('amplitude');axis([0 time(length(time)) -2 2]);title('bpsk modulated signal');

PERFORMANCE COMPARISON%bit error rateEbn=[0:.5:15];BER= berawgn(Ebn,'psk',2,'diff');subplot(5,1,5);loglog(Ebn,BER,'r.-');axis([0 20 0 5*10^(-1)]);title('Eb/N0 vsber(bask)');xlabel('Eb/N0');ylabel('BER');Ebn=[0:.5:15];BER= berawgn(Ebn,'pam',2);loglog(Ebn,BER,'r.-');grid on;hold on;BER= berawgn(Ebn,'fsk',2,'coherence');loglog(Ebn,BER,'g*-');hold on;BER= berawgn(Ebn,'psk',2,'diff');loglog(Ebn,BER,'b.-');axis([0 20 0 5*10^(-1)]);legend('BASK','BFSK','BPSK');title('performance comparison of bask, bfsk and bpsk');xlabel('Eb/N0');ylabel('BER');

OUTPUT WAVEFORMSBASKEnter the input stream [1 0 1 0]

Fig. 1BPSKEnter the input stream [1 0 1 0]

Fig. 2BFSKEnter the input stream [1 0 1 0]

Fig. 3PERFORMANCE COMPARISON

RESULTBASK, BFSK, BPSK digital modulation schemes were implemented in MATLAB and compared the bit error rate of these modulation schemes. Exp No: 231/10/2013SCATTERPLOT OF ASK, PSK & FSKAIMTo generate scatterplot of ASK, PSK, FSK modulated and demodulated signals with and without effect of noise.SOFTWARE USEDMATLAB 7.1THEORYA scatterplot or constellation diagram is a representation of a signal modulated by a digital modulation scheme such as amplitude-shift keying (ASK), phase-shift keying (PSK) and frequency-shift keying(FSK). Measured constellation diagrams can be used to recognize the type of interference and distortion in a signal. The points on a constellation diagram are called constellation points. A constellation diagram can help us define the amplitude and phase of a signal element, particularly when we are using two carriers. In a constellation diagram, a signal element type is represented as a dot. The bit or combination of bits it can carry is often written next to it. The diagram has two axes. The horizontal X axis is related to the in-phase carrier; the vertical Y axis is related to the quadrature carrier.ASKA binary amplitude-shift keying (BASK) signal can be defined bys(t) = A m(t) cos(2fct) ; 0 0, if for k =0, 1, 2, ... the probability distribution function(pdf) of X is given by:

Where is equal to the expected value or mean of X and also to its variance,

The cumulative distribution function (cdf) is given as,

Figure 1 shows the pdf & cdf of poisson distributions.

Fig.1. PDF & CDF of poisson distributionsThe poisson distribution arises in some problems involving counting, for example, monitoring the number of telephone calls arriving at a switching center during various intervals of time. In digital communication, poisson distribution is pertinent to the problem of transmission of many data bits when the error rates are low.BINOMIAL DISTRIBUTIONInprobability theoryandstatistics, thebinomial distributionis thediscrete probability distributionof the number of successes in a sequence ofnindependentyes/no experiments, each of which yields success withprobabilityp. The binomial distribution is the basis for the popularbinomial testof statistical significance. The binomial probability density function for a given valuexand given pair of parametersnandpis

where, q=1-pThe result,y, is the probability of observingxsuccesses innindependent trials, where the probability of success in anygiventrial isp. the indicator functioni(0,1,...,n)(x) ensures thatxonly adopts values of 0, 1, ...,n..The cumulative distribution function can be expressed as:

GAUSSIAN / NORMAL DISTRIBUTIONThe gaussian(or normal) distribution is a very commonly occurring continuous probability distributiona function that tells the probability that an observation in some context will fall between any two real numbers. The normal distribution is immensely useful because of the central limit theorem, which states that, under mild conditions, the mean of many random variables independently drawn from the same distribution is distributed approximately normally, irrespective of the form of the original distribution: physical quantities that are expected to be the sum of many independent processes often have a distribution very close to the normal. Moreover, many results and methods can be derived analytically in explicit form when the relevant variables are normally distributed. The Gaussian distribution is sometimes informally called the bell curve. PDF of normal distribution is

The parameter in this definition is the mean or expectation of the distribution & its variance is 2. A random variable with a Gaussian distribution is said to be normally distributed and is called a normal deviate. If = 0 and = 1, the distribution is called the standard normal distribution or the unit normal distribution, and a random variable with that distribution is a standard normal deviate.Figure 2 shows the pdf&cdf of gaussian distributions,

Fig.2. PDF & CDF of gaussian distributionsPROCEDURE1. Create a random variable that varies between some ranges2. Using MATLAB functions ,compute the CDF and PDF for various distributionsa) For Poisson PDF use MATLAB function poisspdf and for CDF use poisscdf. b) For Gaussian PDF use normpdf and for CDF normcdf. c) For binomial PDF use binopdf and for CDF binocdf. 3. Plot the graphs.PROGRAMclc;clear all;%pdf of normal distributionr=random('normal',0,1,1000,1)y=normpdf(r,0,1);subplot(6,1,1);plot(r,y,'*');title('pdf of normal distribution');xlabel('time'); ylabel('PDF');% generate binomial pdfx=0:10;z=binopdf(x,10,0.5);subplot(6,1,2);plot(x,z,'-');title('pdf of binomial distribution');xlabel('time'); ylabel('PDF');

%generate the poissonpdf x = 0:15;y = poisspdf(x,5);subplot(6,1,3);plot(x,y,'+');title('pdf of poisson distribution');xlabel('time'); ylabel('PDF');

%cdf of normal distributionr=random('normal',0,1,1000,1)t=normcdf(r,0,1);subplot(6,1,4);plot(r,t,'*');title('cdf of normal distribution');xlabel('time'); ylabel('CDF');

%cdf of binomial distributionw=binocdf(x,10,0.5);subplot(6,1,5);plot(x,w,'-');title('cdf of binomial distribution');xlabel('time'); ylabel('CDF');

%cdf of poissonx=0:10;z=poisscdf(x,5);subplot(6,1,6);plot(x,z,'+');title('cdf of poisson distribution');xlabel('time'); ylabel('CDF');OUTPUT WAVEFORMS

RESULTThe PDF & CDF of Poisson distribution, Binomial distribution& Gaussian distribution were plotted.Exp No: 929/1/2014INTRODUCTION TO NS2AIMTo get familiarised with Network simulator-2 SOFTWARE USED Linux THEORYNetwork Simulator (Version 2), widely known as NS2, is simply an event driven simulation tool that has proved useful in studying the dynamic nature of communication networks. Simulation of wired as well as wireless network functions and protocols (e.g., routing algorithms, TCP, UDP) can be done using NS2. In general, NS2 provides users with a way of specifying such network protocols and simulating their corresponding behaviours. NS2 provides users with executable command ns which take on input argument, the name of a Tcl simulation scripting file. Users are feeding the name of a Tcl simulation script (which sets up a simulation) as an input argument of an NS2 executable command ns. In most cases, a simulation trace file is created, and is used to plot graph and/or to create animation. NS2 consists of two key languages: C++ and Object-oriented Tool Command Language (OTcl). While the C++ defines the internal mechanism (i.e., a backend) of the simulation objects, the OTcl sets up simulation by assembling and configuring the objects as well as scheduling discrete events (i.e., a frontend). The C++ and the OTcl are linked together using TclCL. There are three steps in defining a simulation scenario in a NS2. PROCEDUREStep 1 - simulation designThe first step in simulating a network is to design the simulation. In this step, the users should determine the simulation purposes, network configuration and assumptions, the performance measures, and the type of expected results.Step 2 - configuring and running simulationThis step implements the design in the first step. It consists of two phases:1. Network configuration phase: In this phase network components (e.g.,node, TCP and UDP) are created and configured according to the simulation design. Also, the events such as data transfer are scheduled to start at a certain time.2. Simulation Phase: This phase starts the simulation which was configured in the Network Configuration Phase. It maintains the simulation clock and executes event chronologically. This phase usually runs until the simulation clock reached a threshold value specified in the Network Configuration Phase.Step 3 - post simulating processingThe main tasks in this steps include verifying the integrity of the program and evaluating the performance of the simulated network.PROGRAMset ns [new Simulator]

settr [open second.tr w]

$ns trace-all $tr

setnf [open out.nam w]

$ns namtrace-all $nf

proc finish {} {puts "Complete";exit 0}

set n0 [$ns node]

set n1 [$ns node]

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0set sink0 [new Agent/TCPSink]$ns attach-agent $n1 $sink0$ns connect $tcp0 $sink0$ns at 0.5 "$ftp0 start"$ns at 4.5 "$ftp0 stop"$ns at 5.0 "finish"$ns runRESULT Thus familiarized with network simulator 2 and verified the output.

COMMUNICATION SYSTEM ENGINEERING LABPage 1