Lab # 1 Introduction To Communications Principles Using Matlab
Lab # 1 Introduction To Communications Principles Using Matlab
Lab # 1 Introduction To Communications Principles Using Matlab
Using Matlab
OBJECTIVES:
The purpose of this Lab is to review MATLAB for those that have used it before, and to
provide a brief introduction to MATLAB for those that have not used it before. After using this
lab session, you should be able to:
Enter matrices
Perform matrix operations
Make plots
Use MATLAB functions
Write simple m-files
Signal Generation in MATLAB
PRE-LAB:
MATLAB is an interactive program for numerical computation and data visualization. It was
originally developed in FORTRAN as a Matrix Laboratory for solving numerical linear algebra
problems. The original application may seem boring (except to linear algebra enthusiasts), but
MATLAB has advanced to solve nonlinear problems and provide detailed graphics. It is easy to
use, yet very powerful. A few short commands can accomplish the same results that required a
major programming effort only a few years ago. MATLAB features a family of add-on application-
specific solutions called toolboxes. These toolboxes allow you to learn and apply specialized
technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend
the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are
available include communications, signal processing, control systems, neural networks, fuzzy
logic, simulation, and many others.
Starting MATLAB
On Windows platforms, start MATLAB by double-clicking the MATLAB shortcut icon on your
Windows desktop.
Signal’s representation
A signal in MATLAB is represented by a row vector:
Examples:
>> x = [2, 3, -5, -3, 1]
>> n = 2:17 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17]
Default step size is 1
>> n = 2:3:17 = [2, 5, 8, 11, 14, 17]
where xdata and ydata are vectors containing the data. Note that xdata and ydata must be the same
length and both must be the same type, i.e., both must be either row or column vectors. Additional
arguments to the plot command provide other options including the ability to plot multiple data
sets, and a choice of colors, symbols and line types for the data.
PRE-LAB:
Example
Plot the following signal
>> x = 10sin π t
MATLAB CODE:
clear all
close all
clc
t = [-2:0.002:2];
x = 10 * sin (pi * t)
plot(t , x)
title('Example Sinusoid')
xlabel('time(sec)')
ylabel('Amplitude')
MATLAB FIGURE :
MATLAB CODE :
clear all % to clear all simulations
close all
clc
x = 0:pi/30:2*pi; % x vector, 0 <= x <= 2*pi, increments of
pi/30
y = sin(3*x); % vector of y values
plot(x,y) % create the plot
xlabel('x (radians)'); % label the x-axis
ylabel('sine function'); % label the y-axis
title('sin(3*x)'); % put a title on the plot
MATLAB FIGURE :
Figure 1: sinusoidal signal having three cycles in it and time period is same as in above figure 2 sec.
MATLAB CODE :
clear all % to clear all simulations
close all
clc
MATLAB FIGURES :
Figure 1:above figure represent the discrete value graph having value on absolute time axis(values).
Figure 2:above figure represent the discrete value graph with defined horizontal axis.
UNIT IMPULSE :
MATLAB CODE :
clear all % to clear all simulations
close all
clc
Figure 2:above figure represents the unit impulse signal (discrete valued).
UNIT STEP :
MATLAB CODE :
clear all % to clear all simulations
close all
clc
n=-5:5; %n number of samples to plot unit impulse
stem (n, [zeros(1,5) ones(1,6)]) %command used to plot discrete values
title('unit step function')
xlabel('number of samples')
ylabel('amplitude')
MATLAB FIGURE :
MATLAB CODE :
MATLAB FIGURE :
Figure 1: Above figure represent the unit ramp signal having increasing order (x(t) = t).
EXPONENTIAL FUNCTION :
MATLAB CODE :
clear all % to clear all simulations
close all
clc
Figure 1:Above figure represent the exponential signal graph. The signal espreession is (x(t) = exp(t)).
LAB-TASKS :
TASK 1 :
Create a symbol plot with the data generated by adding noise to the given function:
y = 5*x.*exp(-3*x) Where x = 0:0.01:2;
MATLAB CODE :
clear all
close all
clc
Figure 1:Above figure represent the original signal and noisy signal. Blue line signal is a real original (exponential
signal) and red line signal in which we add noise in original signal.
Examples:
Sinusoidal signals:
MATLAB CODE :
clear all
close all
clc
MATLAB FIGURE :
Figure 1: This figure represent the three different sinusoidal signal of different amplitude and frequency using FOR
loop.
Figure 2: Above figure also represent the three sinusoidal signal of different amplitude and frequency. These plots are obtain by
using plot command for multiple graphs in single figure.
SIGNUM FUNCTION :
MATLAB CODE :
clear all
close all
clc
% signum funnction
MATLAB FIGURE :
Figure 1: This figure represent the signum function graph having value -1 and 1 as amplitude.
MATLAB CODE :
clear all
close all
clc
A=3; %amplitude
f0=1/10; %frequency of the square wave
T0=1/f0; %duration of single pulse
t=[-T0/2:0.01:T0/2] %range is fixed for one symbol duration
%implementation of square wave.
for k=1:length(t) %using loop to get values (repeatedly)
if (abs(t)<=T0)
x(k)=A;
else
x(k)=0;
end
end
%to connect the last point to zero to give a rectangular shape
%also experiment with the plot properties to see the wave
y=[0,x,0];
t=[-T0/2,t,T0/2];
figure();
plot(t,y)
xlabel('time axis')
ylabel('amlitude axis')
title('square wave')
MATLAB FIGURE :
MATLAB CODE :
clear all
close all
clc
Figure 1:Above figure represent the scaling operation of the signal.blue line signal is a original sinal and red line signal is a
scaled signal.
Figure 2:Above figure represent the amplitude change of sinusoidal signal.the impact of amplitude changing is described in this
diagram.
Figure 3:Above figure represent the addition operation of the two different signals.
Figure 4: This figure represent the modulation of te real signal. In modulation the real signal is multiply with carrier signal to
shift the original signal to carrier signal frequency.
Task A: Manipulating Sinusoids with MATLAB: In this task, you will generate
sinusoids with different characteristics (amplitudes and frequencies), and their composite signal.
Perform different steps as mentioned below.
MATLAB CODE :
clear all
close all
clc
% first sinusoid
% second sinusoid
% third sinusoid
% fourth sinusoid
% fifth sinusoid
MATLAB FIGURE :
Figure 1: Above figure represent the five different sinusoidal signal using indiviousual calculation of all five signal. The last
graph represent the summation of all the previous ffive sinusoidal signals.
MATLAB CODE :
clear all % commands used to remove all previous simulations
close all % to remove previous graphs
clc
A = [2 3 1 1.5 2.5]; % initializing the amplitudes
F = [1 3 2 5 12]; % different frequencies of sinusoidals
sum = 0; % a dummy veriable
MATLAB FIGURES :
Figure 2: This figure shows the five different sinusoidal signal same as above but in this case we use FOR loop to calculate the
values. In last graph the summation of all the sinusoidal signal graph is represented.
% fourier transform
subplot(2,1,2)
plot(z1)
title('result after ifft of resulting signal')
xlabel('time axis')
ylabel('amplitude')
x1 = ifft(X); %inverse fourier of first signal
y1 = ifft(Y); inverse fourier of second signal
MATLAB FIGURES :
Figure 1: This figure shows the convolution of two rect. Signal and represents the resultant tranglur signal in the last graph.
Figure 2: Above figure shows the convolution but this was obtained by the inverse fourier transform.if we take fourier
transform of both the signal and multiply them. The resultant signal inverse fft gives the same result as convolution.
Q. Convert back the output signal into time domain, and compare both outputs.
A. Both signals have same amplitude and same number of sample on time axis, so this states that
if we convolve two signal in time domain will also equal to that process in which if we first take
fft of time domain signal and then multiply both signal and taking inverse of that resulted
signal.the whole process is established for the reason that multiplication is quite easy in
comparison of convolution.
A. We add extra zero’s at the end of a vector or defined function manually so that we can match
the dimensions/lengths of the function.
f = 1/t or f = 1/n
inverse relation exist between frequency and number of samples.
CRIRITICAL ANALYSIS :
In this lab we learnt about the fundamental concepts and basics of the
MATLAB to obtain the basics of communication signals. In In-lab task we observe the real
massage signal of exponential form and then we observed the noisy signal. We observed that the
real signal we obtained is identical and is form of exponential type and can be extracted on the
receiver side without involvement of noise. Then we add some noise in the real original signal
using random function. Random function take random values for all the samples and add these
values to the original signal, so that every sample of the original signal distorted and randomize
the signal. After getting the noisy signal we can’t predict what is the real shape of the original
signal at the receiver end so that’s why we try to eliminate noise from the desired systems. After
this task we perform certain operation on the given signal in In-Lab. We perform scaling of the
signal by which we change the amplitude ofdifferent signal and by plotting these signals we
observe how amplitude of different signal varies, we also perform addition and modulation of
different signal. Addition is quite same as we add two different number but modultion is a
important parameter. In modulation we multiply two signals and gets the resultant signal. The
resultant signal obtained the frequency which is higher in both multiplicated signal and the
amplitude of the resultant signal varies accordingly.
In Post-Lab task first we generate five different sinusoidal signal having
different amplitude and frequency. As the frequency of the signal increases the number of cycles
or repetition increases in every sinusoidal graph and amplitude changing only impacts on the peek
values. One important part of this is the addition of all the five different sinusoidal signal, we
observe that we get a random signal which didn’t have a particular behavior. Then we use FOR
loop to implement same functionality and we see that by using FOR loop it is quite easy and simple
to obtain the desired output rather than we implement every signal indiviously . inn the last task
we have to perform convolution and we see that when two different rectangle signal gets convolve
we get a triangle signal in result. First we used conv command to get the desired ouptput and then
we use the fourier transform method. If we take fft of the given two signal and multiply the
resultant signal, and then by taking inverse fourier transform we get the same result as of
convolution. So the reason of all this procedure is that the multiplication is easier than convolution
and we have to create ease in signal operations thats why we use fourier transform.
So after this lab we are very much familiar with basic building blocks of the MATLAB and the
fundamental concept of different signal operations.