DSP-Lab REC-553

Download as pdf or txt
Download as pdf or txt
You are on page 1of 66

DIGITAL SIGNAL PROCESSING LAB

Code: REC – 553

C E
, E
E T
I
M Department of ECE

Meerut Institute of Engg. & Tech., Meerut


DIGITAL SIGNAL PROCESSING LAB

LIST OF EXPERIMENTS

1. To study about DSP Processors and architecture of TMS320C6713 DSP


processor.

E
2. Introduction to MATLAB and Code Composer Studio.

C
3. Write a MATLAB Program for the generation of basic signals such as unit
impulse, unit step, ramp, exponential, sinusoidal and cosine.

E
4. To study matrix multiplication using code composer studio.

,
5. Evaluate 4 point DFT of and IDFT of x(n) = 1, 0 ≤ n ≤ 3; 0 elsewhere.

T
6. To implement FFT algorithm.

7. Verify Blackman and Hamming windowing techniques.

IE
8. Implement IIR Butterworth analog Low Pass for a 4 KHz cut off frequency.

9. Verify Circular Convolution using code composer studio.

M
10. Verify linear convolution of two sequence using code composer studio.

11. To implement Tone Generation.

12. To implement floating point arithmetic.


13. Write a MATLAB program to design a FIR Low pass, High pass, Band pass,
Band stop filter using Rectangular window.

14. Write a MATLAB program to design Chebyshev Type-I (Low pass filter, High
pass, Band pass& Band stop filter).
DIGITAL SIGNAL PROCESSING LAB

E
COURSE OUTCOMES

C
CO.1 Learn to apply the linear systems approach to signal processing

E
problems using MATLAB and Code Composer Studio.

CO.2 Students will be able to generate and analyze various types of signals

,
and operations used in the signal processing.

T
CO.3 Students will be able to perform frequency domain analysis of
discrete time systems using N- point DFT and FFT.

E
CO.4 Students will be able to design and evaluate the performance of FIR and

I
IIR filters using window techniques and Butterworth approximation
CO.5 Students will be able to understand the concept of circular
respectively.
convolution and linear convolution.

M
Important Instructions:
 Write MATLAB syntax correctly.

C E
E
 Don’t forget the use of semicolon, to suppress the output in command window.

,
 Handling Error should be avoided.
 M-file should be saved in proper location.

T
 Write the MATLAB program carefully.

IE
M
EXPERIMENT NO. - 1

OBJECTIVE - To study about DSP Processors and architecture of TMS320C6713 DSP


processor.

OUTCOME: Students understand the concept and importance of DSP Processors.

E
REQUIREMENT: DSK TMS320C6713 processor

C
THEORY:

E
1. Introduction
DSPs are processors whose hardware, software, and instruction sets are optimized for

,
high-speed numeric processing applications, an essential for processing digital data,
representing analog signals in real time. The DSP processors have gained increased

T
popularity because of the various advantages like reprogram ability in the field, cost-
effectiveness, speed, energy efficiency etc. Digital signal processors such as the

E
TMS320C6x (C6x) family of processors are like fast special-purpose microprocessors

I
with a specialized type of architecture and an instruction set appropriate for signal
processing. The C6x notation is used to designate a member of Texas Instruments’ (TI)

M
TMS320C6000 family of digital signal processors. The architecture of the C6x digital
signal processor is very well suited for numerically intensive calculations. Based on a
very-long-instruction-word (VLIW) architecture, the C6x is considered to be TI’s most
powerful processor. Digital signal processors are used for a wide range of applications,
from communications and controls to speech and image processing.
DSP techniques have been very successful because of the development of low-cost
software and hardware support. For example, modems and speech recognition can be less
expensive using DSP techniques. DSP processors are concerned primarily with real-time
signal processing. Real time processing requires the processing to keep pace with some
external event, whereas non-real-time processing has no such timing constraint. The
external event to keep pace with is usually the analog input. Whereas analog-based
systems with discrete electronic components such as resistors can be more sensitive to
temperature changes, DSP-based systems are less affected by environmental conditions.
DSP processors enjoy the advantages of microprocessors. They are easy to use, flexible,
and economical.
The hardware experiments in the DSP lab are carried out on the Texas Instruments
TMS320C6713 DSP Starter Kit (DSK), based on the TMS320C6713 floating point DSP
running at 225 MHz. The basic clock cycle instruction time is 1/(225 MHz)= 4.44

E
nanoseconds. During each clock cycle, up to eight instructions can be carried out in
parallel, achieving up to 8×225 = 1800 million instructions per second (MIPS). The

C
C6713 processor has 256KB of internal memory, and can potentially address 4GB of
external memory. The DSK board includes a 16MB SDRAM memory and a 512KB

E
Flash ROM. It has an on-board 16-bit audio stereo codec (the Texas Instruments
AIC23B) that serves both as an A/D and a D/A converter. There are four 3.5 mm audio

,
jacks for microphone and stereo line input, and speaker and head-phone outputs. The

T
AIC23 codec can be programmed to sample audio inputs at the following sampling rates:
fs = 8, 16, 24, 32, 44.1, 48, 96 kHz

E
The ADC part of the codec is implemented as a multi-bit third-order noise-shaping delta-

I
sigma converter for the theory of such converters) that allows a variety of oversampling
ratios that can realize the above choices of fs. The corresponding oversampling
decimation filters act as anti-aliasing prefilters that limit the spectrum of the input analog

M
signals effectively to the Nyquist interval [−fs/2, fs/2]. The DAC part is similarly
implemented as a multi-bit second-order noise-shaping delta-sigma converter whose
oversampling interpolation filters act as almost ideal reconstruction filters with the
Nyquist interval as their passband. The DSK also has four user-programmable DIP
switches and four LEDs that can be used to control and monitor programs running on the
DSP. All features of the DSK are managed by the CCS, which is a complete integrated
development environment (IDE) that includes an optimizing C/C++ compiler, assembler,
linker, debugger, and program loader. The CCS communicates with the DSK via a USB
connection to a PC. In addition to facilitating all programming aspects of the C6713 DSP,
the CCS can also read signals stored on the DSP’s memory, or the SDRAM, and plot
them in the time or frequency domains. The following block diagram depicts the overall
operations involved in all of the hardware experiments in the DSP lab. Processing is
interrupt-driven at the sampling rate fs, as explained below.

C E
The AIC23 codec is configured (through CCS) to operate at one of the above sampling

E
rates fs. Each collected sample is converted to a 16-bit two’s complement integer. The

,
codec actually samples the audio input in stereo, that is, it collects two samples for the
left and right channels. At each sampling instant, the codec combines the two 16-bit

T
left/right samples into a single 32-bit unsigned integer word, and ships it over to a 32-bit
receive register of the multichannel buffered serial port (McBSP) of the C6713 processor,

E
and then issues an interrupt to the processor.

I
Upon receiving the interrupt, the processor executes an interrupt service routine (ISR)
that implements a desired sample processing algorithm programmed with the CCS (e.g.,
filtering, audio effects, etc.). During the ISR, the following actions take place: the 32-bit

M
input sample (denoted by x in the diagram) is read from the McBSP, and sent into the
sample processing algorithm that computes the corresponding 32-bit output word
(denoted by y), which is then written back into a 32-bit transmit-register of the McBSP,
from where it is transferred to the codec and reconstructed into analog format, and finally
the ISR returns from interrupt, and the processor begins waiting for the next interrupt,
which will come at the next sampling instant. Clearly, all processing operations during
the execution of the ISR must be completed in the time
interval between samples, that is, T = 1/fs. For example, if fs = 44.1 kHz, then, T = 1/fs =
22.68 μsec. With an instruction cycle time of Tc = 4.44 nsec, this allows T/Tc = 5108
cycles to be executed during each sampling instant, or, up to 8×5108 = 40864 instructions,
or half of that per channel.
Diagrams of TMS320C6713 DSK

C E
, E
T
Fig1.1 Functional Block diagram of TMS320C6713 DSK

IE
M
Fig 1.2 Board diagram of TMS320C6713 DSK
1.3. Features
The DSK comes with a full complement of on-board devices that suit a wide variety of
application environments. Key features include:
• A Texas Instruments TMS320C6713 DSP operating at 225 MHz.
• An AIC23 stereo codec
• 16 Mbytes of synchronous DRAM
• 512 Kbytes of non-volatile Flash memory (256 Kbytes usable in default configuration)

E
• 4 user accessible LEDs and DIP switches
• Software board configuration through registers implemented in CPLD

C
• Configurable boot options
• Standard expansion connectors for daughter card use

E
• JTAG emulation through on-board JTAG emulator with USB host
• interface or external emulator

,
• Single voltage power supply (+5V)

T
1.4 TMS320C6713 DSP core architecture

E
The TMS320C6713 DSP is a floating point DSP with VLIW architecture. The internal

I
program memory is structured so that a total of eight instructions can be fetched at every
cycle. To give a numerical example, with a clock rate of 225 MHz the C6713 DSP can
fetch eight, 32-bit instructions every 4.4 ns. Features of the C6713 include 264 kBytes of

M
internal memory: 8 kB as L1 cache and 256 kB as L2 memory shared between program
and data space. The processing of instructions occurs in each of the two data paths (A and
B), each of which contains four functional units (.L, .S, .M, .D).
An Enhanced DMA (EDMA) controller supports up to 16 EDMA channels. Four of the
sixteen channels (channels 8−11) are reserved for EDMA chaining, leaving twelve
EDMA channels available to service peripheral devices.
C E
, E
E T
I
M
RESULTS:
The TMS320C6713 DSP processor and its architecture are studied and understood.
EXPERIMENT NO. - 2

OBJECTIVE: Introduction to MATLAB and Code Composer Studio.

OUTCOME: Familiarization with MATLAB and Code Composer Studio usage.

REQUIREMENTS: MATLAB and Code Composer Studio Software.

THEORY:

E
1. MATLAB

C
MATLAB is a high-performance language for technical computing. It integrates

E
computation, visualization, and programming in an easy-to-use environment where

,
problems and solutions are expressed in familiar mathematical notation. Typical uses
include:

T
 Math and computation

E
Algorithm development

I
Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics

M
 Application development, including Graphical User Interface building

MATLAB is an interactive system whose basic data element is an array that does not
require dimensioning. This allows you to solve many technical computing problems,
especially those with matrix and vector formulations, in a fraction of the time it would
take to write a program in a scalar non interactive language such as C or FORTRAN.
The name MATLAB stands for matrix laboratory. MATLAB was originally written to
provide easy access to matrix software developed by the LINPACK and EISPACK
projects, which together represent the state-of-the-art in software for matrix computation.
MATLAB has evolved over a period of years with input from many users. In university
environments, it is the standard instructional tool for introductory and advanced courses
in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for
high-productivity research, development, and analysis.
MATLAB features a family of application-specific solutions called toolboxes. Very
important to most users of MATLAB, 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 signal processing, control systems, neural networks,

E
fuzzy logic, wavelets, simulation, and many others.

1.1. The MATLAB System

C
The MATLAB system consists of five main parts:

E
The MATLAB language.

,
This is a high-level matrix/array language with control flow statements, functions, data

T
structures, input/output, and object-oriented programming features. It allows both
"programming in the small" to rapidly create quick and dirty throw-away programs, and

E
"programming in the large" to create complete large and complex application programs.

I
The MATLAB working environment.
This is the set of tools and facilities that you work with as the MATLAB user or

M
programmer. It includes facilities for managing the variables in your workspace and
importing and exporting data. It also includes tools for developing, managing, debugging,
and profiling M-files, MATLAB's applications.

Handle Graphics.
This is the MATLAB graphics system. It includes high-level commands for two-
dimensional and three-dimensional data visualization, image processing, animation, and
presentation graphics. It also includes low-level commands that allow you to fully
customize the appearance of graphics as well as to build complete Graphical User
Interfaces on your MATLAB applications.
The MATLAB mathematical function library.
This is a vast collection of computational algorithms ranging from elementary functions
like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like
matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms.

The MATLAB Application Program Interface (API).


This is a library that allows you to write C and FORTRAN programs that interact with

E
MATLAB. It include facilities for calling routines from MATLAB (dynamic linking),
calling MATLAB as a computational engine, and for reading and writing MAT-files.

C
2. Code Composer Studio

, E
E T
Fig2.1. Simplified Code Composer Studio IDE Development Flow

I
CCS provides an IDE to incorporate the software tools. CCS includes tools for code
generation, such as a C compiler, an assembler, and a linker. It has graphical capabilities

M
and supports real time debugging. It provides an easy-to-use software tool to build and
debug programs. The C compiler compiles a C source program with extension .c to
produce an assembly source file with extension.asm. The assembler assembles an.asm
source file to produce a machine language object file with extension.obj. The linker
combines object files and object libraries as input to produce an executable file with
extension.out. This executable file represents a linked common object file format (COFF),
popular in Unix-based systems and adopted by several makers of digital signal processors
[25]. This executable file can be loaded and run directly on the C6713 processor. A linear
optimizer optimizes this source file to create an assembly file with extension .asm
(similar to the task of the C compiler). To create an application project, one can “add” the
appropriate files to the project. Compiler/linker options can readily be specified. A
number of debugging features are available, including setting breakpoints and watching
variables; viewing memory, registers, and mixed C and assembly code; graphing results;
and monitoring execution time. One can step through a program in different ways (step
into, over, or out).
Real-time analysis can be performed using real-time data exchange (RTDX). RTDX
allows for data exchange between the host PC and the target DSK, as well as analysis in
real time without stopping the target. Key statistics and performance can be monitored in

E
real time. Through the joint team action group (JTAG), communication with on-chip
emulation support occurs to control and monitor program execution. The C6713 DSK

C
board includes a JTAG interface through the USB port.
2.1. CCS installation and Support

E
Use the USB cable to connect the DSK board to the USB port on the PC. Use the 5-V
power supply included with the DSK package to connect to the +5-V power connector on

,
the DSK to turn it on. Install CCS with the CD-ROM included with the DSK, preferably

T
using the c:\C6713 structure (in lieu of c:\ti as the default).
The CCS icon should be on the desktop as “C6713DSK CCS” and is used to launch CCS.

E
The code generation tools (C compiler, assembler, linker) are used with CCS version 2.x.

I
CCS provides useful documentations included with the DSK package on the following
(see the Help icon):
1. Code generation tools (compiler, assembler, linker, etc.)

M
2. Tutorials on CCS, compiler, RTDX
3. DSP instructions and registers
4. Tools on RTDX, DSP/basic input/output system (DSP/BIOS), and so on. An extensive
amount of support material (pdf files) is included with CCS. There are also examples
included with CCS within the folder c:\C6713\examples. They illustrate the board and
chip support library files, DSP/BIOS, and so on. CCS Version 2.x was used to build and
test the examples included in this book.A number of files included in the following
subfolders/directories within c:\C6713 (suggested structure during CCS installation) can
be very useful:
1. myprojects: a folder supplied only for your projects. All the folders in the
accompanying book CD should be placed within this subdirectory.
2. bin: contains many utilities.
3. docs: contains documentation and manuals.
4. c6000\cgtools: contains code generation tools.
5. c6000\RTDX: contains support files for real-time data transfer.
6. c6000\bios: contains support files for DSP/BIOS.
7. examples: contains examples included with CCS.
8. tutorial: contains additional examples supplied with CCS.

E
2.2. Useful Types of Files
You will be working with a number of files with different extensions. They include:

C
1. file.pjt: to create and build a project named file
2. file.c: C source program

E
3. file.asm: assembly source program created by the user, by the C compiler, or by the
linear

,
optimizer

T
4. file.sa: linear assembly source program.The linear optimizer uses file.sa as input to
produce an assembly program file.asm

E
5. file.h: header support file

I
6. file.lib: library file, such as the run-time support library file rts6700.lib
7. file.cmd: linker command file that maps sections to memory
8. file.obj: object file created by the assembler

M
9. file.out: executable file created by the linker to be loaded and run on the C6713
processor
10. file.cdb: configuration file when using DSP/BIOS
2.3. Steps involved in programming
2.3.1. Connecting the C6713 DSK
2.3.2.Programming
1 Create a folder called “myprojects” on the desktop.
2 Run the C6713 DSK Code Composer Studio (C6713 DSK CCS).
3 Go to Project New, create a project called dtmf.
4 Make sure the Project Type is Executable (.out) and Target is TMS329C67XX.
5 Download the dtmf.cdb file from
http://www.ece.mtu.edu/labs/EElabs/EE3306/resources.
6 Once the project is created, go to Project -Add files to project, add the DSK6713 Board
support Library (BSL)file. This library will simplify the communication with the board
using C language. The file is located at C:\ti\c6000\dsk6713\lib\dsk6713bsl.lib. More
information about this library can be found in Help TMS320C6713 DSK Software Board
Support Library.

E
7 Next, include the “dtmf.cdb” file from the webpage. This configuration file will setup
all the DSP/BIOS correctly for the use of this lab.

C
8 Finally, you can create a new file and begin the laboratory assignment. Remember to
save the file as “dtmf.c” and include it to the project in order for it to run.

E
2.3.3 Compiling into Machine Language
1 After writing the code, the next step is to compile the code to machine language. Go to

,
Project Build.

T
2 The Build command will compile all the files that are include in this project and make
an

E
executable file for the DSP.

I
3 Compiler results are shown at the bottom of the window.
2.3.4 Loading program into DSP Processor
1 Finally, to run the program, load the program into the DSP. Go to File _ Load Program.

M
Load the executable file (.out) that the compiler generated (generally in the Debug
directory of the project).
2 The run the file loaded into the DSP. Go to Debug Run.

RESULTS:
The MATLAB and Code Composer Studio software tools are studied.
EXPERIMENT NO. - 3

OBJECTIVE: Write a MATLAB program for the generation of basic signals such as
unit impulse, unit step, ramp, exponential, sinusoidal & cosine.

OUTCOME: Students will able to generate of basic signals.

E
REQUIREMENT: MATLAB Software.

C
THEORY:
Singularity functions are an important classification of non-periodic signal. They can be

E
used to represent more complicated signal. Some of them are unit impulse function, step
function, ramp function.

T ,
1. Unit Impulse Function is defined as :-

E
, 1 otherwise

I
2. Unit Sep Function is defined as :-

M3. Unit Ramp Function is defined as :-


ALGORITHM

1. Enter the in values for unit step sequence and the length of ramp sequence or
exponential sequence.
2. Determine the function.
3. Plot the values as given by the function.
4. Stop.

E
PROGRAM

C
%PROGRAM FOR GENARATION OF UNIT IMPULSE SIGNAL

E
clc;
clear all;

,
close all;

T
t=-2:1:2;
y=[zeros(1,2), ones(1,1), zeros(1,2)]; subplot(2,2,1);

E
stem(t,y);

I
ylabel('Amplitude -- >');
xlabel('(a) n -- >');

M
%PROGRAM FOR GENERATION OF UNIT STEP SEQUENCE [u(n)-u(n-N)]
n= input('enter the N value');
t =-0:1:n-1;
y1=ones(1,n); subplot(2,2,2);
stem(t,y1);
ylabel('Amplitude -- >');
xlabel('(b) n -- >');

%PROGRAM FOR GENERATION OF RAMP FUNCTION


n1=input('Enter the length of Ramp sequence');
t= 0:n1;
subplot(2,2,3);
stem(t,t);
ylabel('Amplitude -- >');
xlabel('(c) n -- >');

%PROGRAM FOR GENERATION OF EXPONENTIAL FUNCTION


n2=input('enter the length of exponential sequence');

E
t=0:n2;
a=input('Enter the "a" value');

C
y2= exp(a*t);
subplot(2,2,4);

E
stem(t, y2);
ylabel('Amplitude -- >');

,
xlabel('(d) n -- >');

T
%PROGRAM FOR GENERATION OF SINE FUNCTION

E
t=0:.01:pi;

I
y=sin(2*pi*t);
figure(2);
subplot(2,1,1);

M
plot(t,y);
ylabel('Amplitude -- >');
xlabel('(a) n -- >');

%PROGRAM FOR GENERATION OF COSINE FUNCTION


t=0:.01:pi;
y=cos(2*pi*t);
subplot(2,1,2);
plot(t,y);
ylabel('Amplitude -- >');
xlabel('(b) n -- >');
FIGURES
Figures for unit Impulse, unit step, ramp function & exponential function for sine
and cosine functions
Fig1- Continuous Signals

C E
, E
T
Fig2- Discrete Signals

IE
M
RESULTS:
All the basic signals are produced and observed the behavior.
EXPERIMENT NO. 5

OBJECTIVE: Evaluate 4 point DFT of and IDFT of x(n)=1, 0 ≤ n ≤ 3; 0 elsewhere

OUTCOME: Students are able to calculate N- point DFT and IDFT.

REQUIREMENT: MATLAB Software

E
THEORY:
The Discrete Fourier transform (DFT) is a specific kind of discrete transform, used in

C
Fourier analysis. It transforms one function into another, which is called the frequency
domain representation, or simply the DFT, of the original function (which is often a

E
function in the time domain). The DFT requires an input function that is discrete. The

,
discrete input function must also have a limited (finite) duration, such as one period of a
periodic sequence or a windowed segment of a longer sequence. Unlike the Discrete-

T
Time-Fourier-Transform (DTFT), the DFT only evaluates enough frequency components
to reconstruct the finite segment. It is given by following mathematical formula:

IE
M
Inverse Discrete Fourier Transform: The Inverse Discrete Fourier Transform (IDFT)
maps the signal back from the frequency domain into the time domain. It is given by
following relationship:

PROCEDURE:
Step1: Give the discrete input for 4 points.
Step2: Apply the DFT formulation by taking input variables.
Step3: Plot the 4-point DFT.
Step4: Give the discrete input variable.
Step5: Apply the formulae of IDFT.
Step6: Plot the IDFT.

PROGRAM:
clear all;

E
clc;
clear;

C
N = input('Number of DFT points = ');
xn = input('Enter the sequence xn = '); %Get the sequence from user

E
ln = length(xn); %find the length of the sequence
xn = [xn zeros(1,N-ln)];

,
xk = zeros(1,N); %initialize an array of same size as that of input sequence

T
ixk = zeros(1,N); %initialize an array of same size as that of input sequence
%code block to find the DFT of the sequence

E
for k = 0:N-1

I
for n = 0:N-1
xk(k+1) = xk(k+1)+(xn(n+1)*exp((-1i)*2*pi*k*n/N));
end

M
end
%code block to plot the input sequence
t = 0:N-1;
subplot(2,2,1);
stem(t,xn);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('Input Sequence ---->');
grid on;
magnitude = abs(xk); %Find the magnitudes of individual DFT points
disp('DFT Sequence = ');
disp(magnitude);
%code block to plot the DFT sequence
t = 0:N-1;
subplot(2,2,2);
stem(t,magnitude);
ylabel('Amplitude ---->');
xlabel('K ---->');

E
title('DFT Sequence ---->');
grid on;

C
phase = angle(xk); %Find the phases of individual DFT points
disp('Phase = ');

E
disp(phase);
%code block to plot the Phase Response

,
t = 0:N-1;

T
subplot(2,2,3);
stem(t,phase);

E
ylabel('Phase ---->');

I
xlabel('K ---->');
title('Phase Response');
grid on;

M
% Code block to find the IDFT of the sequence
for n = 0:N-1
for k = 0:N-1
ixk(n+1) = ixk(n+1)+(xk(k+1)*exp(1i*2*pi*k*n/N));
end
end
ixk = ixk./N;
%code block to plot the IDFT sequence
t = 0:N-1;
subplot(2,2,4);
stem(t,ixk);
disp('IDFT Sequence = ');
disp(ixk);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('IDFT sequence ---->');
grid on;

E
RESULT:

The result corresponding to 4 point DFT and IDFT can be seen on the plot shown in Fig.

C
1. IDFT gives the signal which is same as the original one before DFT.

E
Fig. 1: 4-Point DFT and IDFT plot

T ,
IE
M Fig. 1: 4-Point DFT and IDFT plot using FFT and IFFT functions.
EXPERIMENT NO. - 6

OBJECTIVE - To implement FFT algorithm.

OUTCOME: Students understand the programming for implementing the FFT algorithm.

E
REQUIREMENT: MATLAB software

C
THEORY:
FFT is an algorithm to convert a time domain signal to DFT efficiently. The groups are

E
decided by the number of samples. A much more computationally efficient algorithm
Works using the divide and conquer principle. First developed by Cooley and Tukey in

,
1965!
Radix-2: DIT or, DIF

T
Radix-2 is the first FFT algorithm. It was proposed by Cooley and Tukey in 1965. The
algorithms appear either in

E
(a) Decimation In Time (DIT), or,

I
(b) Decimation In Frequency (DIF).
DIT and DIF, both yield same complexity and results. They are complementary.

M
C E
, E
T
PROGRAM:

E
%DECIMATION IN TIME [DIT] ALGORITHM function e=dit(x)

I
x=input ('Enter the sequence: ') ;
t=nextpow2(length(x)); % round to next highest power of 2 because radix-2
j=[x zeros(1,(2^t)-length(x))] ; % zero padding

M
N=length(j); % calculate length of padded sequence
S=log2(N); % no. of stages
j=bitrevorder(j); % bit-reverse the input sequence
for stage=1:S
a=1; % Initialise a and b, start points of the butterfly for each stage
b=1+2^(stage-1);
n=0;
while( n<=2^(stage-1)-1 && b<=N)
e=exp((-1i)*2*pi*n/(2^stage)); % Incorporate the twiddle factor
y=j(a)+e*j(b); % Butterfly structure
z=j(a)-e*j(b);
j(a)=y;
j(b)=z;
a=a+1;
b=b+1; % Increment a and b and n for the next butterfly structure
n=n+1;
if(rem(b,2^stage)==1)
a=a+2^(stage-1); % Discontinuity of butterfly struc, change a,b and n

E
b=b+2^(stage-1);
n=0;

C
end
end

E
end
disp(j)

,
e=j;

T
% end
% figure;

E
% subplot (211);

I
% stem(x);
% xlabel('Samples')
% ylabel('Amplitude')

M
% % title('Input Sequence')
% % subplot(212)
% % stem(abs(y))
% % xlabel('Samples')
% % ylabel('Amplitude')
% % title('DIT-FFT Output-Magnitude')

RESULTS: The FFT algorithm is implemented using DIT method.


EXPERIMENT NO.-7

OBJECTIVE: Verify Blackman and Hamming windowing techniques.

OUTCOME: Designing and verification of all types of Blackman and Hamming


windowing techniques can be obtained.

E
REQUIREMENT: MATLAB Software
1. To develop a program to design a FIR Low Pass, High Pass, Band Pass &

C
Band Stop Filter using Blackman window.

E
ALGORITHM
1. Get the passband & stopband ripples.

,
2. Get the passband & stopband edge frequencies.

T
3. Get the sampling frequency.
4. Calculate the order of the filter.

E
5. Find the filter coefficients.

I
6. Draw the magnitude & Phase response.

PROGRAM

M
% Program for the design of fir low pass, high pass, band pass & band stop filters using
Blackman window

clc;

clear all;

close all;

rp = input ('enter the passband ripple');

rs = input ('enter the stopband ripple');

fp = input ('enter the passband frequency');

fs = input ('enter the stopband frequency');


f = input ('enter the sampling frequency');

wp=2*fp/f; ws=2*fs/f;

num= -20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

n= ceil(num/dem);

n1= n+1;

E
if (rem(n,2)~=0)

n1=n;

C
n=n-1;

E
end

,
y=blackman(n1);

T
%LOW PASS FILTER

E
b= fir1(n,wp,y);

I
[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

M
subplot(2,2,1);

plot(o/pi, m);

ylabel('Gain in dB-->');

xlabel('(a) Normalized Frequency');

%HIGH PASS FILTER

b= fir1(n,wp,'high',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,2);
plot(o/pi, m);

ylabel('Gain in dB-->');

xlabel('(b) Normalized Frequency');

%BANDPASS FILTER

wn=[wp ws];

E
b= fir1(n,wn,y);

[h,o]=freqz(b,1,256);

C
m=20*log10(abs(h));

E
subplot(2,2,3);

,
plot(o/pi, m);

ylabel('Gain in dB-->');

T
xlabel('(c)Normalized Frequency');

E
%BANDSTOP FILTER

I
b= fir1(n,wn,'stop',y);

[h,o]=freqz(b,1,256);

M
m=20*log10(abs(h));

subplot(2,2,4);

plot(o/pi, m);

ylabel('Gain in dB-->');

xlabel('(d) Normalized Frequency');

INPUT
enter the passband ripple .03
enter the stopband ripple.01
enter the passband frequency2000
enter the stopband frequency2500
enter the sampling frequency7000

FIGURES

50 50

E
0 0
Gain in dB-->

Gain in dB-->
-50 -50

C
-100 -100

E
-150 -150
0 0.5 1 0 0.5 1
(a) Normalized Frequency (b) Normalized Frequency

,
0 5

T
Gain in dB-->

Gain in dB-->

-50 0

E
-100 -5

I
-150 -10
0 0.5 1 0 0.5 1
(c) Normalized Frequency (d) Normalized Frequency

M2. To develop a program to design a FIR Low Pass, High Pass, Band Pass &

ALGORITHM
Band Stop Filter using Hamming window.

1. Get the passband & stopband ripples.


2. Get the passband & stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter.
5. Find the filter coefficients.
6. Draw the magnitude & Phase response.

PROGRAM
% Program for the design of fir low pass, high pass, band pass & band stop filters using
Hamming window

E
clc;
clear all;

C
close all;
rp = input ('enter the passband ripple');

E
rs = input ('enter the stopband ripple');
fp = input ('enter the passband frequency');

,
fs = input ('enter the stopband frequency');

T
f = input ('enter the sampling frequency');
wp=2*fp/f; ws=2*fs/f;

E
num= -20*log10(sqrt(rp*rs))-13;

I
dem=14.6*(fs-fp)/f;
n= ceil(num/dem);
n1= n+1;

M
if (rem(n,2)~=0)
n1=n;
n=n-1;
end
y=hamming(n1);

%LOW PASS FILTER


b= fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(a) Normalized Frequency');

%HIGH PASS FILTER


b= fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);

E
m=20*log10(abs(h));
subplot(2,2,2);

C
plot(o/pi, m);
ylabel('Gain in dB-->');

E
xlabel('(b) Normalized Frequency');

,
%BANDPASS FILTER

T
wn=[wp ws];
b= fir1(n,wn,y);

E
[h,o]=freqz(b,1,256);

I
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi, m);

M
ylabel('Gain in dB-->');
xlabel('(c) Normalized Frequency');

%BANDSTOP FILTER
b= fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(d) Normalized Frequency');
INPUT
enter the passband ripple .02
enter the stopband ripple .01
enter the passband frequency1200
enter the stopband frequency1700
enter the sampling frequency9000

E
FIGURES

C
50 50

0
Gain in dB-->

Gain in dB-->
0

E
-50
-50

,
-100

-150 -100
0 0.5 1 0 0.5 1

T
(a) Normalized Frequency (b) Normalized Frequency

0 5

E
0
Gain in dB-->

Gain in dB-->

I
-50
-5
-100
-10

M
-150 -15
0 0.5 1 0 0.5 1
(c) Normalized Frequency (d) Normalized Frequency

RESULTS:
The results are satisfactory verified the Blackman and Hamming windowing techniques.
EXPERIMENT NO. - 8

OBJECTIVE - Implement IIR Butterworth analog Low Pass for a 4 KHz cut off
frequency.

OUTCOME: Students are able to realize the IIR Butterworth analog Low Pass filter.

E
REQUIREMENT: MATLAB software

C
PROGRAM:

E
Syntax
[b,a] = butter(n,Wn)

,
[b,a] = butter(n,Wn,ftype)
[z,p,k] = butter(___)

T
[A,B,C,D] = butter(___)
[___] = butter(___,'s')

E
Description

I
[b,a] = butter(n,Wn) returns the transfer function coefficients of an nth-order lowpass
digital Butterworth filter with normalized cutoff frequency Wn.

M
[b,a] = butter(n,Wn,ftype) designs a lowpass, highpass, bandpass, or
bandstop Butterworth filter, depending on the value of ftype and the number of elements
of Wn. The resulting bandpass and bandstop designs are of order 2n.
Note: See Limitations for information about numerical issues that affect forming the
transfer function.

[z,p,k] = butter(___) designs a lowpass, highpass, bandpass, or bandstop


digital Butterworth filter and returns its zeros, poles, and gain. This syntax can include
any of the input arguments in previous syntaxes.example
[A,B,C,D] = butter(___) designs a lowpass, highpass, bandpass, or bandstop
digital Butterworth filter and returns the matrices that specify its state-space
representation.
[___] = butter(___,'s') designs a lowpass, highpass, bandpass, or bandstop
analog Butterworth filter with cutoff angular frequency Wn.
Example
Lowpass Butterworth Transfer Function
Design a 6th-order low pass Butterworth filter with a cutoff frequency of 4KHz, which,
for data sampled at 1000 Hz, corresponds to rad/sample. Plot its magnitude and
phase responses. Use it to filter a 1000-sample random signal.
fc = 4000;
fs = 1000;

[b,a] = butter(6,fc/(fs/2));
freqz(b,a)

C E
, E
E T
I
M
dataIn = randn(1000,1);
dataOut = filter(b,a,dataIn);

RESULT:
The outcome shows the successful implementation of IIR Butterworth analog Low Pass.
EXPERIMENT NO - 9

OBJECTIVE: Verify Circular Convolution using code composer studio.

OUTCOME: Students trained to program for implementing the Circular convolution using
TMS320C6713.

E
REQUIREMENT: CC Studio

C
THEORY: Steps for Cyclic Convolution
Steps for cyclic convolution are the same as the usual convolution, except all index

E
calculations are done "mod N" = "on the wheel" Steps for Cyclic Convolution

,
Step1: "Plot f[m] and h[-m]

E T
I Subfigure 1.1 Subfigure 1.2

M
Step 2: "Spin" h[-m] n times Anti Clock Wise (counter-clockwise)
to get h[n-m] (i.e. Simply rotate the sequence, h[n],
clockwise by n steps)

Figure 2: Step 2
Step 3: Point wise multiply the f[m] wheel and th/z[nm] wheel.
PROCEDURE:
 Open Code Composer Studio, make sure the DSP kit is turned on
 Start a new project using 'Project-new pull down menu, save it in a separate
directory.
 Add the source files to the project using 'Project-^add files to project' pull
down menu.

E
 Add the linker command file hello.cmd
 Add the run time support library file rts6700.lib

C
 Compile the program using the 'Project-compile' pull down menu or by clicking
the shortcut icon on the left side of program window.

E
 Build the program using the 'Project-Build' pull down menu or by clicking the

,
shortcut icon on the left side of program window.
 Load the program(Diff Eq.out) in program memory of DSP chip using the

T
 'File-load program' pull down menu.
 To View output graphically

E
 Select view -^ Graph -> Time and frequency.

PROGRAM:

I
M
#include<stdio.h>

#include<math.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) /*If length of both sequences are not equal*/

E
{
if(m>n) /* Pad the smaller sequence with zero*/

C
{
for(i=n;i<m;i++)

E
h[i]=0;
n=m;

,
}

T
for(i=m;i<n;i++)
x[i]=0;

E
m=n;

I
}
y[0]=0;
a[0]=h[0];

M
for(j=1;j<n;j++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}

E
/*displaying the result*/
printf(" the circular convolution is\n");

C
for(i=0;i<n;i++)
printf("%d \t",y[i]);

E
}
Output:

T ,
IE
M
RESULTS:

The outcomes are of Circular Convolution are verified using code composer studio.
EXPERIMENT NO-10

OBJECTIVE: Verify linear convolution of two sequence using code composer studio.

OUTCOME: Students are able to write a program to implement linear convolution using
TMS320C6713.

E
REQUIRMENT: CC Studio.

C
THEORY: Linear Convolution Involves the following operations.
1. Folding

E
2. Multiplication
3. Addition

,
4. Shifting

T
These operations can be represented by a Mathematical Expression as follows:

IE
x[ ]= Input signal Samples

M
h[ ]= Impulse response co-efficient.
y[ ]= Convolution output. n = No. of Input
samples h = No. of Impulse response co-
efficient.

PROCEDURE:

 Open Code Composer Studio, make sure the DSP kit is turned on
 Start a new project using 'Project-new pull down menu, save it in a separate
directory.
 Add the source files to the project using 'Project-^add files to project' pull
down menu.
 Add the linker command file hello.cmd
 Add the run time support library file rts6700.lib
 Compile the program using the 'Project-compile' pull down menu or by clicking
the shortcut icon on the left side of program window.
 Build the program using the 'Project-Build' pull down menu or by clicking the

E
shortcut icon on the left side of program window.
 Load the program(Diff Eq.out) in program memory of DSP chip using the

C
 'File-load program' pull down menu.
 To View output graphically

E
 Select view -^ Graph -> Time and frequency.

T ,
Algorithm to implement 'C’ or Assembly program for Convolution:

Eg: x[n] = {1, 2, 3, 4}

E
h[k] = {1, 2, 3, 4}

I
Where: n=4, k=4. ; Values of n & k should be a multiple of 4.

M
If n & k are not multiples of 4, pad with zero's to make
multiples of 4
r= n+k-1 ; Size of output sequence. =
4+4-1 = 7.

r^ _____ 0 ______ 1 ______ 2 _____3 _____ 4 _____ 5 _____ 6 _ _


n= 0 x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]
1 x[1]h[0] x[1]h[1] x[1]h[2] x[1]h[3]
2 x[2]h[0] x[2]h[1] x[2]h[2] x[2]h[3]
3 x[3]h[0] x[3]h[1] x[3]h[2] x[3]h[3]
Output: y[r] = { 1, 4, 10, 20, 25, 24, 16}.

PROGRAM:

#include<stdio.h>
#include<math.h>
int y[20];

E
main()
{

C
int m=6;
int n=6;

E
int i=0,j;

,
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int h[15]={1,2,3,4,5,6,0,0,0,0,0,0};

T
for(i=0;i<m+n-1;i++)
{

E
y[i]=0;

I
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}

M
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}

Output:
C E
, E
E T
RESULTS-

I
M
The results are verified the circular convolution of two sequence using code composer
studio.
EXPERIMENT NO. - 11

OBJECTIVE: To implement Tone Generation.

OUTCOME: To be able to understand the meaning of DTMF and generate DTMF


sequence for 1234567890*# & observe its spectrogram.

E
REQUIREMENT: MATLAB Software

C
THEORY:
DTMF (dual tone multi frequency) is the signal which is combination of two signals of

E
different frequencies. It is widely used in a number of applications ranging from

,
telephone/cell phone handsets, hobby kits, for control signaling in telecommunication etc.
In conventional telephone handsets, rotary handsets (pulse dialing) were replaced by

T
touch-tone dialing since it was faster.
There are twelve DTMF signals, each of which is made up of two tones from the

E
following selection: 697 Hz, 770 Hz, 852 Hz, 941 Hz, 1209 Hz, 1336 Hz, and 1477Hz.

I
The tones are divided into two groups (low and high), and each DTMF signal uses one
from each group. This prevents any harmonics from being misinterpreted as part of the
signal. The following table shows the frequencies used for each signal.

M
Table 1: Different frequency combination corresponding to Different digits.

Upper Band
1209
Lower Band 1336 Hz 1477 Hz
Hz

697 Hz 1 2 3

770 Hz 4 5 6
852 Hz 7 8 9

941 Hz * 0 #

PROCEDURE:
Step 1: Select the number who’s DTMF we have to find.
Step 2: Input the two signal of corresponding number.

E
Step3: Calculate the DTMF and plot it using MATLAB.
Step4: Plot the frequency spectrum of corresponding DTMF.

E C
PROGRAM:
-----------------DTMF signal generation corresponding to digit “0”---------

,
clc;
%DTMF corresponding to "0"

T
f1 = 941; f2 = 1336; fs = 8*f2;
t = 0:(1/fs):(4/f1);

E
x1 = sin(2*pi*f1*t);

I
x2 = sin(2*pi*f2*t);
x = x1 + x2;

M
subplot(3,1,1)
plot(1000*t,x1,'k');
title('941 Hz Frequency Component');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,2)
plot(1000*t,x2,'k');

title('1336 Hz Frequency Component');


xlabel('Time');
ylabel('Amplitude');
subplot(3,1,3)
plot(1000*t,x,'k');
title('DTMF corresponding to "0"');
xlabel('Time');
ylabel('Amplitude');
Y = fft(x,64);
p = Y.*conj(Y)/64;

E
f = fs*(0:31)/64;
figure;

C
plot(f,p(1:32),'k');
title('Spectrum corresponding to "0"');

E
xlabel('Time');
ylabel('Frequency');

T ,
------------DTMF signal generation corresponding to digit “9”--------------

IE
%DTMF corresponding to "9"
f1 = 852; f2 = 1477; fs = 8*f2;
t = 0:(1/fs):(4/f1);

M
x1 = sin(2*pi*f1*t);
x2 = sin(2*pi*f2*t);
x = x1 + x2;
subplot(3,1,1)
plot(1000*t,x1,'k');
title('852 Hz Frequency Component');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,2)
plot(1000*t,x2,'k');
title('1477 Hz Frequency Component');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,3)
plot(1000*t,x,'k');

title('DTMF corresponding to "9"');

E
xlabel('Time');
ylabel('Amplitude');

C
Y = fft(x,64);

E
p = Y.*conj(Y)/64;
f = fs*(0:31)/64;

,
figure;

T
plot(f,p(1:32),'k');
title('Spectrum corresponding to "9"');

E
xlabel('Time');

I
ylabel('Frequency');

RESULTS & DISCUSSIONS

M
852 Hz Frequency Component
1
Amplitude

-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time
1477 Hz Frequency Component
1
Amplitude

-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time
DTMF waveform corresponding to "9"
2
Amplitude

-2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time

Fig. 1: Two frequencies corresponding to “9” and its DTMF


Spectrogram corresponding to "9"
12

10

8
Power

E
4

C
2

E
0
0 500 1000 1500 2000 2500 3000
Frequency

,
Fig. 2: Spectrogram corresponding to “9”

T
 The waveforms of upper and lower frequencies and corresponding DTMF output
for digit “0” is shown in Fig.1. The spectrum of DTMF signal is shown in Fig. 2.

E
 DTMF waveform looks as a random signal.

I
 From the spectrum of DTMF signal, it is clear that there are two peaks at
frequencies, 941 Hz and 1336 Hz, verifying the fact that the signal is
combination of these frequencies.

M
 Similarly, the waveforms and spectrogram corresponding to other digits/symbols
can be drawn.
EXPERIMENT NO. - 12

OBJECTIVE - To implement floating point arithmetic.

OUTCOME: Students understand implementation of floating point arithmetic.

E
REQUIREMENT: MATLAB software

C
PROGRAM:
Floating-Point Numbers

E
Fixed-point numbers are limited in that they cannot simultaneously represent very large

,
or very small numbers using a reasonable word size. This limitation can be overcome by
using scientific notation. With scientific notation, you can dynamically place the binary

T
point at a convenient location and use powers of the binary to keep track of that location.
Thus, you can represent a range of very large and very small numbers with only a few

E
digits.

I
You can represent any binary floating-point number in scientific notation form as f2e,
where f is the fraction (or mantissa), 2 is the radix or base (binary in this case), and e is

M
the exponent of the radix. The radix is always a positive number, while f and e can be
positive or negative.

When performing arithmetic operations, floating-point hardware must take into account
that the sign, exponent, and fraction are all encoded within the same binary word. This
results in complex logic circuits when compared with the circuits for binary fixed-point
operations.

The Fixed-Point Designer™ software supports single-precision and double-precision


floating-point numbers as defined by the IEEE® Standard 754.

Scientific Notation
A direct analogy exists between scientific notation and radix point notation. For example,
scientific notation using five decimal digits for the fraction would take the form

±d.dddd×10p=±ddddd.0×10p−4=±0.ddddd×10p+1,
where d=0,...,9 and p is an integer of unrestricted range.

Radix point notation using five bits for the fraction is the same except for the number
base

E
±b.bbbb×2q=±bbbbb.0×2q−4=±0.bbbbb×2q+1,
where b=0,1 and q is an integer of unrestricted range.

C
For fixed-point numbers, the exponent is fixed but there is no reason why the binary point

E
must be contiguous with the fraction. For more information, see Binary-Point-Only
Scaling.

,
The IEEE Format

T
The IEEE Standard 754 has been widely adopted, and is used with virtually all floating-
point processors and arithmetic coprocessors—with the notable exception of many DSP

E
floating-point processors.

I
Among other things, this standard specifies four floating-point number formats, of which
singles and doubles are the most widely used. Each format contains three components: a

M
sign bit, a fraction field, and an exponent field. These components, as well as the specific
formats for singles and doubles, are discussed in the sections that follow.

The Sign Bit

While two's complement is the preferred representation for signed fixed-point numbers,
IEEE floating-point numbers use a sign/magnitude representation, where the sign bit is
explicitly included in the word. Using this representation, a sign bit of 0 represents a
positive number and a sign bit of 1 represents a negative number.

The Fraction Field


In general, floating-point numbers can be represented in many different ways by shifting
the number to the left or right of the binary point and decreasing or increasing the
exponent of the binary by a corresponding amount.

To simplify operations on these numbers, they are normalized in the IEEE format. A
normalized binary number has a fraction of the form 1.f where f has a fixed size for a
given data type. Since the leftmost fraction bit is always a 1, it is unnecessary to store this
bit and is therefore implicit (or hidden). Thus, an n-bit fraction stores an n+1-bit number.

E
The IEEE format also supports denormalized numbers, which have a fraction of the form
0.f. Normalized and denormalized formats are discussed in more detail in the next

C
section.

E
The Exponent Field

In the IEEE format, exponent representations are biased. This means a fixed value (the

,
bias) is subtracted from the field to get the true exponent value. For example, if the

T
exponent field is 8 bits, then the numbers 0 through 255 are represented, and there is a
bias of 127. Note that some values of the exponent are reserved for

E
flagging Inf (infinity), NaN (not-a-number), and denormalized numbers, so the true

I
exponent values range from -126 to 127. See the sections Inf and NaN.

Single-Precision Format

M
The IEEE single-precision floating-point format is a 32-bit word divided into a 1-bit sign
indicator s, an 8-bit biased exponent e, and a 23-bit fraction f. For more information,
see The Sign Bit, The Exponent Field, and The Fraction Field. A representation of this
format is given below.

The relationship between this format and the representation of real numbers is given by
value= (−1)s(2e−127)(1.f)(−1)s(2e−126)(0.f)exceptional value normalized, 0<e

<255,denormalized, e=0, f>0,otherwise.

Exceptional Arithmetic discusses denormalized values.

Double-Precision Format

The IEEE double-precision floating-point format is a 64-bit word divided into a 1-bit sign

E
indicator s, an 11-bit biased exponent e, and a 52-bit fraction f.For more information,
see The Sign Bit, The Exponent Field, and The Fraction Field. A representation of this

C
format is shown in the following figure.

, E
T
The relationship between this format and the representation of real numbers is given by

IE
value= (−1)s(2e−1023)(1.f)(−1)s(2e−1022)(0.f)exceptional value normalized, 0

<e<2047,denormalized, e=0, f>0otherwise.,

M
Exceptional Arithmetic discusses denormalized values.

Range and Precision

The range of a number gives the limits of the representation while the precision gives the
distance between successive numbers in the representation. The range and precision of an
IEEE floating-point number depend on the specific format.

Range

The range of representable numbers for an IEEE floating-point number with f bits
allocated for the fraction, e bits allocated for the exponent, and the bias of e given

by bias=2(e−1)−1 is given below.


where

 Normalized positive numbers are defined within the

range 2(1−bias) to (2−2−f)2bias.

E
 Normalized negative numbers are defined within the

range −2(1−bias) to −(2−2−f)2bias.

C
 Positive numbers greater than (2−2−f)2bias and negative numbers greater

than −(2−2−f_2bias are overflows.

E
Positive numbers less than 2(1−bias) and negative numbers less

,

than −2(1−bias) are either underflows or denormalized numbers.

T
 Zero is given by a special bit pattern, where e=0 and f=0.

E
Overflows and underflows result from exceptional arithmetic conditions. Floating-point

I
numbers outside the defined range are always mapped to ±Inf.

You can use the MATLAB® commands realmin and realmax to determine the dynamic
range of double-precision floating-point values for your computer.

M
Precision

Because of a finite word size, a floating-point number is only an approximation of the


“true” value. Therefore, it is important to have an understanding of the precision (or
accuracy) of a floating-point result. In general, a value v with an accuracy q is specified
by v±q. For IEEE floating-point numbers,

v = (–1)s(2e–bias)(1.f)

and

q = 2–f×2e–bias

Thus, the precision is associated with the number of bits in the fraction field.
Floating-Point Data Type Parameters

The high and low limits, exponent bias, and precision for the supported floating-point
data types are given in the following table.

Data Type Low Limit High Limit Exponent Bias Precision

Single 2-126 ≈ 10-38 2128 ≈ 3 · 1038 127 2-23 ≈ 10-7

Double 2-1022 ≈ 2 · 10-308 21024 ≈ 2 · 10308 1023 2-52 ≈ 10-16

E
Because of the sign/magnitude representation of floating-point numbers, there are two
representations of zero, one positive and one negative. For both

C
representations e = 0 and f.0 = 0.0.

E
Exceptional Arithmetic

In addition to specifying a floating-point format, the IEEE Standard 754 specifies

,
practices and procedures so that predictable results are produced independently of the

T
hardware platform. Specifically, denormalized numbers, Inf, and NaN are defined to deal
with exceptional arithmetic (underflow and overflow).

E
If an underflow or overflow is handled as Inf or NaN, then significant processor overhead

I
is required to deal with this exception. Although the IEEE Standard 754 specifies
practices and procedures to deal with exceptional arithmetic conditions in a consistent
manner, microprocessor manufacturers might handle these conditions in ways that depart

M
from the standard.

Denormalized Numbers

Denormalized numbers are used to handle cases of exponent underflow. When the
exponent of the result is too small (i.e., a negative exponent with too large a magnitude),
the result is denormalized by right-shifting the fraction and leaving the exponent at its
minimum value. The use of denormalized numbers is also referred to as gradual
underflow. Without denormalized numbers, the gap between the smallest representable
nonzero number and zero is much wider than the gap between the smallest representable
nonzero number and the next larger number. Gradual underflow fills that gap and reduces
the impact of exponent underflow to a level comparable with roundoff among the
normalized numbers. Thus, denormalized numbers provide extended range for small
numbers at the expense of precision.

Inf

Arithmetic involving Inf (infinity) is treated as the limiting case of real arithmetic, with
infinite values defined as those outside the range of representable numbers, or –
∞ ≤ (representable numbers) < ∞. With the exception of the special cases discussed
below (NaN), any arithmetic operation involving Inf yields Inf. Inf is represented by the

E
largest biased exponent allowed by the format and a fraction of zero.

C
NaN

A NaN (not-a-number) is a symbolic entity encoded in floating-point format. There are

E
two types of NaN: signaling and quiet. A signaling NaN signals an invalid operation

,
exception. A quiet NaN propagates through almost every arithmetic operation without
signaling an exception. The following operations result in a NaN: ∞–∞, –∞+∞, 0×∞, 0/0,

T
and ∞/∞.

Both types of NaN are represented by the largest biased exponent allowed by the format

E
and a fraction that is nonzero. The bit pattern for a quiet NaN is given by 0.f where the

I
most significant number in f must be a one, while the bit pattern for a signaling NaN is
given by 0.f where the most significant number in f must be zero and at least one of the

M
remaining numbers must be nonzero.
EXPERIMENT NO.- 13

OBJECTIVE: Write a MATLAB program to design a FIR Low pass, High pass, Band
pass, Band stop filter using Rectangular window technique.

OUTCOME: Students will able to program and design the several filters using
Rectangular window technique.

E
REQUIREMENT: MATLAB Software

C
ALGORITHM

E
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.

,
3. Get the sampling frequency.

T
4. Calculate the order of the filter
5. Find the filter coefficients.

E
6. Draw the magnitude & Phase response.

I
PROGRAM
% PROGRAM TO DESIGN FIR LOW PASS FILTER AND HIGH PASS FILTER

M
USING RECTANGULAR WINDOW
clc;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
f=input('enter the sampling frequency');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1= n+1;
if (rem(n,2)~=0)
n1=n;
n=n-1

E
end
y=boxcar(n1);

C
% LOW PASS FILTER

E
b= fir1(n,wp,y);
[h,o]= freqz(b,1,256);

,
m=20*log10(abs(h));

T
subplot (2,2,1);
plot(o/pi,m);

E
ylabel('Gain in dB-->');

I
xlabel('(a)Normalized frequency-->');

% HIGH PASS FILTER

M
b= fir1(n,wp,'high',y);
[h,o]= freqz(b,1,256);
m=20*log10(abs(h));
subplot (2,2,2);
plot(o/pi,m);
ylabel('Gain in dB-->');
xlabel('(b)Normalized frequency-->');

% BAND PASS FILTER


wn=[wp,ws];
b= fir1(n,wn,y);
[h,o]= freqz(b,1,256);
m=20*log10(abs(h));
subplot (2,2,3);
plot(o/pi,m);
ylabel('Gain in dB-->');
xlabel('(c) Normalized frequency-->');

% BAND STOP FILTER


b= fir1(n,wn,'stop',y);

C E
E
[h,o]= freqz(b,1,256);
m=20*log10(abs(h));

,
subplot (2,2,2);

T
plot(o/pi,m);
ylabel('Gain in dB-->');

E
xlabel('(d) Normalized frequency-->');

I
M
INPUT
enter the passband ripple0.05
enter the stopband ripple0.04
enter the passband frequency1500
enter the stopband frequency2000
enter the sampling frequency9000
FIGURES
50 50
Gain in dB-->

Gain in dB-->
0 0

-50 -50

-100 -100
0 0.5 1 0 0.5 1
(a) Normalized frequency--> (b) Normalized frequency-->

E
50 10

C
Gain in dB-->

Gain in dB-->
0 0

E
-50 -10

,
-100 -20
0 0.5 1 0 0.5 1
(c) Normalized frequency--> (d) Normalized frequency-->

T
RESULTS:

E
The design a FIR Low pass, High pass, Band pass, Band stop filter using Rectangular

I
window technique are done successfully.

M
EXPERIMENT NO. 14

OBJECTIVE: Write a MATLAB program to design Chebyshev Type-I (Low pass filter,
High pass, Band pass& Band stop filter)

OUTCOME: Students will able to program and design the filters using Chebyshev
Type-I.

E
REQUIREMENT: MATLAB Software

C
ALGORITHM:

E
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.

,
3. Get the sampling frequency.

T
4. Calculate the order of the filter
5. Find the filter coefficients.

E
6. Draw the magnitude & Phase response.

I
PROGRAM
%Write a MATLAB program to design Chebyshev type-I low pass filter

M
clc;
close all;
clear all;
format long
rp= input ('enter the passband ripple....');
rs= input ('enter the stopband ripple....');
wp= input ('enter the passband freq....');
ws= input ('enter the stopband freq....');
fs= input ('enter the sampling freq....');
w1=2*wp/ fs;
w2=2*ws/ fs;
[n, wn]=cheb1ord (w1,w2,rp,rs,'s');
[b,a]=cheby1(n,rp,wn,'s');
w=0: .01:pi;
[h,om] = freqz(b,a,w);
m=20*log10(abs(h));
an=angle (h);
subplot (2,1,1); plot (om/pi,m);

E
ylabel('Gain in dB-->'); xlabel('(a) Normalised frequency-->');
subplot (2,1,2); plot (om/pi,an);

C
ylabel('Phase in radians-->'); xlabel('(b) Normalised frequency-->');
% Write a MATLAB program to design Chebyshev type-I highpass filter

E
clc;
close all;

,
clear all;

T
format long
rp= input ('enter the passband ripple....');

E
rs= input ('enter the stopband ripple....');

I
wp= input ('enter the passband freq....');
ws= input ('enter the stopband freq....');
fs= input ('enter the sampling freq....');

M
w1=2*wp/ fs;
w2=2*ws/ fs;
[n, wn]=cheb1ord (w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
w=0: .01/pi:pi;
[h,om] = freqz(b,a,w);
m=20*log10(abs(h));
an=angle (h);
subplot (2,1,1); plot (om/pi,m);
ylabel('Gain in dB-->'); xlabel('(a) Normalised frequency-->');
subplot (2,1,2); plot (om/pi,an);
ylabel('Phase in radians-->'); xlabel('(b) Normalised frequency-->');

% Write a MATLAB program to design Chebyshev type-I band pass filter


clc;
close all;
clear all;
format long

E
rp= input ('enter the passband ripple....');
rs= input ('enter the stopband ripple....');

C
wp= input ('enter the passband freq....');
ws= input ('enter the stopband freq....');

E
fs= input ('enter the sampling freq....');
w1=2*wp/ fs;

,
w2=2*ws/ fs;

T
[n]=cheb1ord (w1,w2,rp,rs);
wn=[w1,w2];

E
[b,a]=cheby1(n,rp,wn,'bandpass');

I
w=0: .01:pi;
[h,om] = freqz(b,a,w);
m=20*log10(abs(h));

M
an=angle (h);
subplot (2,1,1); plot (om/pi,m);
ylabel('Gain in dB-->'); xlabel('(a) Normalised frequency-->');
subplot (2,1,2); plot (om/pi,an);
ylabel('Phase in radians-->'); xlabel('(b) Normalised frequency-->');

Write a MATLAB program to design Chebyshev type-I low band stop filter
clc;
close all;
clear all;
format long
rp= input ('enter the passband ripple....');
rs= input ('enter the stopband ripple....');
wp= input ('enter the passband freq....');
ws= input ('enter the stopband freq....');
fs= input ('enter the sampling freq....');
w1=2*wp/ fs;
w2=2*ws/ fs;

E
[n]=cheb1ord (w1,w2,rp,rs);
wn=[w1,w2];

C
[b,a]=cheby1(n,rp,wn,'stop');
w=0: .01:pi;

E
[h,om] = freqz(b,a,w);
m=20*log10(abs(h));

,
an=angle (h);

T
subplot (2,1,1); plot (om/pi,m);
ylabel('Gain in dB-->'); xlabel('(a) Normalised frequency-->');

E
subplot (2,1,2); plot (om/pi,an);

I
ylabel('Phase in radians-->'); xlabel('(b) Normalised frequency-->');

INPUTS

M
Low pass:-
enter the passband ripple....0.23
enter the stopband ripple....47
enter the passband freq....1300
enter the stopband freq....1550
enter the sampling freq....7800
High pass:-

enter the passband ripple....0.3


enter the stopband ripple....60
enter the passband freq....1500
enter the stopband freq....2000
enter the sampling freq....9000

Band Pass:-
enter the passband ripple.....4
enter the stopband ripple....35
enter the passband freq....2000

E
enter the stopband freq....2500
enter the sampling freq....10000

C
Band Stop:-
enter the passband ripple.....25

E
enter the stopband ripple....40
enter the passband freq....2500

,
enter the stopband freq....2750

T
enter the sampling freq....7000

E
FIGURES

I
LOW

M
-100
Gain in dB-->

-200

-300

-400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency-->

4
Phase in radians-->

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency-->

HIGH PASS
BAND PASS

Gain in dB--> -200

-400

-600
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

E
(a) Normalised frequency-->

4
Phase in radians-->

C
0

-2

E
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency-->

,
BANDSTOP

T
0

-50
Gain in dB-->

E
-100

I
-150

-200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency-->

M
4
Phase in radians-->

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency-->

RESULTS:
The design a Chebyshev Type-I (Low pass filter, High pass, Band pass& Band stop filter)
are completed effectively.

You might also like