Cmslab Manual - 1
Cmslab Manual - 1
LAB MANUAL
INTRODUCTION TO MATLAB
Objectives:
Pre-lab theory:
What is MATLAB?
MATLAB is a software program that allows you to do data manipulation and visualization, calculations,
math and programming. It can be used to do very simple as well as very sophisticated tasks. It
can solve large systems of equations efficiently and it is therefore useful for solving differential
equations and optimization problems. It also provides excellent means for data visualization and has
symbolic capabilities. Whilst simple problems can be solved interactively with MATLAB, its real
power shows when given calculations that are cumbersome or extremely repetitive to do by hand!
MATLAB is recognized as the interactive program for numerical linear algebra and matrix
computation. In industries, MATLAB is used for research and to solve practical engineering and
mathematical problems. Also, in automatic control theory, statistics and digital signal processing (Time-
Series Analysis) one can use MATLAB. The following tool boxes make it useful in soft computing at
various industrial and scientific areas:
(i) Neural Networks (ii) Optimization (iii) Genetic Algorithms (iv) Wavelets (v) Fuzzy Logic
(vi) Control systems (vi) Signal processing (vii) Communication Systems
Starting MATLAB
After logging into your account, you can enter MATLAB by double-clicking on the MATLAB shortcut
icon on the Window. After starting MATLAB, the MATLAB Desktop will appear. The default
three-part window looks similar to the figure below. The Desktop is also known as an Integrated
Development Environment (IDE). Clicking the Start button in the lower left-hand corner will display
a list of MATLAB tools, shortcuts, and documentation.
display(a)
display(b)
display(c)
[ 12 3
1+2 i ]
2. Use MATLAB to compute: 6(35^1.4)+14^0.35
Solution:
We can write it as:
clc
clear all
e=6*35^1.4+14^0.35;
display(e)
It displays the result:
e=
873.1743
3. Define a 4x3 matrix with zeros everywhere except the first line that is filled with 1. Hint= use
ones and zeros command
Solution:
First we define 4x3 matrix then make it null matrix by replacing the rows and columns with zero. Then
using the same command for the replacement of first row from zero to one. Code is given below:
clc
clear all
close all
syms m;
matrix=[2,4,3;24,3,4;6,5,4;7,4,3];
display(matrix);
matrix(:,:)=0;
display (matrix);
matrix([1],:)=1;
display(matrix);
It displays the following result:
First matrix is matrix which we introduce, second one is null matrix and third one is required matrix.
matrix =
2 4 3
1 1 1
0 0 0
0 0 0
0 0 0
clc
clear all
close all
syms xyz;
A=[6 -4 8; -5 -3 7; 14 9 -5];
%X=[x;y;z];
B=[112;75;-67];
C=1./A;
X=C*B;
display(X);
Result that we get from above code is as follows:
X=
-8.4583
-56.9714
29.7333
5. Use MATLAB to find roots of 13x3 + 182x2 – 184x +2503 = 0
Solution:
To find the rootes of equation we just make its matrix and then apply command of ‘roots()’ which gives
roots in matrix form. Code for above equation is:
clc
clear all
close all
syms x;
A=[13 182 -184 2503];
r=roots(A);
display(r);
LAB 01-B
INTRODUCTION TO PLOTTING COMMAND ON MATLAB
Objectives:
Pre-lab theory:
MATLAB is very useful for making scientific and engineering plots. You can create plots of known,
analytical functions, you can plot data from other sources such as experimental measurements, and you
can analyze data, perhaps by fitting it to a curve, and then plot a comparison. MATLAB also has powerful
built-in routines for drawing contour and three-dimensional surface plots.
Two-dimensional line and symbol plots are created with the plot command. In its simplest form plot takes
two arguments
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.
1. Use MATLAB to plot the functions y=4√(6x+1) and z=5e0.3x – 2x over the interval 0<x<1.5
Solution:
Code for plot of above two functions is:
clc
clear all
x=0:0.1:1.5;
y=4*sqrt(6*x+1);
z=5*exp(0.3*x)-2*x;
plot(x,y,'r');
2. Use MATLAB to plot function s= 2 sin (3t+2) + √(5t+1) over the interval 0<t<5.
Solution:
Code for above function is:
clc
clear all
close all
symst;
t=0:0.1:5;
s=2*sin(3*t+2)+sqrt(5*t+1);
plot(t,s);
xlabel('t');ylabel('s=2sin(3t+2)+?(5t+1)');
gtext('s=2sin(3t+2)+?(5t+1)');
title('Q4');
It gives the graph:
4. Plot the function y= (4/Π) [(sin x) + (sin 3x)/3 + (sin 5x)/5 + (sin7x)/7] over the interval –Π<x<Π.
These are the first four terms of the Fourier Series representation of a square wave.
Solution:
Code for this function is as follows:
clc
clear all
close all
syms x;
x=-pi:0.1*pi:pi;
y=(4/pi)*[sin(x)+(sin(3*x)/3)+(sin(5*x)/5)+(sin(7*x)/7)];
plot(x,y,'r');
title('Q6');
xlabel('Pi');ylabel('y=(4/pi)*[sin(x)+(sin(3*x)/3)+(sin(5*x)/5)+(sin(7*x)/7)]');
Objectives:
(a) Learn time domain representation of various discrete signals
(b) Learn and implement amplitude and continuous time scaling techniques
(c) Learn and implement time shifting techniques.
Time Shifting:
Time shifting by t0corresponds to the transformation:g(t) → g(t-t0) where, t0 is the time shift. If t0>0, the
waveform g(t) is obtained by shifting towards the right, relative to the time axis. If to<0, g(t) is shifted to
the left.
Time Scaling:
Time scaling corresponds to the transformation: g(t) → g(t/a), If a>0, t→ t/aexpands the function
horizontally by a factor of a.The figure compares g(t) and g(t/2).
LAB TASKS:
1) Consider the following signal X(t)=sin(2πft)
where f=1Hz
t=0→2
Write the MATLAB code to implement the following functions
A. 2X(t)
B. X(t-2)
C. X(t/2)
D. X(-t)
2) Draw the sum of signals.
10
−5
( t )=∑ *cos(2*pi*n*f*t)
n=1 2∗pi
WhereT= 2 ms and we wish to show the signal for 10 ms.Thus, f = 1/T = 5000Hz
MATLAB Code:
%Draw the sum of signals.
clc
clearall
closeall
del_t = 0.02e-3;
t=0:del_t:10e-3; %creates a 1 x 501 row vector of time points
n=(1:10).'; % creates a 10x1 column vector of integers 1 to 10
COS=cos((n*t)*2*pi*500);
plot(t,COS(1,:))
plot(t,COS(2,:))
A=-5./(pi*n.^2);
x=sum(A(:,ones(1,501)).*COS);
plot(t,x)
Increasing power will lead to more capacity. However, as the increase in capacity is logarithmic function
of power, the returns are diminishing.
MATLAB Code:
%Capacity with increasing signal power
clc
clearall
closeall
B=1;
N0=1;
P=[0:10^4];
C=B.*log2(1+P./( N0*B));
plot(P,C);
xlabel('Power,P');
ylabel('capacity,C bit/sec');
title('Capacity vs Power')
Increase the noise and bandwidth one by one and observe the results.
Background:
Power and Energy content of a signal is often calculated in signal processing for communication
applications. Gaussian noise is statistical noise that has a probability density function (abbreviated pdf) of
the normal distribution (also known as Gaussian distribution). In other words, the values that the noise
can take on Gaussian-distributed. It is most commonly used as additive white noise to yield additive white
Gaussian noise (AWGN). Gaussian noise is properly defined as the noise with a Gaussian amplitude
distribution, says nothing of the correlation of the noise in time or of the spectral density of the noise.
Labeling Gaussian noise as 'white' describes the correlation of the noise.
Task 01:
Task 02:
Task 03:
LAB 03-B
SQUARE WAVE SYNTHESIS, CONDITIONALS AND LOOPS
Objective:
This lab gives the idea of implementation of programming (if-else, loops) in MATLAB also it tells us
how to find integrals and derivatives.
LAB TASK 1:
Write a code that take an input from user and display its required waveform
a=input('please enter \n 1 for sawtooth \n 2 for unit step \n 3 for impulse \n 4 for rectpulse \n or any other
number for all graphs: \n')
global t n h s q u w p;
t=-10:0.001:10;
n=-10:10;
h=-10:10;
s=-3:0.001:3;
p=sawtooth(t);
u=[zeros(1,10) ones(1,11)];
q=[zeros(1,10) 1 zeros(1,10)];
w=rectpuls(s*0.5);
if(a==1)
plot(t,p);
xlabel('t'); ylabel('Sawtooth');
else
if(a==2)
stem(n,u,'.','r');
xlabel('n'); ylabel('unit step');
else
if(a==3)
stem(h,q,'.','g')
xlabel('t'); ylabel('Impulse');
else
if(a==4)
plot(s,w)
xlabel('t'); ylabel('Rectpulse');
end
end
end
Output we get.
LAB TASK 3:
Using while loop write a code that will display a series even or odd numbers.
a=input('enter 1 for even numbers 2 for Odd numbers')
global e;
e=0;
while e<20; %loop
if a==1
R=rem(e,2); %to get remainder
LAB TASK 1:
Q1: Take 1st , 2nd , 3rd , order derivative of function
f(x)= x2cos(x)+xsin(x)2
Output is:
%f(x)=xsin(x)2
clc
clearall
closeall
symsx;
f = x*sin(x^2);
fprintf'Integral is \n\n'
a=int(f,x);
pretty(a)
OUTPUT:
LAB TASK 3:
Q3:Evaluate integral
1
2∫sin(x)2dx
clc
symsx;
f = sin(x)^2;
a=int(f,x,1,2);
pretty(a)
OUTPUT:
7th harmonic:
V=5; %the peak voltage
f0 = 1000; % Fundamental frequency in Hertz
w0 = 2*pi*f0; % Fundamental frequency in radians
T=1/f0; % the period of the square wave
D=0.5; % pulse duty ratio
% plotting a square wave
dT=T/512; % incremental time,
t1=0:dT:D*T-dT; % Positive half period
t2=D*T:dT:T-dT; % Negative half period
t=[t1 t2]; %One complete period
v=V*square(w0*t); % keyword to generate a square wave in MATLAB
V0=0;
V1= 4*V/pi;
V3= 4*V/(3*pi);
V5= 4*V/(5*pi);
V7= 4*V/(7*pi);
V9= 4*V/(9*pi);
v1 = V0+V1*sin(w0*t); % First (fundamental) harmonic
v13 = v1+V3*sin(3*w0*t); % First + Third harmonic
v135 =v13+V5*sin(5*w0*t); % First +Third +Fifth harmonic
v1357=v135+V7*sin(5*w0*t); %first+third+fifth+seventh
subplot (2,2,1)
plot(t,v,t,v1357)
title('7th harmonic')
OUTPUT:
99th harmonic:
clc
V=5;
f0 = 1000;
w0 = 2*pi*f0;
Objective:
Description:
Correlation is the process that qualifies the degree of inter-dependence of one process upon another or
measures the similarity between one set of data and other. Correlation is of two types: Cross-correlation
and Auto Correlation. It is implemented in MATLAB by the command “xcorr”, provided that two
sequences be convolved are of finite length.
Task 1 :
1. Apply auto-correlation on x1 without using build in Matlab function and plot the output.
2. Apply time shifting (no=2 )to the signal x1 and save the output in vector x2. Plot the output.
Implementation of build in MATLAB command of correlation is not allowed.
3. Now, apply autocorrelation on signal x2 and plot the output graphs.
4. Observe and write down your conclusion.
Task 02:
X(t)=cos(2π3t)
LAB 04-B
POWER SPECTRAL DENSITY
Objective:
Description:
The power spectral density (PSD) of the signal describes the power present in the signal as a function of
frequency, per unit frequency. Power spectral density is commonly expressed in watts per hertz (W/Hz).
An important relationship between the Autocorrelation of a signal g(t) and Power Spectral Density Ψg(τ )
Task 1:
Task 02:
Plot the Power Spectral Density for the Gaussian noise generated for 50 number of samples.
Also find out fourier series and fourier transform for the above signal.
Also plot the output.
Plotting signal :
g1 = [0 :1 / 3 2 :1 − ( 1 / 3 2 ) ] ;
g2 = [ − 1 :1 / 3 2 :1 − ( 1 / 3 2 ) ] ;
g3 = [ − 1 :1 / 3 2 :0 − ( 1 / 3 2 ) ] ;
g = [ g1 , g2 , g3 ] ;
t = [ − 1 :1 / 6 4 :1 − ( 1 / 6 4 ) ] ;
p lo t ( t , g ) ;
a x i s ( [ − 1 .5 1 .5 −1.5 1 . 5 ] )
g r id
The above approach uses the Matlab commands FFT and FFTSHIFT. Now by directly using the formula
we can also obtain the plot with the help of following code segment.
m=128;
a=1;
f o r n = − m/ 2 : 1 :m/2−1
i f n == 0
Dn( a ) = 0 ;
else
Dn=( i ∗ (( −1) . ˆ n ) ) / ( n ∗ p i ) ;
end
a = a +1;
end
n = − m/ 2 :m/2 −1;
stem ( n , abs (Dn) )
Magnitude and phase of Dn can also be obtained as follows.
magDn = abs (Dn) ;
argDn = a n g le (Dn) ;
stem ( f ,magDn) ;
stem ( f , argDn ) ;
Comments:
1. FFT function plot the fourier series but with the DC component.
LAB 05-B
Plot the magnitude | Dn| (in volts) and phase Dn (in degrees) of the first twenty-one
2. Plot two periods of g(t) , directly i.e., by creating a vector of samples of g(t) and plotting
that vector.
3. Plot an approximation to g(t) using these first twenty-one terms of the exponential Fourier
series.
f u n c t io n y = s in c 1 ( x ) % s i n c f u n c t io n implement a t io n
k = le n g t h ( x ) ;
fori=1:k
f x ( i ) == 0
y(i)=1;
else
y ( i ) = s i n ( x ( i ) ) /x ( i ) ;
end
end
n = [ − 1 0 :1 0 ]; % s e t s up t he v e c t o r o f i n t e g e r i n d i c e s .
z=n∗(pi/4);
Dn = 0 .2 5 ∗ exp (− i ∗ z ) . ∗ s in c 1 ( z ) ; % s in c 1 ( ) i s d e f in e d above .
w = 0 .5 ∗ n ;
g r id
t i t l e ( ’ Magnitude o f t he Ex p o n e n t ia l Fo u r ie r S e r i e s C o e f f i c i e n t s ’ )
ylabel(’degrees’)
g r id
t i t l e ( ’ Phase o f t he Ex p o n e n t ia l Fo u r ie r S e r i e s C o e f f i c i e n t s ’ )
The signal g(t) can be reconstructed by adding the Fourier coefficients. To verify this we find
n = [ − 1 0 :1 0 ];
z=n∗(pi/4);
multiplication
nwo = n ∗ ( p i / 2 ) ; % d e f i n e e le v e n f r e q u e n c i e s f o r sum
t = [ 0 : 0 . 0 1 : 8 ] ; % d e f i n e time s a mpling p o in t s
p lo t ( t , r e a l ( g ) ) , g r id , x l a b e l ( ’ Seconds ’ )
t i t l e ( ’ Approximation t o g ( t ) u s in g t he f i r s t t en components o f t he Fo u r ie r
series’)
code is used to generate two periods of function g(t). It uses a custom made unit step function,
u(t), a copy of which is also provided below. The ability to use the unit step function to write
p lo t ( t , g t )
g r id , x l a b e l ( ’ s e c o n d s ’ )
t i t l e ( ’ The r e a l g ( t ) ’ )
a x i s ( [ 0 8 −0.2 1 . 2 ] ) ;
f u n c t io n [ y ] = u ( x )
y =0.5+0.5 ∗ s ig n ( x ) ;
end
FOURIER TRANSFORM
Objective:
This lab related to the implementation of Fourier Transform in MATLAB. This lab is also related to
remove noise (high freq. signal) from message signal.
LAB TASK 1:
Why is the output of the second plot like this? Find a better range for t to plot sin(20*pi*t) right. Can you
find a good lower bound for the sampling interval in terms of the frequency?
clc
clear; close all
t = 0:0.1:10;
y1 = sin(2*pi*t);
y2 = sin(2*pi*10*t);
subplot(2,1,1)
plot(t,y1,'r');
holdon;
plot(t,y2);
subplot(2,1,2)
plot(t,y2)
We observe that second plot i.e. y2=sin(20*pi*t) have magnitude of exp(-14) which is minimum as
compared to y1=sin(2*pi*t). y2 is consider as noise. When we plot both y1 and y2, the graph of y2 is
approximately at zero.
If we take our time interval low then y2 can be plot and can be visualize in more better way.
MATLAB Code for this is given below:
clc
clear; close all
t = 0:0.01:3;
y1 = sin(2*pi*t);
y2 = sin(2*pi*10*t);
subplot(2,1,1)
plot(t,y1,'r');
holdon;
plot(t,y2);
subplot(2,1,2)
plot(t,y2)
LAB TASK 2:
Give the MATLAB commands to plot the amplitude spectrum for the signal.
LAB TASK 3:
Make a function to plot waveform and amplitude spectrum of a signal. The function has prototype:
functionspecplot ( t, dt, et, y )
% % Opens a new figure window with two plots:
% the waveform and amplitude spectrum of a signal.
% % On entry :
% t sampling range of the signal;
% dt sampling rate;
% et end of the range;
% y samples of the signal over the range t.
% Sospecplot computes the amplitude spectrum of the signal.
clc
clearall
closeall
dt = 1/100; % sampling rate
et = 4; % end of the interval
t = 0:dt:et; % sampling range
sum=0;
for k=10:20
y=(20-k)*sin(2*pi*k*t);
Description:
Our focus in this session will be on using MATLAB for simulating communication systems. How to use
full wave rectifier and filters on MATLAB. A filter in MATLAB is represented by its transfer function.
The transfer function is in general in the form of the division of two polynomials. The filter is completely
defined by the coefficients of the polynomial at the numerator and the polynomial at the denominator.
These are the vectors a and b respectively in the program.
There are many realizations for designing filters. One common realization is Butterworth, which is the
one used here, hence the function name butter.
The butter function has two arguments. The first argument is the order of the filter. The larger the order
the sharper the filter (closer to ideal), but more processing is required. For most of our applications an
order of 3-5 should be sufficient.
The second argument is a coefficient related to the cutoff frequency. Without going into the details of the
derivation, to design a LPF filter of cutoff frequency W, the argument should be set to 2*W*ts, where ts
is the time step size of the program. For more details about the command butter , type:
To apply the filter to a given signal, we use the function filter. This function has three parameters: the
coefficients of the filter a and b, and the vector to be filtered. Note that although we think of the filter
operation in frequency domain, the filter function operates on a time-domain vector. The output should as
well be taken as a time-domain vector.
LAB TASK:
m-File:
ts=0.00001;
t= -0.1:ts:0.1;
m=exp(-100*abs(t));
c=cos(2*pi*1000*t);
g=m.*c;
y=abs(g);
cutoff=1000; [a b]=butter(5,2*cutoff*ts);
z=filter(a,b,y);
figure (1)
plot(t,m,t,z);
xlabel ('time')
ylabel('amplitude')
M=abs(fftshift(fft(m)));
G=abs(fftshift(fft(g)));
Y=abs(fftshift(fft(y)));
f=[-length(t)/2:length(t)/2-1]/(length(t)*ts);
figure (2)
subplot (221)
plot(f,M)
subplot(222)
plot(f,G)
subplot (223)
plot(f,Y)
subplot(224)
plot(f,Z)
Discussion
This is usually the first step in any simulation. There are three parameters to define: the beginning of the
interval, the step size, the end of the interval. The beginning and end of the interval are intuitive; for
periodic signals you want to cover 3-5 periods; for non-periodic signals, you usually want to cover the
non-zero part of the signal.
The selection of the step size is crucial for the accuracy of the simulation. You need enough sample points
to represent the signal. Usually, the step size is taken to be of the order of one hundredth of the smallest
period in the program (Or, the sampling frequency fs = 1/ts should be 100 times the frequency of the
signal). In our example, since we are having c(t) of frequency 1000 Hz, we selected fs = 100000, or ts =
0.00001.
This is a straightforward step. The function abs stands for | |, while pi=π. Note that the signals m and c
are now vectors of the same size as t.
This is also a straightforward step. However note the dot after m. Why this is necessary here? What
would happen if you remove the dot?
This is again a straightforward step, provided you recognize that full-wave rectification is mathematically
equivalent to taking the absolute value.
This operation is frequently encountered in simulating communication systems. A LPF is defined by one
parameter, the cutoff frequency.
A filter in MATLAB is represented by its transfer function. The transfer function is in general in the form
of the division of two polynomials. The filter is completely defined by the coefficients of the polynomial
at the numerator and the polynomial at the denominator. These are the vectors a and b respectively in the
program.
There are many realizations for designing filters. One common realization is Butterworth, which is the
one used here, hence the function name butter.
The butter function has two arguments. The first argument is the order of the filter. The larger the order
the sharper the filter (closer to ideal), but more processing is required. For most of our applications an
order of 3-5 should be sufficient.
The second argument is a coefficient related to the cutoff frequency. Without going into the details of the
derivation, to design a LPF filter of cutoff frequency W, the argument should be set to 2*W*ts, where ts
is the time step size of the program. For more details about the command butter , type:
In the previous step we have only created the filter. To apply the filter to a given signal, we use the
function filter. This function has three parameters: the coefficients of the filter a and b, and the vector to
be filtered. Note that although we think of the filter operation in frequency domain, the filter function
operates on a time-domain vector. The output should as well be taken as a time-domain vector.
The Fourier Transform of signals can be found in MATLAB using the function fft. It can be used with a
single argument, which is the time-domain vector. The fft function yields only the positive side of the
spectrum. To get the double-sided spectrum, augment fft by fftshift. Finally, if you are only interested in
the amplitude spectrum, augment all by the function abs. The resulting frequency-domain vector will
have the same size as the size of the input time-domain vector.
To plot the frequency spectrum as a function of frequency, you need to create the frequency axis. The
available range of frequencies depends on ts, and is given by the relation:
f=[-length(t)/2:length(t)/2-1]/(length(t)*ts);
% Plotting
We leave this step to the student to explore. Use the help command to read about plot subplot, figure,
legend, xlabel, ylabel, title and axis commands.
Theory:
Amplitude Modulation:
It is the simplest form of signal processing in which the carrier amplitude is simply changed
according to the amplitude of the information signal,hence the name Amplitude Modulation. When the
information signal’s amplitude is increased the carrier signal’s amplitude is increased and when the
information signal’s amplitude is decreased the carrier signal’s amplitude is decreased. In other
words, the ENVELOPE of the carrier signal’s amplitude contains the information signal.
LAB TASK 1:
In communication we need modulation for proper and reasonable communication. And for modulation we
multiply our message signal with carrier signal. Following code is of modulation of a signal.
MATLAB CODE:
clc; clear all; close all;
ts=1*0.0005;
t=-0.04:ts:0.04;
T=0.02; %gives width
c_f=300; %carrier frequency
sig1=sinc(2*t/T); %at origin sinc function
sig2=sinc(2*t/T-1); %right shifted
sig3=sinc(2*t/T+1); %left shifted
m_sig=2*sig1+sig2+sig3; %message signal
Len=length(t);
Len=2^ceil(log2(Len)); %round length in terms of power of 2
M_freq=fftshift(fft(m_sig,Len)); %FT of msgsgnlfftshift gives origin at zero fft find fourierlen gives how
much
freqm=(-Len/2:Len/2-1)/(Len*ts); %freq axis -Len/2 gives 2 half parts +ve and -ve,
%we want small values so we devide "len*ts"
% above line also tells us len/2+len/2 gives equal to length, but at zero
% it also gives one more length, so we -1 from length to satisfy length
% dimention
c=cos(2*pi*c_f*t); %carrier sgnlc_f is carrier freq
s_dsb=m_sig.*c; %modulation
Len=length(t);
Len=2^ceil(log2(Len)+1);
S_dsb=fftshift(fft(s_dsb,Len)); %fft of modulated sgnl
freqs=(-Len/2:Len/2-1)/(Len*ts);
Tranges=[-0.03 0.03 -2 2]; %time ranges
figure(1)
subplot(221);
tdl=plot(t,m_sig) %we define it equal a veriable so that we can define more properties. i.e it use further
axis(Tranges); title('message signal')
set(tdl,'Linewidth',2); %2 points increases of line width
xlabel('{\it t (sec)}');
ylabel('{\it m} (t})');
subplot(223);
LAB TASK 2:
Following figure is given:
Here in first graph there is message signal and demodulated signal and received SSB signal in time
domain. In second figure USB (upper side band) and LSB (lower side band) in time and frequency
domain in given.
Assignment : Write a code for envelop detection in MATLAB
QAM
ts=1*0.0005;
t=-0.04:ts:0.04;
T=0.01;
fc=2200;
sg1=sinc(2*t/T);
sg2=sinc(2*t/T-1);
sg3=sinc(2*t/T+1);
m1=sg1+sg2+sg3;
m2=(sg1+sg2)-abs(t);
len=length(m1);
lt=length(t);
Lfft=2^ceil(log2(lt));
M1=fftshift(fft(m1,Lfft));
M2=fftshift(fft(m2,Lfft));
freqm=(-Lfft/2:Lfft/2-1)/(Lfft*ts);
B=150;
h=fir1(40,[B*ts]);
dem1=m1.*cos(2*pi*fc*t);
dem2=m2.*sin(2*pi*fc*t);
Franges=[-700 700 0 250];
subplot(223);td3=plot(t,s_dem1);
axis(Tranges); set(td3,'Linewidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it m1} (t)');
title('First Demodulated Signal 1');
subplot(224);td4=plot(t,s_rec1);
axis(Tranges); set(td4,'Linewidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it m1} (t)');
title('Detected Signal 1');
figure(2)
subplot(221);td5=plot(t,m2);
axis(Tranges); set(td5,'Linewidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it m1} (t)');
title('Message signal 2');
subplot(222);td6=plot(t,s_qam);
axis(Tranges); set(td6,'Linewidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it s}_{\rm DSB} (t)');
subplot(224);td8=plot(t,s_rec2);
axis(Tranges); set(td8,'Linewidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it m1} (t)');
title('Detected Signal 2');
% Display Branch 1 in Frequency Domain
Franges=[-700 700 0 100];
figure(3);
subplot(221);fd1=plot(freqm,abs(M1));
axis(Franges); set(fd1,'Linewidth', 1.5);
xlabel('{\it f} (Hz)'); ylabel('{\it M1} (f)');
title('Spectrum of Message Signal 1');
subplot(222);fd2=plot(freq,abs(2*S_qam));
axis(Franges); set(fd2,'Linewidth', 1.5);
xlabel('{\it f} (Hz)');ylabel('{\it S}_{\rm QAM} (f)');
title('QAM Spectrum Magnitude');
subplot(223);fd3=plot(freq,abs(S_dam));
axis(Franges); set(fd3,'Linewidth', 1.5);
xlabel('{\it f} (Hz)');ylabel('{\it E}_{1(f)}');
title('First Demodulated Spectrum');
subplot(224);fd4=plot(freq,abs(S_rec1));
axis(Franges); set(fd4,'Linewidth', 1.5);
xlabel('{\it f} (Hz)');ylabel('{\it M}_{d1(f)}');
title('Recovered Spectrum 1');
subplot(222);fd6=plot(freq,abs(2*S_qam));
axis(Franges); set(fd6,'Linewidth', 1.5);
xlabel('{\it f} (Hz)');ylabel('{\it S}_{\rm QAM} (f)');
title('QAM Spectrum Magnitude');
subplot(223);fd7=plot(freq,abs(2*S_dam2));
axis(Franges); set(fd7,'Linewidth', 1.5);
xlabel('{\it f} (Hz)');ylabel('{\it E}_{2(f)}');
title('Second Demodulated Spectrum');
subplot(224);fd8=plot(freq,abs(1*S_rec2));
axis(Franges); set(fd8,'Linewidth', 1.5);
xlabel('{\it f} (Hz)');ylabel('{\it M}_{d2(f)}');
title('Recovered Spectrum 2');
Lab 09
COMMUNICATION SYSTEM LAB MANUALPage 46
Balanced Modulator
Objective: To generate AM-Double Side Band Suppressed Carrier (DSB-SC) signal.
Apparatus Required:
Resistors 6.8KΩ 1
1K_Ω,51 KΩ 2 each
Capacitors 0.1 μF 4
(Linear Pot)
CRO 100MHz 1
Theory:
Balanced modulator is used for generating DSB-SC signal. A balanced modulator consists of two
standard amplitude modulators arranged in a balanced configuration so as to suppress the carrier wave.
The two modulators are identical except the reversal of sign of the modulating signal applied to them.
Observation Table:
Message signal
Carrier signal
DSB-SC Signal
Model Waveforms:
Results:
Inferences:
Questions:
1. What is the efficiency of the DSB-SC modulating system?
2. What are the applications of balanced modulator?
3. What is the effect of amplitude of message on DSB-Sc signal?
Pd = 1W
Ic(max) = 100 mA
Capacitor 0.01μF 1
Inductor 1mH 1
CRO 20MHz 1
Theory:
Mixers are used in a variety of RF/microwave applications, including military radar, cellular
base stations, and more. An RF mixer is a three-port passive or active device that can modulate
or demodulate a signal. The purpose is to change the frequency of an electromagnetic signal
while (hopefully) preserving every other characteristic (such as phase and amplitude) of the
initial signal. A principal reason for frequency conversion is to allow amplification of the
received signal at a frequency other than that of the RF.
Circuit Diagram:
Procedure:
1. Connect the circuit as per the circuit diagram as shown in Fig.2. Assume C=0.1μF and calculate the
1
value Of L1 using f= where f=7KHz
2 π √ L1 C 1
2. Apply the input signals at the appropriate terminals in the circuit.
3. Note down the frequency of the output signal, which is same as the difference frequency of giving
signals.
Sample readings:
Signal Amplitude (Volts) Frequency(KHz)
Input signal1 4 5
Output signal 9 7
Waveforms:
Precautions:
1.Check the connections before giving the supply
2.Observations should be done carefully
Questions:
Objective: In this Laboratory exercise you will generate a single-tone modulated FM signal
using the Voltage-controlled Oscillator (VCO) in a Phase-locked loop (PLL)
Task
Build the circuit shown next. This uses the VCO portion of the 4046 PLL.
First, investigate it using the "test input" circuit that is shown in Figure 2. Find the
frequency and sketch the waveform for the three VCO input voltages shown in the table below.
From that information, deterine the FM constant , Kf, for your modulator. See the data analysis
section below for guidence in this calculation.
Second, instead of the "test input" circuit, use, as the input, the function generator with
the sinusoidal output listed as follows:
Frequency = 5 kHz (fm = modulating frequency)
Amplitude = 2 volts (p-p)
D.C.Offset = 5V
2VDO/3
VDD/2
VDD/3
PLL has emerged as one of the fundamental building block in electronic technology. It is used
for the frequency multiplication, FM stereo detector , FM demodulator , frequency shift keying
decoders, local oscillator in TV and FM tuner. It consists of a phase detector, a LPF and a
voltage controlled oscillator (VCO) connected together in the form of a feedback system. The
VCO is a sinusoidal generator whose frequency is determined by a voltage applied to it from an
external source. In effect, any frequency modulator may serve as a VCO. The phase detector or
comparator compares the input frequency, fin , with feedback frequency , f out , (output
frequency). The output of the phase detector is proportional to the phase difference between f in ,
and f out . The output voltage of the phase detector is a DC voltage and therefore m is often refers
to as error voltage . The output of the phase detector is then applied to the LPF , which removes
the high frequency noise and produces a DC lend. The DC level, in term is the input to the VCO.
The output frequency of the VCO is directly proportional to the input DC level. The VCO
frequency is compared with the input frequencies and adjusted until it is equal to the input
frequency. In short, PLL keeps its output frequency constant at the input frequency.
Thus, the PLL goes through 3 states.
1. Free running state.
2. The capture range / mode
Data Analysis
The FM constant, Kf , can be determined by plotting the VCO's output frequency v/s the VCO's
input voltage. This should give (approximately) a straight line, its slope is Kf in hert- per-volt.
You will want to conver it to radians/second-per-volt in order to write the expression
for the FM signal you generate. To find β , use
β = [peakmodulatingtoneamplitude/modulatingtonefrequency(inHz)]kf
f max −f min
β=
fm
Use the following circuit for FM demodulation. It is not necessary to use the bu_er and
output low pass fiter.
Questions:
Objective:
I) To observe the effects of pre-emphasis on given input signal.
ii) To observe the effects of De-emphasis on given input signal.
Apparatus Required:
As shown in the figure (Pre-emphasis Circuit) and (De-emphasis circuit)
Theory:
The noise has a effect on the higher modulating frequencies than on the lower ones. Thus, if the higher
frequencies were artificially boosted at the transmitter and correspondingly cut at the receiver, an
improvement in noise immunity could be expected, there by increasing the SNR ratio. This boosting of
the higher modulating frequencies at the transmitter is known as pre-emphasis and the compensation at
the receiver is called de-emphasis.
Circuit Diagrams:
For Pre-emphasis:
For De-emphasis:
0.5
10
11
15
Table2: De-emphasis Vi =
0.150
Graphs:
Precautions:
1. Check the connections before giving the power supply
2. Observation should be done carefully
Result:
Task: Design a complete System using Puls width modulation and demodulation.
Task: Design a complete System using Puls position modulation and demodulation.