0% found this document useful (0 votes)
187 views

Experiment No. 1: Objective: Write A MATLAB Program To Generate An Exponential Sequence X (N) (A)

This is an experiment on MATLAB based on digital signal processing lab. Hence to clear my basic concepts I require the salivahanan book.

Uploaded by

Shinibali Mandal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views

Experiment No. 1: Objective: Write A MATLAB Program To Generate An Exponential Sequence X (N) (A)

This is an experiment on MATLAB based on digital signal processing lab. Hence to clear my basic concepts I require the salivahanan book.

Uploaded by

Shinibali Mandal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 53

Experiment No.

1
Objective: Write a MATLAB program to generate an exponential sequence X(n)=(a)n for

i) 0< a<1 ii) -1<a<0 iii) a<-1 iv) a>1

Software Used: MATLAB R2012a

Theory:

An exponential sequence is a sequence of the form X(n)=( a)n in which the argument n occurs
as an exponent.

X(n)= (a)n -∞≤ n ≤∞

As per given statement , plot of given sequence can be described as below:


i) For 0 <a < 1 , the sequence value would be exponentially decreasing as value of n increases.

ii) For -1 <a <0 , the sequence value would acquire positive value for even value of n and negative
for odd value of n. At the same time value of n decreases as n increases.

iii ) For a < -1 , the sequence value would acquire positive value for even value of n and negative for
odd value of n. At the same time value of n decreases as n increases.

iv)For a > 1,the sequence value would be exponentially increasing as the value of n increases.

In MATLAB we generally use stem() function to plot discrete sequence.

Source Code:
clc;
clear all;
close all;
n=1:15;

disp('Enter value of a1 between 0 to 1');


a1=input('a1=');
%x=power(a,n); Inbuilt Funcion
for i=1:length(n)
x1(i)=a1^i;
end
disp('Enter value of a2 between -1 to 0');
a2=input('a2=');
for i=1:length(n)
x2(i)=a2^i;
end

disp('Enter value of a3 less than -1');


a3=input('a3=');
for i=1:length(n)
x3(i)=a3^i;
end

disp('Enter value of a4 greater than 1');


a4=input('a4=');
for i=1:length(n)
x4(i)=a4^i;
end

subplot(2,2,1);
stem(x1);
xlabel('n');
ylabel('x1');
title('Graph for 0<a1<1');

subplot(2,2,2);
stem(x2);
xlabel('n');
ylabel('x2');
title('Graph for -1<a2<0');

subplot(2,2,3);
stem(x3);
xlabel('n');
ylabel('x3');
title('Graph for a3<-1');

subplot(2,2,4);
stem(x4);
xlabel('n');
ylabel('x4');
title('Graph for a4>1');

Result: On performing above experiment in MATLAB , desired sequence of X(n)=(a)n is obtained


.Below are graphs for given 4 cases of value of a:

i) For 0 <a < 1 , a = 0.8


ii) For -1 <a <0 , a = -0.8
iii) For a < -1 , a = -8
iv) For a > 1 , a = 8
PLOT
Experiment No. 2
Objective: Write a MATLAB program to generate the signal S(n)=2*n*(0.8^n ) corrupted by noise
d(n) resulting the signal X(n).Where X(n)=S(n)+d(n).Also down sample the corrupted signal.

Software Used: MATLAB R2012a

Theory: A discrete-time signal is a time series consisting of a sequence of quantities.

For Example: Here signal S (n) =2*n*(0.8^n ) is discrete time signal.

Noise:
In signal processing, noise is a general term for unwanted (and, in general, unknown) modifications
that a signal may suffer during capture, storage, transmission, processing, or conversion.
Sometimes the word is also used to mean signals that are random (unpredictable) and carry no useful
information; even if they are not interfering with other signals or may have been introduced
intentionally, as in comfort noise.
For Example: We are generating noise with inbuilt function in MATLAB rand().
Downsampling:
In digital signal processing, decimation is the process of reducing the sampling rate of a signal. The
term downsampling usually refers to one step of the process, but sometimes the terms are used
interchangeably. Decimation is a specific case of sample rate conversion in a multi-rate digital signal
processing system. A system component that performs decimation is called a decimator.

Here we are downsampling distorted signal by factor 2.


Source Code:

clc;
close all;
clear all;
n=1:90;
%Random signal as noise
d=rand(1,90);

%Generating Original Signal


for i=1:length(n)
s(i)=2*n(i)*(0.8.^n(i))
end

% signal+ Noise
x=s+d;

%Plot of signal
subplot(2,2,1);
stem(s);
xlabel('n');
ylabel('s');
title('Original Signal');

%Plot of Noise
subplot(2,2,2);
stem(d);
xlabel('n');
ylabel('d');
title('Noise Signal');

%Plot of Signal+Noise
subplot(2,2,3);
stem(x);
xlabel('n');
ylabel('x');
title('Distorted Signal');

%Downsampling distorted signal by 2


for i=1:2:length(n)
y(i)=x(i);
end

%Plot of downsampled distorted signal


subplot(2,2,4);
stem(y);
xlabel('n');
ylabel('y');
title('Downsampled Distorted Signal');
PLOT

Experiment No. 3
Objective: Generate Gaussian number with mean=20 and variance=40.Also plot the pdf of
generated number.
Software Used: MATLAB R2012a

Theory:

PDF:

In probability theory, a probability density function (PDF), or density of a continuous


random variable, is a function, whose value at any given sample in the sample space can be
interpreted as providing a relative likelihood that the value of the random variable would
equal that sample.In other words, while the absolute likelihood for a continuous random
variable to take on any particular value is 0 ,the value of the PDF at two different samples
can be used to infer, in any particular draw of the random variable, how much more likely it
is that the random variable would equal one sample compared to the other sample.

Normal Distribution:

In probability theory, the normal (or Gaussian or Gauss or Laplace–Gauss) distribution is a


very common continuous probability distribution. Normal distributions are important
in statistics and are often used in the natural and social sciences to represent real-
valued random variables whose distributions are not known. A random variable with a
Gaussian distribution is said to be normally distributed and is called a normal deviate.
The normal distribution states that averages of samples of observations of random
variables independently drawn from independent distributions converge in distribution to
the normal, that is, become normally distributed when the number of observations is
sufficiently large.
Normal Distribution can be written as below:

We will be implementing this with above function as we all as inbuilt MATLAB function
normpdf().

Source Code:
clc;
close all;
clear all;

mu=20;
var=40;
sd=sqrt(var);
%Generating random variable
x=normrnd(mu,sd,1,200);

%Plotting of Random Variable

subplot(3,1,1);
stem(x);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('Random Variable','fontweight','bold','fontsize',10);
title('Random Variable Plot','fontweight','bold','fontsize',10);

%Gaussian function using equation


f=(1/(sd*sqrt(2*pi)))*exp(-1*(x-mu).^2/(var*2));

%Plot of Gaussian function


subplot(3,1,2);
stem(x,f);
xlabel('Random Variable x','fontweight','bold','fontsize',10);
ylabel('Guassian Amplitude','fontweight','bold','fontsize',10);
title('Guassian Probability Density function using
expression','fontweight','bold','fontsize',10);

%Plot of Gaussian function using inbuilt MATLAB function


y = normpdf(x,mu,sd);
subplot(3,1,3);
stem(x,y);
xlabel('Random Variable x','fontweight','bold','fontsize',10);
ylabel('Guassian Amplitude','fontweight','bold','fontsize',10);
title('Guassian pdf with inbuilt
funcion','fontweight','bold','fontsize',10);

Result:

We have generated random variable by taking specific values of mu and sigma. By using this
generated random variable we have generated Gaussian pdf which is as expected in inverted
bell shape graph.
PLOT

Observation:

We have verified Gaussian pdf function obtained by formula and inbuilt function in matlab
and graphs are identical. Please find above diagrams.
Experiment No. 4-i
Objective: Generate Gaussian number with mean=0 and variance=1.Plot the generated
number and calculate 3rd moment i.e Skewness using

𝑥𝑗 − 𝑢
1
Skew(X1, X2, ……Xn) = ∑𝑁
𝒋=𝟎 [ ─ ]^3
𝑁

Software Used: MATLAB R2012a

Theory:

Normal or Gaussian distribution:

In probability theory, the normal (or Gaussian or Gauss or Laplace–Gauss) distribution is a


very common continuous probability distribution. The normal distribution states that
averages of samples of observations of random variables independently drawn from
independent distributions converge in distribution to the normal, that is, become normally
distributed when the number of observations is sufficiently large.
Normal Distribution can be written as below:

Skewness:

The skewness is defined as the third moment about the mean with the following equation,
The skewness describes the degree of asymmetry of a distribution. A symmetric distribution
has a skewness of zero, while an asymmetric distribution has a nonzero skewness. If more
extreme tail of the distribution is to the right of the mean, the skewness is positive; if the more
extreme tail is to the left of the mean, the skewness is negative. The skewness is illustrated in
Fig.

Source Code:
clc;
close all;
clear all;

mu=0;
var=1;
sd=sqrt(var);
N=1:300;
%Generating random variable
x=normrnd(mu,sd,1,300);

%Calculation of Skew using given formula


s=0;
for i=1:length(N)
s=s+(((x(i)-mu)/sd)^3);
end
s=s/length(N);
disp(s);
str = sprintf('Skew Value is %d ', s);
disp(str);

%Plot of Gaussian PDF


f=(1/(sd*sqrt(2*pi)))*exp(-1*(x-mu).^2/(var*2));
subplot(2,1,1);
stem(x,f);
xlabel('Random Variable x','fontweight','bold','fontsize',10);
ylabel('Guassian Amplitude','fontweight','bold','fontsize',10);
title('Guassian Probability Density
function','fontweight','bold','fontsize',10);
%Skew calculattion using inbuilt function
% Y=skewness(x,1);
% disp(Y);

Result:
We have generated Gaussian pdf of random variables and calculated skewness value. Plot has
been printed to verify skewness value.

PLOT

Observation:

As per above graph we see that left tail is longer and hence skewness must be negative.
Calculated value of skewness from given function is negative and hence the experiment is
verified. Also using inbuilt function y = skewness(X) result is verified but value obtained
differs slightly as MATLAB has 2 interpretations for skewness function.
Experiment No. 4-ii
Generate Gaussian number with mean=0 and variance=1 and plot its lognormal distribution.

Source Code:
clc;
close all;
clear all;

mu=0;
var=1;
sd=sqrt(var);
N=1:300;

x=lognrnd(mu,sd,300);

subplot(2,1,1);
stem(x);
xlabel('No of samples','fontweight','bold','fontsize',10);
ylabel('Amplitude','fontweight','bold','fontsize',10);
title('Lognormal Number','fontweight','bold','fontsize',10);

%PDF of Lognormal generated Random Variable


f=(1/(sd*sqrt(2*pi)))*exp(-1*(log(x-mu)).^2/(var*2));

%Plot of Gaussian funtion


subplot(2,1,2);
stem(x,f);
xlabel('Random Variable x','fontweight','bold','fontsize',10);
ylabel('Guassian Amplitude','fontweight','bold','fontsize',10);
title('Guassian Probability Density function using
expression','fontweight','bold','fontsize',10);

Result:

PLOT

Observation: From graph we


observe that lognormal function is always right sided as log
values can’t be negative.
Experiment No. 5
Objective: Write MATLAB program to develop a signal y(n) generated by convolution of
two sequences x(n) and h(n).Also verify result using inbuilt functions.

Software Used: MATLAB R2012a

Theory:

Convolution is a mathematical operation used to express the relation between input and
output of an LTI system. It relates input, output and impulse response of an LTI system as

The input-output characteristic of linear time-invariant (LTI) systems, the most widely used
type of system in signal processing, is described entirely in terms of the impulse response of
the system. The impulse response is the output of the system due to an impulse input
signal. Given the input signal, the output of an LTI system is the convolution of the input
signal with the impulse response of the system. Hence, convolution plays a key role in
relating the input and output signals of an LTI system.

Source Code:

clc;
close all;
clear all;

x=input('Enter Sequence X(n)');


h=input('Enter Sequence H(n)');

m=length(x);
n=length(h);
c1=conv(x,h);
%Zero padding for unequal length sequence
h=[h,zeros(1,m)];
x=[x,zeros(1,n)];

% disp(h);
% disp(x);
for i=1:m+n-1
c(i)=0;
for j=1:m+n-1
if (j<=i)
c(i)=c(i)+(x(j)*h(i-j+1));
end
end
end
disp('Convolution of x(n) and h(n) is ');
disp(c);

%Plot of X(n)
subplot(2,2,1);
stem(x);
title('Input sequencce X(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('X(n)','fontweight','bold','fontsize',10);

%Plot of H(n)
subplot(2,2,2);
stem(h);
title('Input sequencce H(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('H(n)','fontweight','bold','fontsize',10);

%Plot of X(n)*H(n)
subplot(2,2,3);
stem(c);
title('Convolution of X(n) and H(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C(n)','fontweight','bold','fontsize',10);

%Plot of X(n)*H(n) using inbuilt function


subplot(2,2,4);
stem(c1);
title('Convolution of X(n)&H(n) using inbuilt
function','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C1(n)','fontweight','bold','fontsize',10);

Result:

We have taken 2 unequal length sequences and used padding for equating length of them.
Convolution uses 2 loops in which first loop is used for shifting and second loop is for
product of shifted signal and original signal.
PLOT

Observation:

Convolution of 2 input signals has been verified with inbuilt function as well and results are
identical.
Experiment No. 6
Objective: Generate Gaussian distributed numbers and uniformly distributed numbers and
find the correlation between them.

Software Used: MATLAB R2012a

Theory:

A signal operation similar to signal convolution, but with completely different physical
meaning, is signal correlation. The signal correlation operation can be performed either with
one signal (autocorrelation) or between two different signals(crosscorrelation). Physically,
signal autocorrelation indicates how the signal energy (power) is distributed within the signal,
and as such is used to measure the signal power. Typical applications of signal autocorrelation
are in radar, sonar, satellite, and wireless communications systems. Devices that measure
signal power using signal correlation are known as signal correlators. There are also many
applications of signal crosscorrelation in signal processing systems, especially when the
signal is corrupted by another undesirable signal (noise) so that the signal estimation
(detection) from a noisy signal has to be performed. Signal crosscorrelation can be also
considered as a measure of similarity of two signals.

Given two discrete-time real signals (sequences) x[k] and y[k]. The autocorrelation and
croosscorrelation functions are respectively defined by

Source Code:
clc;
close all;
clear all;
mu=0;
var=1;
sd=sqrt(var);

%Generating random variable


x=normrnd(mu,sd,1,30);
h1=unidrnd(500,1,30);
m=length(x);
l=length(h1);

%disp(h1);
for i=1:30
h(i)=h1(l-i+1);
end

%Zero padding for unequal length sequence


n=length(h);
H=[h,zeros(1,m)];
X=[x,zeros(1,n)];

for i=1:m+n-1
c(i)=0;
for j=1:m+n-1
if (j<=i)
c(i)=c(i)+(X(j)*H(i-j+1));
end
end
end

c1=xcorr(x,h1);

%Plot of X(n)
subplot(2,2,1);
stem(x);
title('Gaussian Distributed Numbers
x(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('x(n)','fontweight','bold','fontsize',10);

%Plot of H(n)
subplot(2,2,2);
stem(h1);
title('Uniformly Distributed Numbers
h1(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('h1(n)','fontweight','bold','fontsize',10);

%Corr of X(n)*H(n)
subplot(2,2,3);
stem(c);
title('Correlation of X(n) and H(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C(n)','fontweight','bold','fontsize',10);

%Corr of X(n)& H(n) using inbuilt function


subplot(2,2,4);
stem(c1);
title('Correlation of x &h1 using inbuilt
function','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C1(n)','fontweight','bold','fontsize',10);
Result:
Generated uniformly distributed and gaussian distributed numbers. We have folded
sequence h1 to perform correlation by using convolution formula. Below are graphs plotted
for original signals and correlation between them.

PLOT

Observation:

Correlation of 2 input signals has been verified with inbuilt function as well and results are
identical. Plots are as shown above.
Experiment No. 7
Objective: Write a MATLAB program to perform circular convolution of two finite
unequal length sequence.

Software Used: MATLAB R2012a

Theory:

Circular convolution is another way of finding the convolution sum of two input signals. It
resembles the linear convolution, except that the sample values of one of the input signals is
folded and right shifted before the convolution sum is found. Also note that circular
convolution could also be found by taking the DFT of the two input signals and finding the
product of the two frequency domain signals. The Inverse DFT of the product would give the
output of the signal in the time domain which is the circular convolution output. The two input
signals could have been of varying sample lengths. But we take the DFT of higher point,
which ever signals levels to. For eg. If one of the signal is of length 256 and the other spans
51 samples, then we could only take 256 point DFT. So the output of IDFT would be
containing 256 samples instead of 306 samples, which follows N1+N2 – 1 where N1 & N2
are the lengths 256 and 51 respectively of the two inputs. Thus the output which should have
been 306 samples long is fitted into 256 samples. The 256 points end up being a distorted
version of the correct signal. This process is called circular convolution. The circular
convolution of two sequences x[n],h[n] is a wrap-around of the sequences after a period of N
samples. So, the circular convolution is defined by

where (n′−n)N gives the remainder of n′−n divided by N. For example, (−1)N=N−1.This
means, if the index for x[(n′−n)N] would leave the range 0,…,N−1 to the left, it would wrap
around and come in from the right again. This means that the circular convolution is
periodic with length N.

Source Code:

clc;
close all;
clear all;

x=input('Enter Sequence X(n)');


h=input('Enter Sequence H(n)');

m=length(x);
n=length(h);

l=max(m,n);

%Zero padding for unequal length sequence


if(m-n>0)
h=[h,zeros(1,m-n)];
else
x=[x,zeros(1,n-m)];
end
disp(x);
disp(h);

%circular shifting and convolution


for n = 1:l
c(n) = 0;
for i = 1:l
j = n-i+1;
if(j<=0)
j = l+j;
end
c(n) = [c(n)+x(i)*h(j)];
end
end

disp('Circular Convolution of x(n) and h(n) is using Formula');


disp(c);

disp('Circular Convolution of x(n) and h(n) is using inbuilt function');


c1=cconv(x,h,l);
disp(c1);

subplot(2,1,1);
stem(c);
title('Circular Convolution of X(n)&H(n) using
formula','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C(n)','fontweight','bold','fontsize',10);

subplot(2,1,2);
stem(c1);
title('Circular Con of X(n)&H(n) using inbuilt
function','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C1(n)','fontweight','bold','fontsize',10);

Result:
Circular convolution of x(n) and h(n) is calculated by using two loops in which first loop is
for signal x(n) keeping it clockwise and second loop makes h(n) counter clockwise and then
shifts it by 1 and multiplies h(n),x(n) and adds it .Below is plot for circular convolution
using formula and inbuilt MATLAB function.
PLOT

Observation:

Circular convolution of x(n) and h(n) has been verified with formula and inbuilt function
and results are identical shown as above.
Experiment No. 8
Objective: Design a FIR low-pass filter with given specification and verify magnitude,
phase impulse response using FDA toolbox .Order=100,Window=Rectangular window, cut
off frequency in rad/sec=0.4.

Software Used: MATLAB R2012a

Theory:

In signal processing, a finite impulse response (FIR) filter is a filter whose impulse
response (or response to any finite length input) is of finite duration, because it settles to
zero in finite time. The impulse response of an Nth-order discrete-time FIR filter lasts
exactly N + 1 samples (from first nonzero element through last nonzero element) before it
then settles to zero. FIR filters are employed in filtering problems where linear phase
characteristics within the pass band of the filter are required. To obtain an FIR filter which
approximates the original frequency response, the Fourier series expansion of the system
must be truncated, but the direct truncation of the series leads to Gibbs phenomenon, i.e., a
fixed percentage overshoot and ripple before and after an approximated discontinuity, which
in undesired. In order to avoid this, a time-limited weighting function called window is
used. Here we are implementing FIR filter using rectangular window.

Fourier Transform of rectangular window:

Magnitude and Phase response as below:

Source Code:
clc;
clear all;
close all;
n=100;

w=rectwin(n+1);
b=fir1(n,0.4,'low',w);
freqz(b,1,512);
impz(b);

Result:

We have designed low pass filter with given specifications and magnitude and phase plot is
as shown in figure below.Result is verified with FDA tool also.

MATLAB Code output:


FDA Tool Output:Magnitude and Phase plot together
Observation:

Plots for amplitude and phase response has been verified with fdatool .Impulse response is
also plotted and verified by using inbuilt function impz(b).
Experiment No. 9
Objective: Design a IIR low-pass Butterworth filter with following specification and verify
magnitude, phase, impulse response using FDA toolbox, Order Minimum, Pass Band
attenuation in DB : 3.6,Stop Band attenuation in DB : 36 , Pass Band Freq in Hz: 1500,Stop
Band Freq in Hz: 2000 , Sampling Freq in Hz: 6000

Software Used: MATLAB R2012a

Theory:

The Butterworth filter is a type of signal processing filter designed to have a frequency
response as flat as possible in the passband. It is also referred to as a maximally flat
magnitude filter. Butterworth filters sacrifice rolloff steepness for monotonicity in the pass-
and stopbands. Unless the smoothness of the Butterworth filter is needed, an elliptic or
Chebyshev filter can generally provide steeper rolloff characteristics with a lower filter
order. We compute filter order n and 3DB down frequency with buttord function in matlab
and then butter function returns the filter coefficients in length n+1 row vectors b and a,
with coefficients in descending powers of z.

Source Code:

clc;
clear all;
close all;
wp=1500/6000;
ws=2000/6000;
[n,wn]=buttord(wp,ws,0.36,36);
[b,a]=butter(n,wn,'low');
freqz(b,a,512,512);
str = sprintf('Order of filter is %d and wn is %d ', n,wn);
disp(str);
wvtool(a);

Result:

We have designed butterworth low pass filter using matlab inbuilt functions buttord and
butter .Order of resulted filter is 17 and 3DB cut off frequency is 0.27 rad/sec. Also we used
wvtool(WindowVector) to plot time and frequency domain plots of filter coefficients
a.Impulse response is plotted using FDA Tool.
Command Window Output:

Magnitude and Phase Response of designed filter:

WVTOOL:
Impulse response using FDA Tool:

Magnitude and Phase Response Using FDA Tool:


Magnitude (dB) and Phase Responses
21.9522 0.7853

-8.4708 -1.3743

-38.8939 -3.534

-69.3169 -5.6936

Phase (radians)
Magnitude (dB)

Low pass Butterw orth: Magnitude


-99.74 -7.8533
Low pass Butterw orth: Phase

-130.163 -10.0129

-160.5861 -12.1726

-191.0091 -14.3322

-16.4919
0 0.5 1 1.5 2 2.5
Frequency (kHz)

Observation:

Magnitude and phase response of designed filter is verified using FDA tool .Also wvtool is
used to check time and frequency domain coefficients of filter.
Experiment No. 10-1
Objective: Design the following circuit using Simulink Toolbox on MATLAB. Half Adder
and Full Adder

Software Used: MATLAB R2018a

Theory:

An adder is a digital logic circuit in electronics that implements addition of numbers. In


many computers and other types of processors, adders are used to calculate addresses,
similar operations and table indices in the ALU and also in other parts of the
processors. These can be built for many numerical representations like excess-3 or binary
coded decimal. Adders are classified into two types: half adder and full adder. The half
adder circuit has two inputs: A and B, which add two input digits and generate a carry and
sum. The full adder circuit has three inputs: A and C, which add the three input numbers and
generate a carry and sum. When a full-adder logic is designed, you string eight of them
together to create a byte-wide adder and cascade the carry bit from one adder to the next.

Half Adder:

Logic Diagram: Truth Table

Full Adder:

Logic Diagram: Truth Table

Simulink Design:
HA:

FA:

Result:

First Half Adder is designed using XOR and AND gate .Full adder is designed using half
adder which contains 2 XOR ,2 AND and 1 OR gate .All gates used have 2 input and 1
output port. Input signals are generated from pulse generater using different amplitude and
different duty cycle. Input /Output signal graphs are as shown below.
Half Adder:

Full Adder:

Observation:

Half Adder and Full adder have been designed and result is verified by checking output at
scope. Pulse width and amplitude is varied to obtain different input signals keeping time
period same. Truth table of both FA,HA has been verified by checking graph.
Experiment No. 10-2
Objective: Design the following circuit using Simulink Toolbox on MATLAB. Half Wave
Rectifier and Full Wave Bridge Rectifier

Software Used: MATLAB R2018a

Theory:

A rectifier is a circuit which converts the Alternating Current (AC) input power into a Direct
Current (DC) output power. The input power supply may be either a single-phase or a multi-
phase supply .The power diode in a half wave rectifier circuit passes just one half of each
complete sine wave of the AC supply in order to convert it into a DC supply. Then this type
of circuit is called a “half-wave” rectifier because it passes only half of the incoming AC
power supply as shown below.

Half Wave Rectifier:

Vmax
Vout =
π

Full Wave Bridge Rectifier:

A bridge rectifier is a type of full wave rectifier which uses four or more diodes in a bridge
circuit configuration to efficiently convert the Alternating Current (AC) into Direct Current
(DC) .The bridge rectifier is made up of four diodes namely D1, D2, D3, D4 and load resistor
RL. It allows electric current during both positive and negative half cycles of the input AC
signal.

Vmax
Vout =

Simulink Design:

Half Wave Rectifier:

Full Wave Rectifier:


Result:

Half Wave Rectifier:

Full Wave Rectifier:

Observation:

Half wave rectifier and full wave bridge rectifier have been designed using Simulink and used
powergui to simulate the same. Waveforms have been observed using scope and result is
verified. Output voltage is verified using formula mentioned above.
Experiment No. 11
Objective: Design the following circuit using Simulink Toolbox on MATLAB. Amplitude
Modulation and demodulation, Frequency Modulation and demodulation

Software Used: MATLAB R2018a

Theory:

Amplitude modulation (AM)


It is a modulation technique used in electronic communication, most commonly for
transmitting information via a radio carrier wave. In amplitude modulation, the amplitude of
the carrier wave is varied in proportion to that of the message signal being transmitted. At the
receiving station, the message signal is extracted from the modulated carrier by demodulation.

𝑦(𝑡) = [𝐴 + 𝑚 𝑐𝑜𝑠 𝑤𝑚 𝑡]. 𝑠𝑖𝑛 𝑤𝑐 𝑡

Amplitude Demodulation
When demodulating a signal, two basic steps are there:

 Create baseband signal: The main element of AM demodulation is to create the


baseband signal. This can be achieved in a number of ways - one of the easiest is to
use a simple diode and rectify the signal. This leaves elements of the original RF
signal. When other forms of demodulation are used, they too leave some elements of
an RF signal.
 Filter: The filtering removes any unwanted high frequency elements from the
demodulation process. The AM demodulation process is outlined in the diagram
below. This particular example applies particularly to a diode detector.
There are a number of ways in which an AM signal can be demodulated. There is a balance
that needs to be made of the performance of the circuit that is required against the complexity,
and hence the cost that can be tolerated.
The major types of AM demodulator are:

 Diode AM detector: This is by far the simplest form of AM demodulator or detector,


requiring just a semiconductor (or other form) of diode along with a capacitor to
remove the high frequency components. It suffers from a number of disadvantages,
but its performance is more than adequate for most applications including broadcast
receivers where cost is a significant driver.
 Synchronous AM detector: This form of AM detector offers a higher level of
performance, but at the cost of considerably the use of considerably more components.
This means that it is only used in receivers where the levels of performance are
paramount and can justify the additional component costs.
Fig 1: Amplitude Demodulation

Frequency modulation (AM)

In telecommunications and signal processing, frequency modulation (FM) is the encoding


of information in a carrier wave by varying the instantaneous frequency of the wave.
In analog frequency modulation, such as FM radio broadcasting of an audio signal
representing voice or music, the instantaneous frequency deviation, the difference between
the frequency of the carrier and its center frequency, is proportional to the modulating signal.
𝑡
𝑆𝑓𝑚 (𝑡) = 𝐴𝑐 . 𝑐𝑜𝑠 [2𝜋. 𝐹𝑐 . 𝑡 + ∅𝑐 + 𝐾𝑓𝑚 . ∮ 𝑚(𝑡)𝑑𝑡]
−∞

Fig 2: Frequency Modulation

FM demodulators
There are a number of circuits that can be used to demodulate FM. Each type has its own
advantages and disadvantages, some being used when receivers used discrete components,
and others now that ICs are widely used.
 Slope FM detector: This form of detector uses the slope of a tuned circuit to convert
the frequency variations into amplitude variations. As the frequency of the FM signal
varies, it changes its position on the slope of the tuned circuit, so the amplitude will
vary.
 Ratio detector: This FM demodulator circuit was widely used with discrete
components, providing a good level of performance. It was characterised by the
transformer with three windings that was required
 Foster-Seeley FM detector: Like the Ratio detector the Foster Seeley detector or
discriminator was used with discrete components, providing excellent performance
for the day in many FM radios.
 PLL, Phase locked loop FM demodulator: FM demodulators using phase locked
loops, PLLs can provide high levels of performance. They do not require a costly
transformer and can easily be incorporated within FM radio ICs.
 Quadrature FM demodulator: This form of FM demodulator is very convenient
for use within integrated circuits. It provides high levels of linearity, while not
requiring many external components.
 Coincidence FM demodulator: This form of demodulator has many similarities to
the quadrature detector. It uses digital technology and replaces a mixer with a logic
NAND gate.

Simulink Design:

Amplitude Modulation

Modulator Demodulator

Fig 3: Amplitude Modulation and Demodulation

Frequency Modulation

Modulator

Demodulator

Demodulat
or
Fig 4: Frequency Modulation and Demodulation

Result:

Amplitude Modulation
Fig 5: Amplitude Modulation and Demodulation using Simulink

Frequency Modulation

Fig 6: Frequency Modulation and Demodulation using Simulink

Observation:

AM modulation and Demodulation is performed using Simulink .For demodulation of AM


we used product modulator and LPF and verified waveforms using scope. The Continuous-
Time VCO (voltage-controlled oscillator) block used to observe demodulated FM .It
generated a signal with a frequency shift from the Quiescent frequency (Fc) parameter that
is proportional to the input signal. The input signal is interpreted as a voltage.
Experiment No. 12
Objective: Write a program to read RGB image and perform the following operations on the
image. Extract Red, Green and Blue components of the image and combine them to get the
original image.

Software Used: MATLAB R2012a

Theory:

In computer science,digital image processing is the use of computer algorithms to perform


image processing on digital images .As a subcategory or a field of DSP, digital image
processing has many advantages over analog image processing. It allows much wider range
of algorithms to be applied to the input data and can avoid problem such as build up of noise
and signal distortion during processing. Since images are defined over 2D, digital image
processing may be modelled in the form of multidimensional system.

Source Code:
clc;
clear all;
close all;

A=imread('C:\Users\user\Pictures\pic.png');
Y=imread('C:\Users\user\Pictures\pic2.jpg');
B=im2double(A);
R=B(:,:,1);
G=B(:,:,2);
B=B(:,:,3);
subplot(3,2,1),imshow(A);
title('Original Image','fontweight','bold','fontsize',10);
subplot(3,2,2),imshow(R);
title('Red component of image','fontweight','bold','fontsize',10);
subplot(3,2,3),imshow(G);
title('Green component of image','fontweight','bold','fontsize',10);
subplot(3,2,4),imshow(B);
title('Blue component of image','fontweight','bold','fontsize',10);
H=cat(3,R,G,B);
subplot(3,2,[5,6]),imshow(H);
title('Combine of RGB to original
image','fontweight','bold','fontsize',10);
Result:

Fig 1: Extraction of RGB component of an image and then combine back to get original image

Observation: We have observed that after converting image double precision, we obtained
Red component from slice 1,Blue from slice2 and Green from slice 3 of image and used cat
function to concatenate those 3 slices back to original image.
Experiment No. 13
Objective: Covert the RGB image into grey scale image and resize image to 512*512 pixels,
add and subtract another RGB image to original image calculate sizes of all the images.

Software Used: MATLAB R2012a

Theory:

In computer science,digital image processing is the use of computer algorithms to perform


image processing on digital images .As a subcategory or a field of DSP, digital image
processing has many advantages over analog image processing. It allows much wider range
of algorithms to be applied to the input data and can avoid problem such as build up of noise
and signal distortion during processing. Since images are defined over 2D, digital image
processing may be modelled in the form of multidimensional system.

Source Code:
clc;
clear all;
close all;
img = imread('pic.png'); % Read image

Y = imread('pic2.jpg');
J= rgb2gray(img);

K = imresize(img, [512 512]);


Y = imresize(Y, [512 512]);

subplot(3,2,1),imshow(img);
title('Original image','fontweight','bold','fontsize',10);
subplot(3,2,2),imshow(J);
title('Grayscale image','fontweight','bold','fontsize',10);
Z = imadd(K,Y);
subplot(3,2,3),imshow(Z);
title('Addition of images','fontweight','bold','fontsize',10);
U=imsubtract(K,Y);
subplot(3,2,4),imshow(U);
title('Subtraction of images','fontweight','bold','fontsize',10);
subplot(3,2,[5,6]),imshow(Y);
title('Second images','fontweight','bold','fontsize',10);
Result:

Fig 1: Grayscale conversion, addition and subtraction of 2 images

Fig 2: Size of original image, after resizing, after adding 2images, after subtracting 2 images

Observation: We have converted image to grayscale using rgb2gray function. Also we added
and subtracted 2 images using imadd and imsubtract functions. Also we have calculated size
of each image using size function.
Experiment No. 14
Objective: Write a program to read a RGB image and perform the following operations on
the image. Calculate the discrete cosine transform of the image and then recover the original
image. Add Gaussian noise to grayscale image and then recover the original grayscale image.

Software Used: MATLAB R2012a

Theory:

DCT:

A discrete cosine transform (DCT) expresses a finite sequence of data points in terms of a
sum of cosine functions oscillating at different frequencies. DCTs are important to numerous
applications in science and engineering, from lossy compression of audio (e.g. MP3)
and images (e.g. JPEG) (where small high-frequency components can be discarded),
to spectral methods for the numerical solution of partial differential equations. The use
of cosine rather than sine functions is critical for compression, since it turns out that fewer
cosine functions are needed to approximate a typical signal, whereas for differential equations
the cosines express a particular choice of boundary conditions. In particular, a DCT is
a Fourier-related transform similar to the discrete Fourier transform (DFT), but using
only real numbers.
Noise:

Salt-and-pepper noise known as impulse noise can be caused by sharp and sudden
disturbances in the image signal. It presents itself as sparsely occurring white and black pixels.
An effective noise reduction method for this type of noise is a median filter or
a morphological filter.

Principal sources of Gaussian noise in digital images arise during acquisition e.g. sensor
noise caused by poor illumination and/or high temperature, and/or transmission e.g. electronic
circuit noise. In digital image processing Gaussian noise can be reduced using a spatial filter,
though when smoothing an image, an undesirable outcome may result in the blurring of fine-
scaled image edges and details because they also correspond to blocked high frequencies.

Source Code:
clc;
clear all;
close all;
m=0;
v=0.01;
d=0.05;
img = imread('pic.png');

G = rgb2gray(img);
Q=im2double(G);
J = imnoise(Q,'gaussian',m,v);
S= imnoise(Q,'salt & pepper',d);

subplot(2,2,1),imshow(img);
title('Original image','fontweight','bold','fontsize',10);
subplot(2,2,2),imshow(G);
title('GrayScale image','fontweight','bold','fontsize',10);
subplot(2,2,3),imshow(J);
title('Gaussian noise+image','fontweight','bold','fontsize',10);
subplot(2,2,4),imshow(S);
title('Salt&Pepper noise+image','fontweight','bold','fontsize',10);

I = rgb2gray(img);
K = dct2(I);
subplot(1,2,1),imshow(K);
title('DCT of grayscale image','fontweight','bold','fontsize',10);
L = idct2(K);
subplot(1,2,2),imshow(L,[0 255]);
title('IDCT of grayscale image','fontweight','bold','fontsize',10);

h = fspecial('average', [3 3]);
filtimg = imfilter(J,h);
figure,imshow(filtimg);title('Gaussian Filtered image');

B = medfilt2(S);
figure,imshow(B);title('Salt&Pepper Filtered image');

Result:

Fig 1: DCT and IDCT of an image


Fig 2: Image with noise and recovered image

Observation:We have calculated DCT of image and recovered original image back using
idct2 function. Also, we have used inbuilt function to add noise into image and recovered
image using spatial filter for Gaussian noise where hsize is kept as default .But as we increase
hsize more smooth picture is obtained. Median filter for salt and paper noise is used. Results
are as shown in above figure.
Experiment No. 15
Objective: Write a program to perform DFT and IDFT of signal and verify using inbuilt
MATLAB function.

Software Used: MATLAB R2012a

Theory:

Discrete Fourier transform (DFT) converts a finite sequence of equally-spaced samples of


a function into a same-length sequence of equally-spaced samples of the discrete-time Fourier
transform (DTFT), which is a complex-valued function of frequency. The interval at which
the DTFT is sampled is the reciprocal of the duration of the input sequence. An inverse DFT
is a Fourier series, using the DTFT samples as coefficients of complex sinusoids at the
corresponding DTFT frequencies. It has the same sample-values as the original input
sequence. The DFT is therefore said to be a frequency domain representation of the original
input sequence. If the original sequence spans all the non-zero values of a function, its DTFT
is continuous (and periodic), and the DFT provides discrete samples of one cycle. If the
original sequence is one cycle of a periodic function, the DFT provides all the non-zero values
of one DTFT cycle.
The DFT is the most important discrete transform, used to perform Fourier analysis in many
practical applications. In digital signal processing, the function is any quantity or signal that
varies over time, such as the pressure of a sound wave, a radio signal or
daily temperature readings, sampled over a finite time interval (often defined by a window
function). In image processing, the samples can be the values of pixels along a row or column
of a raster image. The DFT is also used to efficiently solve partial differential equations and
to perform other operations such as convolutions or multiplying large integers.
The discrete fourier transform transforms a sequence of N complex numbers 𝑥𝑛 =
𝑥0 , 𝑥1 , 𝑥2 … . . 𝑥𝑁−1 into another sequence of complex numbers, 𝑋𝑘 = 𝑋0 , 𝑋1 , 𝑋2 … . . 𝑋𝑁−1 ,
which is defined by

𝑁−1
−2∗𝑝𝑖∗𝑖∗𝑘∗𝑛
𝑋𝑘 = ∑ 𝑥𝑛 . 𝑒 𝑁
𝑛=0

IDFT of signal is given by below formula:


𝑁−1
1 2∗𝑝𝑖∗𝑖∗𝑘∗𝑛
𝑥𝑛 = ∑ 𝑋𝑘 . 𝑒 𝑁
𝑁
𝑘=0
Source Code:
clc;
clear all;
close all;
N=16;

for n=1:16
x(n)=n;
end
y=zeros(1,N);
for K=1:16
for m=1:16
y(K)=y(K)+x(m)*exp((-j)*2*pi*(m-1)*(K-1)/N);
end
end

Y = fft(x);
m = abs(y); % Magnitude
p = unwrap(angle(y));
t=0:N-1;
subplot(3,2,1)
stem(t,x)
ylabel ('Amplitude');
xlabel ('Time Index');
title('DFT with formula','fontweight','bold','fontsize',10)

t=0:N-1;
subplot(323);
stem(t,m);
ylabel ('Amplitude');
xlabel ('K');

t=0:N-1;
subplot(3,2,5);
stem(t,p);
ylabel ('phase');
xlabel ('K');

m1 = abs(Y);
p1 = unwrap(angle(Y));

t=0:N-1;
subplot(3,2,2)
stem(t,x)
ylabel ('Amplitude');
xlabel ('Time Index');
title('FFT with inbuilt function','fontweight','bold','fontsize',10)

t=0:N-1;
subplot(324);
stem(t,m1);
ylabel ('Amplitude');
xlabel ('K');

t=0:N-1;
subplot(3,2,6);
stem(t,p);
ylabel ('phase');
xlabel ('K');

%IDFT of signal
for h=1:16
for k=1:16
x(h)=(x(h)+y(k)*exp((j)*2*pi*(h-1)*(k-1)/N)/N);
end
end

t=0:N-1;
subplot(1,2,1);
stem(t,x/2);
ylabel ('Amplitude');
xlabel ('Time Index');
title('IDFT with formula','fontweight','bold','fontsize',10)

X = ifft(y);
t=0:N-1;
subplot(1,2,2);
stem(t,X);
ylabel ('Amplitude');
xlabel ('Time Index');
title('IFFT with inbuilt function','fontweight','bold','fontsize',10)

Result:

DFT: IDFT:

Fig 1: DFT of signal using formula and Fig 2: IDFT of signal using formula and IFFT
FFT function in MATLAB function in MATLAB

Observation:

DFT and IDFT of signal are calculated using formula method and same is verified using
MATLAB inbuilt function fft and ifft.
Experiment No. 16
Objective: Plot the pole-zero plot for following transfer functions .Use Z-plane for the same.

2𝑧 −1 + 9𝑧 −2 +18𝑧 −3 +48𝑧 −4
𝐻(𝑧) =
3𝑧 −1 + 3𝑧 −2 +25𝑧 −3 −12𝑧 −4

5𝑧 −1 − 9𝑧 −2 +16𝑧 −3 −14𝑧 −4
𝐻(𝑧) = −1
𝑧 − 2𝑧 −2 +10𝑧 −3 +64𝑧 −5
Also calculate the impulse response for following transfer function.

0.58𝑧 −1 + 0.95𝑧 −2 +0.49𝑧 −3 +1𝑧 −4


𝐻(𝑧) =
1𝑧 −1 + 0.75𝑧 −2 −0.48𝑧 −3 −0.9𝑧 −4

Software Used: MATLAB R2012a

Theory:

Pole – Zero Plot:

In mathematics, signal processing and control theory, a pole–zero plot is a graphical


representation of a rational transfer function in the complex plane which helps to convey
certain properties of the system such as:

 Stability
 Causal system / anticausal system
 Region of convergence (ROC)
 Minimum phase / non minimum phase

A pole-zero plot shows the location in the complex plane of the poles and zeros of the transfer
function of a dynamic system, such as a controller, compensator, sensor, equalizer, filter or
communications channel. By convention, the poles of the system are indicated in the plot by
an X while the zeros are indicated by a circle or O.

A pole-zero plot can represent either a continuous-time (CT) or a discrete-time (DT) system.
For a CT system, the plane in which the poles and zeros appear is the s plane of the Laplace
transform. In this context, the parameter s represents the complex angular frequency, which
is the domain of the CT transfer function. For a DT system, the plane is the z plane,
where z represents the domain of the Z-transform.
Impulse Response:

In signal processing, the impulse response, or impulse response function (IRF), of a dynamic
system is its output when presented with a brief input signal, called an impulse. The impulse
response describes the reaction of the system as a function of time (or possibly as a function
of some other independent variable that parameterizes the dynamic behavior of the system).

Source Code:
clc;
clear all;
close all;
z=[2 9 18 48];
p=[3 3 25 -12];
subplot(2,2,1);
zplane(z,p);
grid
title('4th-Order Digital Filter')

z1=[5 -9 16 -14];
p1=[1 -2 10 0 64]
subplot(2,2,2);
zplane(z1,p1);
grid
title('5th-Order Digital Filter')

z2=[0.58 0.95 0.49 1]


p2=[1 0.75 -0.48 -0.9]

subplot(2,2,[3 4]);
impz(z2,p2);
grid
title('Impulse Response of system')

Result:
Observation:

Pole-zero plot of both the transfer function is as shown above.Both the systems are unstable
as poles lies outside of unit circle.

Impulse response of given transfer function is plotted as shown above which shows higher
amplitude at higher number of samples.

You might also like