DSP Lab by Adarsh 252001107
DSP Lab by Adarsh 252001107
AND TECHNOLOGY
KURUKSHETRA UNIVERSITY,
KURUKSHETRA
SUBMITTED TO : SUBMITTED BY :
Ekta mam Adarsh Kumar
Assistant professor ece ‘B’
Ece, uiet, kuk 252001107
INDEX
S.NO. EXPERIMENT DATE SIGNATURE
1. Introduction to MATLAB.
08.09.2022
THEORY :
What is MATLAB?
MATLAB is widely used in all areas of applied mathematics, in education and research at
universities, and in the industry. MATLAB stands for MATrix LABoratory and the
software is built up around vectors and matrices. This makes the software particularly
useful for linear algebra but MATLAB is also a great tool for solving algebraic and
differential equations and for numerical integration. MATLAB has powerful graphic tools
and can produce nice pictures in both 2D and 3D. It is also a programming language, and
is one of the easiest programming languages for writing mathematical programs.
MATLAB also has some tool boxes useful for signal processing, image processing,
optimization, etc.
Note: From now on an instruction to press a certain key will be denoted by < >, e.g.,
pressing the enter key will be denoted as <enter>. Commands that should be typed at the
prompt, will be written in courier font.
The MATLAB environment (on most computer systems) consists of menus, buttons and a
writing area similar to an ordinary word processor. There are plenty of help functions that
you are encouraged to use. The writing area that you will see when you start MATLAB,
is called the command window. In this window you give the commands to MATLAB. For
example, when you want to run a program you have written for MATLAB you start the
program in the command window by typing its name at the prompt. The command window
is also useful if you just want to use MATLAB as a scientific calculator or as a graphing
tool. If you write longer programs, you will find it more convenient to write the program
code in a separate window, and then run it in the command window .
In the command window you will see a prompt that looks like >> . You type your
commands immediately after this prompt. Once you have typed the command you wish
MATLAB to perform, press <enter>. If you want to interupt a command that MATLAB is
running, type <ctrl> + <c>.
The commands you type in the command window are stored by MATLAB and can be
viewed in the Command History window. To repeat a command you have already used,
you can simply double-click on the command in the history window, or use the <up arrow>
at the command prompt to iterate through the commands you have used until you reach the
command you desire to repeat.
THEORY : The sine function starts from 0. Maximum value of sine function is 1.
Range of cosine is -1 to 1. Range of tangent is from -∞ to ∞.
Range of secant is -1 to 1.
PROGRAM:
t = 0:25;
a = sin(t);
subplot(4,2,1)
plot(a)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Sine wave for continuous function ');
subplot(4,2,2)
stem(a)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Sine wave for discrete function ');
b = cos(t);
subplot(4,2,3)
plot(b)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Cosine wave for continuous function ');
subplot(4,2,4)
stem(b)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Cosine wave for discrete function ');
c = tan(t);
subplot(4,2,5)
plot(c)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Tangent wave for continuous function ');
subplot(4,2,6)
stem(c)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Tangent wave for discrete function ');
d = cot(t);
subplot(4,2,7)
plot(d)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Cotangent wave for continuous function ');
subplot(4,2,8)
stem(d)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Cotangent wave for discrete function ');
RESULT :
EXPERIMENT : 3
AIM : To study Unit Impulse, Unit Ramp, Unit step & Exponential function.
THEORY : A unit step has 1 for t ≥ 0 and 0 for t ˂ 0. A unit ramp has t for t ≥ 0 and
0 for t ˂ 0.
PROGRAM:
t = -7:1:7;
x = [zeros(1,7) ones(1,7)];
subplot(2,2,1)
stem(x)
xlabel('time');
ylabel('amplitude');
title('Unit Step Signal');
a = 0:7;
z = [zeros(1,7) a];
subplot(2,2,3)
stem(z)
xlabel('time');
ylabel('amplitude');
title('Unit Ramp Signal');
e = exp(t);
subplot(2,2,4)
stem(e)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Exponential Function ');
RESULT :
EXPERIMENT : 4
AIM : To study Convolution and Multiplication.
subplot(2,2,2)
stem(z)
xlabel('time');
ylabel('amplitude');
title('Multiplication');
p = conv(x,y) ;
subplot(2,2,3)
plot(p)
xlabel('time');
ylabel('amplitude');
title('Convolution');
subplot(2,2,4)
stem(p)
xlabel('time');
ylabel('amplitude');
title('Convolution');
RESULT :
EXPERIMENT : 5
AIM : To study Real, Imaginary phase and magnitude of Exponential function.
a = exp(m.*t);
subplot(2,2,1);
plot(t,a);
xlabel('time');
ylabel('amplitude');
title('Exponential');
b = real(a);
subplot(2,2,2);
plot(t,b);
xlabel('time');
ylabel('amplitude');
title('Real phase of exponential function');
c = imag(a);
subplot(2,2,3);
plot(t,c);
xlabel('time');
ylabel('amplitude');
title('Imaginary phase of exponential function');
d = abs(a);
subplot(2,2,4);
plot(t,d);
xlabel('time');
ylabel('amplitude');
title('Absolute of exponential function');
RESULT :
EXPERIMENT : 6
AIM : To study the Sampling of a Sinusoidal Discrete Signal.
THEORY : A continuous time signal can be represented in its samples and can be
recovered back when sampling frequency fs is greater than or equal to the twice the
highest frequency component of the message signal. i.e. fs ≥ 2fm
PROGRAM:
clc;
clear all ;
close all ;
n = 0:0.7:70 ;
x = sin(0.5 * pi * n);
subplot(4,1,1)
stem(x)
xlabel('time');
ylabel('amplitude');
title('Original')
y = resample(x,2,1) ;
subplot(4,1,2)
stem(y)
xlabel('time');
ylabel('amplitude');
title('fs=2fm')
y = resample(x,5,1);
subplot(4,1,3)
stem(y)
xlabel('time');
ylabel('amplitude');
title('fs>2fm') ;
y = resample(x,1,2);
subplot(4,1,4)
stem(y)
xlabel('time');
ylabel('amplitude');
title('fs<2fm') ;
RESULT :
EXPERIMENT : 7
AIM : Write a program to plot the Circular Convolution of two signals.
y = cconv(a,b,4) ;
subplot(2,1,1)
plot(y)
xlabel('time');
ylabel('amplitude');
title('Circular-Convolution');
subplot(2,1,2)
stem(y)
xlabel('time');
ylabel('amplitude');
title('Circular-Convolution');
RESULT :
EXPERIMENT : 8
AIM : To study toolbox of various FIR (Finite Impulse Response) filter.
THEORY :
The term FIR abbreviation is “Finite Impulse Response” and it is one of two main
types of digital filters used in DSP applications. Filters are single conditioners and
function of each filter is, it allows an AC components and blocks DC components.
The best example of the filter is a phone line, which acts as a filter. Because, it limits
frequencies to a rage significantly smaller than the range of human beings can hear
frequencies.
There are various kinds of filters, namely LPF, HPF, BPF, BSF. A LPF allows only
low frequency signals through tom its o/p, so this filter is used to eliminate high
frequencies. A LPF is convenient for controlling the highest range of frequencies in
an audio signal. An HPF is quite opposite to LPF. Because, it rejects only frequency
components below some threshold. The best example of the HPF is, cutting out the
60Hz audible AC power.
The design methods of FIR filter based on approximation of ideal filter. The ensuing
filter approaches the perfect characteristic because the order of the filter will
increase, so creating the filter and its implementation additional complicated.
The design process starts with necessities and specifications the FIR filter. The
method used in the design process of the filter depends upon the implementation and
specifications. There are many advantages and disadvantages of the design methods.
Thus, it is very significant to elect the right method for FIR filter design. Due to
efficiency and simplicity of the FIR filter, most commonly window method is used.
The other method sampling frequency method is also very simple to use, but there
is a small attenuation in the stopband.
The three most popular design methods are (in order):
1. Parks-McClellan: The Parks-McClellan method (inaccurately called “Remez”
by Matlab) is probably the most widely used FIR filter design method. It is an
iteration algorithm that accepts filter specifications in terms of passband and
stopband frequencies, passband ripple, and stopband attenuation. The fact that
you can directly specify all the important filter parameters is what makes this
method so popular. The PM method can design not only FIR “filters” but also
FIR “differentiators” and FIR “Hilbert transformers”.
2. Windowing:. In the windowing method, an initial impulse response is derived
by taking the Inverse Discrete Fourier Transform (IDFT) of the desired
frequency response. Then, the impulse response is refined by applying a data
window to it.
There are six types of Window methods:
i. Rectangular
ii. Bartlett
iii. Hanning
iv. Hamming
v. Blackman
vi. Kaiser
3. Direct Calculation: The impulse responses of certain types of FIR filters (e.g.
Raised Cosine and Windowed Sinc) can be calculated directly from formulas.
FILTER DESIGNING :
1. Low-Pass Filter(LPF) :
THEORY :
The infinite impulse response is a type of digital filter that is used in Digital Signal
Processing applications. A filter’s job is to allow certain types of signals to pass and
block the rest. The infinite impulse response filter is unique because it uses a
feedback mechanism. It requires current as well as past output data. Though they are
harder to design, IIR filters are computationally efficient and generally cheaper.