Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
A Digital Signal Processor (DSP) is an integrated circuit designed for high-speed data
manipulations, and is used in audio, communications, image manipulation, and other data-
acquisition and data-control applications.
Digital signals are those that are transmitted within or between computers, in which
information is represented by discrete states – for example, high voltages and low voltages –
rather than by continuously variable levels in a continuous stream, as in an analog signal.
DSP Chip
A DSP chip can contain many hardware elements; some of the more common ones are
listed below:
110
1. Central Arithmetic Unit: This part of the DSP performs major arithmetic functions such
as multiplication and addition. It is the part that makes the DSP so fast in comparison
with traditional processors.
2. Auxiliary Arithmetic Unit: DSPs frequently have an auxiliary arithmetic unit that
performs pointer arithmetic, mathematical calculations, or logical operations in
parallel with the main arithmetic unit.
3. Serial Ports: DSPs normally have internal serial ports for high-speed communication
with other DSPs and data converters. These serial ports are directly connected to the
internal buses to improve performance, to reduce external address decoding problems,
and to reduce cost.
Memory:
Memory holds information, data, and instructions for DSPs and is an essential part of any
DSP system. Although DSPs are intelligent machines, they still need to be told what to do.
Memory devices hold a series of instructions that tell the DSP which operations to perform on
the data (i.e., information). In many cases, the DSP reads some data, operates on it, and writes it
back. Almost all DSP systems have some type of memory device, whether it is on-chip memory
or off-chip memory; however, on-chip memory operates faster.
Ports:
Communication ports are necessary for a DSP system. Raw information is received and
processed; then that information is transmitted to the outside world through these ports. For
example, a DSP system could output information to a printer through a port. The most common
ports are serial and parallel ports. A serial port accepts a serial (single) stream of data and
converts it to the processor format. When the processor wishes to output serial data, the port
accepts processor data and converts it to a serial stream (e.g., modem connections on PCs). A
parallel port does the same job, except the output and input are in parallel (simultaneous)format.
The most common example of a parallel port is a printer port on a PC.
111
Programmability:
A single piece of digital DSP hardware can perform many functions. For example, a
multimedia PC can play music and also function as a word processor if it is loaded with suitable
programs. This ability to use the same hardware for many functions provides important
flexibility. You can implement any new function you think of, as long as you can program it.
1) Upgradability
Once you have designed and implemented your system, you may want to upgrade
or add new functions. Perhaps you would like to adapt your system to a new
environment. With a digital system, this means modifying your code. With an
analog system, this could involve obtaining and soldering in new components, or
even a complete redesign.
2) Flexibility
A single DSP board can be made to perform many functions by simply loading
new programs into it. In our demonstrations, we are using the same DSK board as
a tone generator and as a low-pass filter by simply loading it with different
software. This flexibility reduces design time and complexity. With analog
circuits, a new circuit has to be designed for each new function.
Stability:
The stability of analog circuits depends upon several factors. Analog circuits are affected
by temperature and aging, among other things. Also, two analog systems using the same
design and components may differ in performance.
i) Temperature
Analog components such as resistors, capacitors, diodes, and operational
amplifiers are affected by temperature, humidity, and aging. A temperature-
sensitive analog circuit may perform quite differently in the UK than in Egypt,
where the temperatures are different. This could prove disastrous for a company
112
that sells its products worldwide. Digital circuits do not gradually change their
characteristics over time, temperature, or humidity. They either work or they
don’t work. In other words, digital circuits are repeatable as long as they are
designed with enough tolerance to operate properly over the range of expected
conditions.
ii) Ageing
The effects of component aging can be detrimental to analog circuits as
characteristics and performance change. These effects can sometimes be
anticipated, or their effect may not be critical. Analog designers must be aware of
these effects.
iii) Tolerances
Components such as resistors and capacitors have tolerances. If a
component tolerance is only accurate to within 10%, two apparently identical
analog circuits could perform differently enough to cause operational problems.
This can make design, manufacturing, and support expensive.
Digital Repeatability:
A properly designed digital circuit will produce the same result every time, in
addition to being identical from unit to unit. If the same multiplication is performed on
500 computers, all 500 computers should produce the same result. Component tolerances,
aging, and temperature drifts also do not affect digital circuits nearly as much.
A properly designed digital circuit will produce the same results in the UK as in
Egypt, even when the temperatures are different. On the other hand, 500 analog circuits
could produce a range of results.
In digital circuitry, logical 1s and 0s are defined when an analog voltage is above
or below an analog voltage threshold. For a digital circuit to be repeatable, the analog
voltage which represents the logical 1s and 0sneeds to be sufficiently greater or less than
the threshold so as not to be affected by circuit variations or noise. The only concern is
that timing restrictions and maximum device ratings should not be exceeded. If proper
digital inputs are not maintained, the 1s and 0s can be corrupted, making a normally
repeatable digital circuit suddenly fail. On the other hand, analog circuit characteristics
will tend to gradually drift.
113
DSP Development
i) The Program
The DSP chip is a piece of hardware that cannot function without the intelligence of a
program. A program is a series of instructions that perform certain functions.
ii) Assemblers
Assemblers generate machine-level code from text instructions. Assemblers take our text
instructions and convert them into machine language. This relieves us of the burden of having to
remember binary instructions for DSP.
iii)High-Level Language
High-level languages are like assembly languages, but much friendlier. Assembly
languages have very basic instructions, such as multiply, add, and compare. High-level
languages have higher-level instructions, such as print, and repeat until equal to zero. Therefore,
it is easier to write programs in high-level languages. While it is easier to write in high-level
languages, assembly language can produce programs that are able to execute faster. For this
reason, both have their uses in DSPs. Sometimes it is necessary to write time-critical sections of
a program in assembly. A complete program may have sections of code in assembly and sections
in a high-level language. It is easy to combine both types of code into a single executable
program. Assembly and high-level programming languages make it possible to program DSPs to
perform a variety of functions.
114
iv)Simulators
DSP simulator is a software implementation of a DSP chip. A simulator typically runs on
a computer (PC or workstation), simulating almost all of the functionality of the DSP. They are
used to analyze the feasibility of designs before the designs are committed to hardware. They are
also very useful in determining whether or not a particular design will work.
v)Emulators
An emulator allows us to directly control and debug the results of instructions executing
on the DSP. Modern emulators do not replace the DSP chip on the board but exert their control
through a serial emulation scan path. Using these devices, it is possible to see all of the internal
changes in the device at each step. Developers can execute the instructions one step at a time,
check voltage levels for correct operation, and check each result in their own time. Emulators are
invaluable tools in development environments.
vi)Debugger
A debugger interface is used to display program execution information in a useable
format for the programmer. The data displayed in the debugger windows is essentially a
formatted data print of the contents of the DSP memory. This memory is simply loaded into the
PC using either an emulator or a communications link with the PC using appropriate software.
Debuggers consist of a user interface on the host PC computer, which can control and
modify the contents and execution of the chip. The user interface displays the contents of RAM,
registers, and the disassembly of the currently loaded program. The major advantage of
debuggers over simulators is that they operate in real-time, allowing the designer to assess the
performance of the system in a real-time environment.
vii)Development Cycle
After the feasibility of the design is established through simulation, program design can
begin. First, the software is designed. This stage determines the complexity and the modules of
the code. The modules of software are written and tested, and then the full system is put together
and tested. If everything works as required, the result is version 1.0 of the product on the market.
If it does not work as required, the process is repeated until it does. When new requirements and
improvements emerge as a result of user feedback, a new version is produced via the same
process.
115
About PL-DSPTMS320C6745 DSP Trainer
116
Uses TMS-320C6745 DSP processor from Texas Instruments
Exclusively designed for education in a user friendly format with onboard Noise
generator block, RTC block, LCD display, Speech processing block, etc.
Supports Fixed and floating point operation.
Embedded JTAG supported via USB.
Onboard Peripherals
117
o Manually generate a noise and can be added with
information signal
o Now this noisy signal can be removed/suppressed by
executing a filter program via a CODEC
118
TECHNICAL SPECIFICATIONS
The PL-DSP features the TMS320C6745 PL-DSP, a 375 MHz device delivering up to
3648 million instructions per second (MIPs) and 2736 MFLOPS. This PL-DSP generation is
designed for applications that require high precision accuracy. The C6745 is based on the
TMS320C6000 DSP platform designed to needs of high-performing high-precision applications
such as pro-audio, medical and diagnostic. Other hardware features of the TMS320C6745 DSK
board include:
Software - Designers can readily target the TMS32C6745 PL-DSP through TI´s robust and
comprehensive Code Composer Studio v5™ PL-DSP development platform. The tools, which
run on Windows 98, Windows 2000, Windows XPand Windows 7, allow developers to
seamlessly manage projects of any complexity. Code Composer Studio features for the
TMS320C6745 PL-DSP includes:
A complete Integrated Development Environment (IDE), an efficient optimizing C/C++
compiler assembler, linker, debugger, an a advance deditor with Code Maestro™
technology for faster code creation, data visualization, a profiler and a flexible project
manager
DSP/BIOS™ real-time kernel
Target error recovery software
PL-DSP diagnostic tool
"Plug-in" ability for third-party software for additional functionality
119
INTRODUCTION TO PL-DSP
The 6745 PL-DSP is a low-cost standalone development platform that enables users to
evaluate and develop applications for the TI C67XX DSP family. The DSP also serves as a
hardware reference design for the TMS320C6745 DSP. Schematics, logic equations and
application notes are available to ease hardware development and reduce time to market.
An on-board AIC23 codec allows the DSP to transmit and receive analog signals.SPI is
used for the codec control interface and McASP0 is used for data. Analog audio I/O is done
through two 3.5mm audio jacks that correspond to microphone input, and headphone output and
also line input, line output. The codec can select the microphone or the line input as the active
input. The analog output is driven to both the line out (fixed gain) and headphone (adjustable
gain)connectors.
The PL-DSP includes 8 LEDs, 8 DIP switches, 4*4 LED matrix, LCD and Seven
segment as a simple way to provide the user with interactive feedback. It also includes phone
keypad to study DTMF signals.
The PL-DSP includes Real time clock displayed on LCD to learn RTC and I2Cprotocol.
Code Composer communicates with the DSP through an embedded JTAG emulator with a USB
host interface.
HARDWARE SETTING
JTAG cable must be connected to PC and kit before power ON the PL-DSP board. The
required driver for the emulator is automatically installed by computer.
120
INTRODUCTION TO CODE COMPOSER STUDIO
Code Composer is the DSP industry's first fully integrated development environment
(IDE) with DSP-specific functionality. With a familiar environment liked MS-based C++TM,
Code Composer lets you edit, build, debug, profile and manage projects from a single unified
environment. Other unique features include graphical signal analysis, injection/extraction of data
signals via file I/O, multi-processor debugging, automated testing and customization via a C-
interpretive scripting language and much more.
1. IDE
2. Debug IDE
3. Advanced watch windows
4. Integrated editor
5. File I/O, Probe Points, and graphical algorithm scope probes
6. Advanced graphical signal analysis
7. Interactive profiling
8. Automated testing and customization via scripting
9. Visual project management system
10. Compile in the background while editing and debugging
11. Multi-processor debugging
12. Help on the target DSP
121
Click OK to open workspace window.
122
To create a new project, go to Project→New CCS Project. Give name to project with
location to save project or use default location. Project type must be Executable.
Following window should appear. Device family is C6000.The Variant is C674x
Floating-point DSP and next to this you have to selectEVMC6747. In device
connection, select Texas Instruments XDS100v2USB Emulator. In project templates
and example section, you have to select an Empty project. As per shown in below
window.
After finishing project creation. Empty Project will appear in left window of software, as
shown below
123
To create a source file. Go to File → New → source file.
124
The new source file popup window should appear containing source folder, In Source file
section save the file name with extension .c, Select template as a Default C++ source
template as shown below:
The next window will appear where you can write your code and save it. Or you can add
existing source file as shown below.
125
1. Now write your c program, as follows
126
3. Then click on Test connection in above window, so testing window will appear as
follows
If above window will appear with this message then your connection is correct, then you
can close this window and proceed further.
If following window appears, then connection may be incorrect. So power off PL-DSP
board and power it again, and do all processes again till scan- test will be succeeded.
127
4. After that build your program from Project → Build ALL. Following console window
will appear. It shows if any error present or not.
5. To debug the program, double click on Debug icon shown in above window or press
F11. Debug process starts as follows.
128
6. After few seconds, loading of program is completed that is shown in following
Window
7. Run program by clicking on RUN icon in above window, program will run
completely and give output in console window as follows.
129
8. After completion of the program, close debug session by clicking on disconnecticon
shown in above window. It will come to previous edit window
9. After completion of one program close project by right clicking on project name and
delete as shown below.
11. Only click on OK. It will delete project from project explorer only. Don’t tick on
Delete project content on disk. It will delete all program from computer.
130
HOW TO IMPORT EXISTING PROJECT
12. Open CCStudio v5
13. Then Go to Project→ Import Existing CCS Eclipse Project as per shown
below.
131
14. Selection of Existing CCS Eclipse project window should appear. As shown
below.
15. Browse to select directory. Selected project will appear in discovered projects section.
Asshown below
132
16. Select and click on ok, in above window, so following window will appear
17. Click on ‘Finish’ button. Selected project will automatically import into project
explorer window present at the left side of software window. As shown below
133
For debugging and downloading follow the procedure from 11 to 14.
Viewing the Graphs/ Plots using CCS v5.0
10. Now open Graph in Tools menu by selecting the required type of graph
134
11. Modify the graph properties according to the requirement and enter the start address of
the variable to be plotted and click OK
135
Program – 1
136
Program
#include<stdio.h>
#include<math.h>
float y[200],x[200];
int n,m;
voidmain()
{
y[1]=1;
y[2]=1;
for (m=1;m<=150;m++)
{
if (m==3)
x[m]=1;
else
x[m]=0;
}
for (n=3;n<=150;n++)
{
y[n]=1.9447*y[n-1]-y[n-2];
}
}
137
Waveforms/Graphs:
Viva-voce:
1. Solving difference equations
2. Graph Plotting using CCS
3. Syntaxes of various Keywords used in the program
138
Program –2
DFT / IDFT of given DT signal
Date:
Program
#include<stdio.h>
#include<math.h>
int N,x[15],i,k,n;
float w,yR,yI,XR[15],XI[15];
voidmain()
{
printf("Enter the length of the sequence:");
scanf("%d",&N);
w=(2*3.1415)/N;
printf("Enter the sequence:");
for(i=0;i<N;i++)
{
scanf("%d",&x[i]);
}
for (k=0;k<N;k++)
{
yR=0;
yI=0;
for(n=0;n<N;n++)
{
yR=yR+x[n]*(cos(w*n*k));
yI=yI+x[n]*(-sin(w*n*k));
}
XR[k]=yR;
XI[k]=yI;
}
printf("The result of DFT of the given sequence is X(k)=\n");
for (k=0;k<N;k++)
printf("%f+j%f\n",XR[k],XI[k]);
}
139
Input Sequence x(n)=[1 2 3 4 4 3 2 1]
#include<stdio.h>
#include<math.h>
int N,i,k,n;
float w,yR,yI,XR[15],XI[15],yR1,yR2,yI1,yI2,xR[15],xI[15];
voidmain()
{
printf("Enter the length of the sequence:");
scanf("%d",&N);
w=(2*3.1415)/N;
printf("Enter the real part of complex coefficient sequence:");
for(i=0;i<N;i++)
{
scanf("%f",&XR[i]);
}
printf("Enter the imaginary part of complex coefficient
sequence:");
for(i=0;i<N;i++)
{
scanf("%f",&XI[i]);
}
for (n=0;n<N;n++)
{
yR=0;
140
yI=0;
for(k=0;k<N;k++)
{
yR1=XR[k]*(cos(w*n*k));
yR2=-XI[k]*(sin(w*n*k));
yR=yR+yR1+yR2;
yI1=XI[k]*(cos(w*n*k));
yI2=XR[k]*(sin(w*n*k));
yI=yI+yI1+yI2;
}
xR[n]=yR/N;
xI[n]=yI/N;
}
printf("The result of IDFT of the given complex coefficient
sequence is x(n)=\n");
for (n=0;n<N;n++)
printf("%f+j%f\n",xR[n],xI[n]);
}
141
Viva-Voce:
1. Mathematical expressions to find DFT / IDFT
2. Applications of DFT
3. Syntaxes of various Keywords used in the program
142
Program – 3
Frequency response of a second order system
Date:
Aim: To plot the frequency response of a second order system.
Software Requirements: Personal Computer with Code Composer Studio v 5.0,
Hardware Requirements: TMS320C6745 DSK
Program :
#include <stdio.h>
#include <math.h>
int i,n;
float x[10],y[10];
void main()
{
for(i=-2;i<=9;i++)
{
y[i]=0;
x[i]=0;
}
x[0]=1;
for(n=0;n<=9;n++)
{
y[n]=0.375*y[n-1]+0.667*y[n-2]+x[n]+0.25*x[n-1];
}
printf("The impulse response of the given second order system is:");
for(n=0;n<=9;n++)
printf("%f\n",y[n]);
}
143
144
Waveforms/Graphs:
145
Program – 4
Fast Fourier Transform
Date:
Program
#include<stdio.h>
#include<math.h>
voidmain()
{
int n,i,j,k,n1,n2;
double m,x[30],y[30],c,s,e,a,t1,t2;
m=(log(n)/log(2));
printf("The total no. of stages %lf\n",m);
j = 0; /* bit-reverse */
n2 = n/2;
for (i=1; i < n - 1; i++)
{
n1 = n2;
while ( j >= n1 )
{
j = j - n1;
n1 = n1/2;
}
j = j + n1;
if (i < j)
{
t1 = x[i];
x[i] = x[j];
x[j] = t1;
t1 = y[i];
146
y[i] = y[j];
y[j] = t1;
}
}
n1 = 0; /* FFT */
n2 = 1;
for (i=0; i < m; i++)
{
n1 = n2;
n2 = n2 + n2;
e = -6.283185307179586/n2;
a = 0.0;
for (j=0; j < n1; j++)
{
c = cos(a);
s = sin(a);
a = a + e;
for (k=j; k < n; k=k+n2)
{
t1 = c*x[k+n1] - s*y[k+n1];
t2 = s*x[k+n1] + c*y[k+n1];
x[k+n1] = x[k] - t1;
y[k+n1] = y[k] - t2;
x[k] = x[k] + t1;
y[k] = y[k] + t2;
}
}
}
147
Result: Hence FFT of a sequence is found.
148
Program – 5
Power Spectrum of a given Signal
Date:
Program
#include<stdio.h>
#include<math.h>
int n,i,j,k,n1,n2;
float m,x[10],y[10],psd[10],c,s,e,a,t1,t2;
voidmain()
{
for(i=0;i<n;i++)
{
psd[i]=0;
x[i]=0;
}
m=(log(n)/log(2));
printf("The total no. of stages %lf\n",m);
j = 0; /* bit-reverse */
n2 = n/2;
for (i=1; i < n - 1; i++)
{
n1 = n2;
while ( j >= n1 )
{
j = j - n1;
n1 = n1/2;
}
j = j + n1;
if (i < j)
149
{
t1 = x[i];
x[i] = x[j];
x[j] = t1;
t1 = y[i];
y[i] = y[j];
y[j] = t1;
}
}
n1 = 0; /* FFT */
n2 = 1;
for (i=0; i < m; i++)
{
n1 = n2;
n2 = n2 + n2;
e = -6.283185307179586/n2;
a = 0.0;
for (j=0; j < n1; j++)
{
c = cos(a);
s = sin(a);
a = a + e;
for (k=j; k < n; k=k+n2)
{
t1 = c*x[k+n1] - s*y[k+n1];
t2 = s*x[k+n1] + c*y[k+n1];
x[k+n1] = x[k] - t1;
y[k+n1] = y[k] - t2;
x[k] = x[k] + t1;
y[k] = y[k] + t2;
}
}
}
for(i=0;i<n;i++)
psd[i]=(x[i]*x[i]+y[i]*y[i])/n;
printf("The PSD of the given sequence is\n");
for(i=0;i<n;i++)
printf("%f\n",psd[i]);
}
150
151
Waveforms/Graphs:
Viva-Voce:
152
Program – 6
Implementation of LP/HP FIR filter on a sequence
Date:
Aim: To implement LP FIR filter on a sequence.
Software Requirements: Personal Computer with Code Composer Studio v 5.0, Matlab v8.5
Hardware Requirements: TMS320C6745 DSK
Program:
Filter Type: Lowpass
Window Type: Hamming
Order: 10
Fs=1000Hz
Fc=1Hz
Matlab support:
clc;
clear all;
close all;
153
0.16645399578198858
0.18248696958198654
0.16645399578198858
0.12447981176888186
0.07259853985055098
0.030627611554787409
0.014596556252797903];
h=h';
%Finding the output of FIR filter
y=conv(x,h);
figure,plot(y);
C program
#include<stdio.h>
#include <math.h>
// random sequence values
float n[51]={ 0.576053456321354, 0.810628105007939 ,
0.403843368384066, 0.988439267199745 , 0.0899988149868883 ,
0.320941032647761 , 0.511408938819178 , 0.0606063665682423
, 0.725687923545844 , 0.556555748561992 , 0.529359902481257
, 0.829982432033195 , 0.858759034071804 ,
0.789028923313949, 0.317833053726229 , 0.452207453762982 ,
0.752227970049942 , 0.109861705750686 , 0.109742368593904 ,
0.269883663704401 , 0.524637345396311 , 0.972651076977497 ,
0.710408685278170 , 0.311859945147533 , 0.291457127647727
, 0.850357337374621 , 0.911647424007853 , 0.639276147276064
, 0.255370297944443 , 0.0886658400322831 ,
0.838255587537226 , 0.584718619263320 , 0.948108735396022 ,
0.0610289291925092 , 0.584641303355111 , 0.285108085658642
, 0.827732173448263 , 0.190986440697398 , 0.442529962202884
, 0.393411506367576 , 0.826573979042765 ,
0.676871093438419 , 0.207603034379981 , 0.318104726150263
, 0.133810985356126 , 0.671462889478031 , 0.570991075462406
, 0.169767066026489, 0.147655777151737 , 0.476079718267456
, 0.908102416506950};
// FIR HAMMING WINDOW LOWPASS filter coefficients
float
h[51]={0.014596556252797903,0.030627611554787409,0.0725985398505
5098,0.12447981176888186 ,0.16645399578198858,
,0.18248696958198654 ,0.16645399578198858 ,0.12447981176888186
,0.07259853985055098,0.030627611554787409,0.014596556252797903};
float t[51],x[51],xn[51],y[61];
int i,j,m,k,p;
int main()
{
// defining time variable
t[0]=0;
for(i==0;(i+1)<51;i++)
{
154
t[i+1]=t[i]+0.01;
printf("%f\n",t[i]);
}
// defining half cycle of sinewave
printf("The input signal is");
for(j==0;j<51;j++)
{
x[j]=sin(2*3.1415*t[j]);
printf("%f\n",x[j]);
}
// generating signal plus noise
printf("The input plus noise is:");
for(p==0;p<51;p++)
{
xn[p]=x[p]+n[p];
printf("%f\n",xn[p]);
}
//initializing output variable
for (i=0;i<61;i++)
y[i]=0;
}
}
}
printf("\nThe resultant sequence y is :");
for (i=0;i<51;i++)
{
printf("\n%f",y[i]);
}
155
INPUT SIGNAL PLOT SIGNAL PLUS RANDOM NOISE PLOT
156
Waveforms/Graphs:
Fig 6.1:a) Input Signal b) Signal + noise c) Smoothened or Lowpass filtered output
157
Result: Thus Lowpass FIR filter is implemented on a sinewave corrupted with random noise and
the result observed is smoothened.
158
Program – 7
Implementation of Decimation Process
Date:
Aim: To implement Decimation process on a sequence.
Software Requirements: Personal Computer with Code Composer Studio v 5.0, Matlabv8.5
Hardware Requirements: TMS320C6745 DSK
Program:
Down sampling:
#include<stdio.h>
#include<math.h>
int x[100],y[100];
float z,d;
float a,b;
int i,j;
void main()
{
printf(“\n Enter the length of input sequence”);
scanf(“%f”,&a);
printf(“\n Enter sampling value:”);
scanf(“%f”,&b);
printf(“Enter values for input x(n):\n”);
for(i=0;i<=a;i++)
scanf(“%d”,&x[i]);
j=0;
for(i=1;i<=a;i++)
{
y[i]=x[j];
j=j+b;
}
d=a/b;
z=ceilf(d);
for(i=1;i<=z;i++)
printf(“\n The Down sampled version is y[%d]=%d”,i,y[i]);
}
159
PROCEDURE FOR SELECTING ANTI-ALIASING FIR FILTER COEFFICIENTS
160
MATLAB SUPPORT:
DECIMATION
clc;
clear all;
close all;
%decimation
Fs=50;
t=0:1/Fs:2*pi;
D=3
x1 = sin(t);
h1=[
0
-0.000043020495399987069
-0.000076013438760316076
0
0.00018487124619081242
0.00026753581008901812
0
-0.00050970783426300664
-0.00067879593558529917
0
0.0011407690199314677
0.0014464278234642166
0
-0.0022436979078414884
-0.0027521260481395641
0
161
0.0040375134195622716
0.0048376681337442612
0
-0.0068240527838610019
-0.0080464176413262388
0
0.011070838087278455
0.012941029950154342
0
-0.017654667293030096
-0.020661234151834809
0
0.028687013916059163
0.034237591369701031
0
-0.051349505150856727
-0.065855675339352465
0
0.1362791750483513
0.27488503838177852
0.33333333333333331
0.27488503838177852
0.1362791750483513
0
-0.065855675339352465
-0.051349505150856727
0
0.034237591369701031
0.028687013916059163
0
-0.020661234151834809
-0.017654667293030096
0
0.012941029950154342
0.011070838087278455
0
-0.0080464176413262388
-0.0068240527838610019
0
0.0048376681337442612
0.0040375134195622716
0
-0.0027521260481395641
-0.0022436979078414884
0
0.0014464278234642166
0.0011407690199314677
0
-0.00067879593558529917
162
-0.00050970783426300664
0
0.00026753581008901812
0.00018487124619081242
0
-0.000076013438760316076
-0.000043020495399987069
];
h1=h1';
x_antialiasing=conv(x1,h1);
decim_output=downsample(x_antialiasing,D);
n=length(decim_output);
figure,
subplot(2,1,1);
stem(x1);
subplot(2,1,2);
stem(decim_output(13:118));
grid
Convolution ‘c’ program - Support
#include<stdio.h>
#include<math.h>
float x[100],y[100],h[100];
int l,k,i,j,n,m;
voidmain()
{
for(i=0;i<l+m-1;i++)
{
x[i]=0;
h[i]=0;
}
printf("\nEnter the sequence x:");
for (i=0;i<l;i++)
scanf("%f",&x[i]);
printf("\nEnter the sequence h:");
for (j=0;j<m;j++)
scanf("%f",&h[j]);
163
for (i=0;i<100;i++)
y[i]=0;
}
}
}
printf("\nThe resultant sequence y is :");
for (i=0;i<l+m-1;i++)
printf("\n%f",y[i]);
}
DECIMATION ‘C’ PROGRAM
#include<stdio.h>
#include<math.h>
double x[315],y[315],t[315],h[500],xd[105];
float z,d;
float a,b,D;
int i,j,Fs=50,n,k;
int main()
{
/*defining a input wave*/
for (i=0;i<315;i++)
{
t[i]=i/Fs;
x[i]=sin(Fs*t[i]);
}
printf("The input wave is:\n");
for(i=0;i<315;i++)
{
printf("\n%lf",x[i]);
}
for(i=0;i<500;i++)
{
h[i]=0;
}
/*Passing input wave through anti-aliasing filter*/
h[0]= 0.000000000 ;
h[1]= -0.000043020 ;
h[2]= -0.000076013 ;
h[3]= 0.000000000 ;
164
h[4]= 0.000184871 ;
h[5]= 0.000267536 ;
h[6]= 0.000000000 ;
h[7]= -0.000509708 ;
h[8]= -0.000678796 ;
h[9]= 0.000000000 ;
h[10]= 0.001140769 ;
h[11]= 0.001446428 ;
h[12]= 0.000000000 ;
h[13]= -0.002243698 ;
h[14]= -0.002752126 ;
h[15]= 0.000000000 ;
h[16]= 0.004037513 ;
h[17]= 0.004837668 ;
h[18]= 0.000000000 ;
h[19]= -0.006824053 ;
h[20]= -0.008046418 ;
h[21]= 0.000000000 ;
h[22]= 0.011070838 ;
h[23]= 0.012941030 ;
h[24]= 0.000000000 ;
h[25]= -0.017654667 ;
h[26]= -0.020661234 ;
h[27]= 0.000000000 ;
h[28]= 0.028687014 ;
h[29]= 0.034237591 ;
h[30]= 0.000000000 ;
h[31]= -0.051349505 ;
h[32]= -0.065855675 ;
h[33]= 0.000000000 ;
h[34]= 0.136279175 ;
h[35]= 0.274885038 ;
h[36]= 0.333333333 ;
h[37]= 0.274885038 ;
h[38]= 0.136279175 ;
h[39]= 0.000000000 ;
h[40]= -0.065855675 ;
h[41]= -0.051349505 ;
h[42]= 0.000000000 ;
h[43]= 0.034237591 ;
h[44]= 0.028687014 ;
h[45]= 0.000000000 ;
h[46]= -0.020661234 ;
h[47]= -0.017654667 ;
h[48]= 0.000000000 ;
h[49]= 0.012941030 ;
h[50]= 0.011070838 ;
h[51]= 0.000000000 ;
h[52]= -0.008046418 ;
165
h[53]= -0.006824053 ;
h[54]= 0.000000000 ;
h[55]= 0.004837668 ;
h[56]= 0.004037513 ;
h[57]= 0.000000000 ;
h[58]= -0.002752126 ;
h[59]= -0.002243698 ;
h[60]= 0.000000000 ;
h[61]= 0.001446428 ;
h[62]= 0.001140769 ;
h[63]= 0.000000000 ;
h[64]= -0.000678796 ;
h[65]= -0.000509708 ;
h[66]= 0.000000000 ;
h[67]= 0.000267536 ;
h[68]= 0.000184871 ;
h[69]= 0.000000000 ;
h[70]= -0.000076013 ;
h[71]= -0.000043020 ;
for (i=0;i<388;i++)
{
y[i]=0;
}
for (n=0; n < 388; n++)
{
for(k=0;k<315;k++)
{
if((n-k)>=0)
{
y[n]+=x[k]*h[n-k];
}
}
}
printf("\nThe resultant filtered sequence y is :");
for (i=0;i<388;i++)
{
printf("\n%lf",y[i]);
}
a=315;/* length of the inputwave*/
b=3;/*decimation factor*/
/*performing downsampling*/
j=0;
for(i=0;i<105;i++)
{
xd[i]=y[j];
j=j+b;
}
d=a/b;
166
z=ceilf(d);
printf("\n The Down sampled version is:\n");
for(i=0;i<z;i++)
{
printf("\n%lf",xd[i]);
}
}
INPUT SEQUENCE PLOT
167
Waveforms/Graphs:
168
Program – 8
Implementation of Interpolation Process
Date:
Aim: To implement Interpolation process on a sequence.
Software Requirements: Personal Computer with Code Composer Studio v 5.0, Matlab v 8.5
Hardware Requirements: TMS320C6745 DSK
Program:
Upsampling:
#include<stdio.h>
#include<math.h>
void main()
{
int x[100],xu[100],N,i,I,n,R;
printf(“\n Enter the length of input sequence”);
scanf(“%f”,&N);
printf(“\n Enter Interpolation factor:”);
scanf(“%f”,&I);
printf(“Enter values for input x(n):\n”);
for(i=0;i<=N;i++)
scanf(“%d”,&x[i]);
for(n=0;n<(N*I)-(I-1);n++)
{
R=n%I;
If(R==0)
xu[n]=x[n/I];
else
xu[n]=0;
}
printf(“\n Interpolated sequence is:”);
for(i=0;i<(N*I)-(I-1);i++)
printf(“%d”,xu[i]);
}
169
PROCEDURE FOR SELECTING ANTI-IMAGING FIR FILTER COEFFICIENTS
MATLAB SUPPORT
INTERPOLATION
clc ; clear all ; close all;
Fs=2;
t=0:1/Fs:6*pi;
%interpolation
I=2
x = sin(t);
subplot(2,1,1);
stem(x);
xu=upsample(x,2);
h=[0.5,1,0.5,0];
interp_output=conv(xu,2*h);
m=length(interp_output);
subplot(2,1,2);
stem(interp_output);
grid
170
Convolution ‘c’ program - Support
#include<stdio.h>
#include<math.h>
float x[100],y[100],h[100];
int l,k,i,j,n,m;
voidmain()
{
for(i=0;i<l+m-1;i++)
{
x[i]=0;
h[i]=0;
}
printf("\nEnter the sequence x:");
for (i=0;i<l;i++)
scanf("%f",&x[i]);
printf("\nEnter the sequence h:");
for (j=0;j<m;j++)
scanf("%f",&h[j]);
for (i=0;i<100;i++)
y[i]=0;
}
}
}
printf("\nThe resultant sequence y is :");
for (i=0;i<l+m-1;i++)
printf("\n%f",y[i]);
171
INTERPOLATION ‘C’ PROGRAM
#include<stdio.h>
#include<math.h>
int main()
{
float x[38],xu[76],h[76],y[78],t[38];
int i,I,n,R,k;
float m=0,Fs=2;
/*input sinewave*/
for (i=0;i<38;i++)
{
t[i]=m/Fs;
x[i]=sin(t[i]);
m=m+1;
}
}
}
}
printf("\nThe resultant sequence y is :");
for (i=0;i<78;i++)
{
printf("\n%f",y[i]);
}
}
INPUT SEQUENCE PLOT
173
RESULT OF ANTI-IMAGING FILTER : INTERPOLATED SEQUENCE PLOT
174
Waveforms/Graphs:
175
Program – 9
Implementation of I/D Sampling rate Converter
Date:
Aim: To implement sampling rate conversion by a rational factor I/D on a sequence.
Software Requirements: Personal Computer with Code Composer Studio v 5.0, Matlab v 8.2
Hardware Requirements: TMS320C6745 DSK
Program:
Procedure for selecting Lowpass filter coefficients for I/D sampling rate conversion
MATLAB SUPPORT
MULTIRATE SAMPLING BY RATIONAL FACTOR - I/D
clc
clear all
close all
Fs=10;
t=0:1/Fs:2*pi;
%interpolation
I=2;D=3;
x = sin(t);
subplot(2,1,1);
stem(x);
xu=upsample(x,I);
h=[
0
-0.000086040990799974139
-0.00015202687752063215
176
0
0.00036974249238162484
0.00053507162017803623
0
-0.0010194156685260133
-0.0013575918711705983
0
0.0022815380398629355
0.0028928556469284333
0
-0.0044873958156829768
-0.0055042520962791282
0
0.0080750268391245432
0.0096753362674885223
0
-0.013648105567722004
-0.016092835282652478
0
0.02214167617455691
0.025882059900308684
0
-0.035309334586060191
-0.041322468303669618
0
0.057374027832118327
0.068475182739402063
0
-0.10269901030171345
-0.13171135067870493
0
0.2725583500967026
0.54977007676355705
0.66666666666666663
0.54977007676355705
0.2725583500967026
0
-0.13171135067870493
-0.10269901030171345
0
0.068475182739402063
0.057374027832118327
0
-0.041322468303669618
-0.035309334586060191
0
0.025882059900308684
0.02214167617455691
0
177
-0.016092835282652478
-0.013648105567722004
0
0.0096753362674885223
0.0080750268391245432
0
-0.0055042520962791282
-0.0044873958156829768
0
0.0028928556469284333
0.0022815380398629355
0
-0.0013575918711705983
-0.0010194156685260133
0
0.00053507162017803623
0.00036974249238162484
0
-0.00015202687752063215
-0.000086040990799974139
];
h=h';
interp_output=conv(xu,2*h);
subplot(2,1,2);
%decimation
multirate_output=downsample(interp_output,D);
subplot(2,1,2);
stem(multirate_output(14:54));
grid
Convolution ‘c’ program - Support
#include<stdio.h>
#include<math.h>
float x[100],y[100],h[100];
int l,k,i,j,n,m;
voidmain()
{
for(i=0;i<l+m-1;i++)
{
x[i]=0;
h[i]=0;
178
}
printf("\nEnter the sequence x:");
for (i=0;i<l;i++)
scanf("%f",&x[i]);
printf("\nEnter the sequence h:");
for (j=0;j<m;j++)
scanf("%f",&h[j]);
for (i=0;i<100;i++)
y[i]=0;
}
}
}
printf("\nThe resultant sequence y is :");
for (i=0;i<l+m-1;i++)
printf("\n%f",y[i]);
}
MULTIRATE SAMPLING BY RATIONAL FACTOR - I/D - C-PROGRAM
#include<stdio.h>
#include<math.h>
void main ()
{
float x[38], xu[76], h[72], y[147], xd[47], t[38];
int i, j, I, n, R, k, l, p, q;
float m = 0, Fs = 2, a,b, d, z;
/*input sinewave */
for (i = 0; i < 38; i++)
{
t[i] = m / Fs;
x[i] = sin (t[i]);
m = m + 1;
}
q = sizeof (x);
h[0] = 0;
h[1] = -0.000086040990799974139;
179
h[2] = -0.00015202687752063215;
h[3] = 0;
h[4] = 0.00036974249238162489;
h[5] = 0.00053507162017803623;
h[6] = 0;
h[7] = -0.0010194156685260133;
h[8] = -0.0013575918711705983,
h[9] = 0;
h[10] = 0.0022815380398629355;
h[11] = 0.0028928556469284333;
h[12] = 0;
h[13] = -0.0044873958156829742;
h[14] = -0.0055042520962791282;
h[15] = 0;
h[16] = 0.0080750268391245432;
h[17] = 0.009675336267488524;
h[18] = 0;
h[19] = -0.013648105567722004;
h[20] = -0.016092835282652478;
h[21] = 0;
h[22] = 0.02214167617455691;
h[23] = 0.025882059900308684;
h[24] = 0;
h[25] = -0.035309334586060191;
h[26] = -0.041322468303669618;
h[27] = 0;
h[28] = 0.057374027832118327;
h[29] = 0.068475182739402063;
h[30] = 0;
h[31] = -0.10269901030171345;
h[32] = -0.13171135067870493;
h[33] = 0;
h[34] = 0.2725583500967026;
h[35] = 0.54977007676355705;
h[36] = 0.66666666666666663;
h[37] = 0.54977007676355705;
h[38] = 0.2725583500967026;
h[39] = 0;
h[40] = -0.13171135067870493;
h[41] = -0.10269901030171345;
h[42] = 0;
h[43] = 0.068475182739402063;
h[44] = 0.057374027832118327;
h[45] = 0;
h[46] = -0.041322468303669618;
h[47] = -0.035309334586060191;
h[48] = 0;
h[49] = 0.025882059900308684;
h[50] = 0.02214167617455691;
180
h[51] = 0;
h[52] = -0.016092835282652478;
h[53] = -0.013648105567722004;
h[54] = 0;
h[55] = 0.009675336267488524;
h[56] = 0.0080750268391245432;
h[57] = 0;
h[58] = -0.0055042520962791282;
h[59] = -0.0044873958156829742;
h[60] = 0;
h[61] = 0.0028928556469284333;
h[62] = 0.0022815380398629355;
h[63] = 0;
h[64] = -0.0013575918711705983;
h[65] = -0.0010194156685260133;
h[66] = 0;
h[67] = 0.00053507162017803623;
h[68] = 0.00036974249238162489;
h[69] = 0;
h[70] = -0.00015202687752063215;
h[71] = -0.000086040990799974139;
/*Interpolation factor*/
I = 2;
/* Upsampling*/
for (n = 0; n < (q*I)-(I-1); n++)
{
R = n % I;
if (R == 0)
xu[n] = x[n / I];
else
xu[n] = 0;
}
l = sizeof (xu);
p = sizeof (h);
181
{
if ((n - k) >= 0)
a = sizeof (y);
b = 3; /*decimation factor */
/*performing downsampling*/
j = 0;
d = a / b;
z = ceilf (d);
182
Waveforms/Graphs:
Result: Sample rate converter by a rational factor I/D is obtained and is plotted.
183
Program – 10
Implementation of HP IIR filter for a given sequence
Date:
#include "stdio.h"
#include "math.h"
int i,w,wc,c;
float H[100],ap,as,fp,fs,wp,ws,epsilon,lambda,N,a,b;
void main()
{
printf("\n Enter Passband attenuation in dB: ");
scanf("%f",&ap);
wp=2*3.1415*fs;
ws=2*3.1415*fp;
a=pow(10,(0.1*ap));
b=pow(10,(0.1*as));
epsilon=sqrt(a-1);
lambda=sqrt(b-1);
//filter order
N=(log10(lambda/epsilon))/(log10(ws/wp));
N=ceilf(N);
printf("The order is :\n");
printf("%f",N);
184
wc=wp;
for(w=0;w<=100;w++)
{
H[w]=1/sqrt(1+pow((float)wc/w,2*N));
printf("H[%d]=%f\n",w,H[w]);
}
Input:
Enter Passband attenuation in dB: 3
185
Waveforms/Graphs:
186
Program – 11
Impulse response of a second order system
Date:
Aim: To plot the impulse response of a second order system.
Software Requirements: Personal Computer with Code Composer Studio v 5.0
Hardware Requirements: TMS320C6745 DSK
Program :
#include <stdio.h>
#include <math.h>
int i,n;
float x[10],y[10];
void main()
{
for(i=-2;i<=9;i++)
{
y[i]=0;
x[i]=0;
}
x[0]=1;
for(n=0;n<=9;n++)
{
y[n]=0.375*y[n-1]+0.667*y[n-2]+x[n]+0.25*x[n-1];
}
printf("The impulse response of the given second order system
is:");
for(n=0;n<=9;n++)
printf("%f\n",y[n]);
}
187
188
Waveforms/Graphs:
Fig 11.1:a) Input impulse signal b) Impulse response of second order system
Result: Impulse response of a second order system is calculated and is plotted
Viva-Voce:
1. Define unit impulse.
2. What is impulse response?
189
SIGNAL PROCESSING
USING SCILAB
INTRODUCTION TO SCILAB
Scilab is free and open source software for numerical computation providing a
powerful computing environment for engineering and scientific applications
From the software point of view, Scilab is an interpreted language. This generally
allows to get faster development processes, because the user directly accesses a high-level
language, with a rich set of features provided by the library. The Scilab language is meant to
be extended so that user-defined data types can be defined with possibly overloaded
operations. Scilab users can develop their own modules so that they can solve their particular
problems.
Scilab includes hundreds of mathematical functions. It has a high-level programming
language allowing access to advanced data structures, 2-D and 3-D graphical
functions. A large number of functionalities is included in Scilab:
Maths& Simulation
For usual engineering and science applications including mathematical operations and
data analysis.
2-D & 3-D Visualization
Graphics functions to visualize, annotate and export data and many ways to create and
customize various types of plots and charts.
Optimization
Algorithms to solve constrained and unconstrained continuous and discrete
optimization problems.
Statistics
Tools to perform data analysis and modeling
Control System Design & Analysis
Standard algorithms and tools for control system study
Signal Processing
Visualize, analyze and filter signals in time and frequency domains.
Application Development
Increase Scilab native functionalities and manage data exchanges with external tools.
Xcos - Hybrid dynamic systems modeler and simulator
Modeling mechanical systems, hydraulic circuits, control systems, etc.
Whatever our platform is (i.e. Windows, Linux or Mac), Scilab binaries can be
downloaded directly from the Scilab homepage http://www.scilab.org or from the Download
193
area http://www.scilab.org/download. Scilab binaries are provided for both 32 and 64-bit
platforms so that they match the target installation machine.
There are several ways of using Scilab and the basic two methods are:
Using the console in the interactive mode
Using the exec function against a file
The console
The first way is to use Scilab interactively, by typing commands in the console, analyzing
the results and continuing this process until the final result is computed.
The editor
Scilab,from version 5.2 provides a new editor which allows to edit scripts easily.The
editor can be accessed from the menu of the console, under the Applications > Editor menu,
or from the console, as presented below.
--> editor ()
194
This editor allows to manage several files at the same time, as presented in figure below
There are many features but commonly used features are under the Execute menu.
Load into Scilab allows to execute the statements in the current file, as if wedid a
copy and paste. This implies that the statements which do not end withthe semicolon
";" character will produce an output in the console.
Evaluate Selection allows to execute the statements which are currently selected.
Execute File into Scilab allows to execute the file, as if we used the execfunction. The
results which are produced in the console are only those whichare associated with
printing functions, such as disp for example.
We can also select a few lines in the script, by right clicking and get the context menu as
presented below:
195
Using exec
When several commands are to be executed, it may be more convenient to writethese
statements into a file with Scilab editor. To execute the commands located in such a file, the
exec function can be used, followed by the name of the script. This file generally has the
extension.sce or .sci, depending on its content:
Files having the .sci extension contain Scilab functions and executing themloads the
functions into Scilab environment (but does not execute them)
Files having the .sce extension contain both Scilab functions and
executablestatements.
Executing a .scefile has generally an effect such as computing several variables and
displaying the results in the console, creating 2D plots, reading or writing into a file, etc.
196
Program – 1
Fast Fourier Transform
Date:
Program:
clear all;
clc ;
close ;
//Inverse FFT
x_inv = real (fft(X ,1) )
disp(X,'The DFT of the input is X=');
INPUT:
Enter the input sequence:x=[1 2 3 4 4 3 2 1]
OUTPUT:
The input sequence is x= 1. 2. 3. 4. 4. 3. 2. 1.
The DFT of the input is X= 20. - 5.8284271 - 2.4142136i 0 - 0.1715729 - 0.4142136i
0 - 0.1715729 + 0.4142136i 0 - 5.8284271 + 2.4142136i
The inverse DFT is x= 1. 2. 3. 4. 4. 3. 2. 1.
The inverse is 1. 2. 3. 4. 4. 3. 2. 1.
Result: The DFT of a sequence using Fast Fourier Transform is computed
197
Program – 2
Implementation of I/D sampling rate converters
Date:
Program
clc;
clear all;
close;
t=0:0.05:1;
x=sin(10*t);
I=input('Enter the Interpolation factor:');
D=input('Enter the Decimation factor:');
scf(0);
plot2d3(x);
xlabel("$0\le t\le 1$","fontsize",4,"color","red");
ylabel("$x(t)={sin(10t)}$","fontsize",4,"color","red");
title("Input signal","color","red","fontsize",4);
y=intdec(x,I/D);
scf(1);
plot2d3(y);
xlabel("$0\le t\le 1$","fontsize",4,"color","red");
ylabel("$y(t)={x(2t/3)}$","fontsize",4,"color","red");
title("I/D sampled signal","color","red","fontsize",4);
INPUT:
Enter the Interpolation factor:2
Enter the Decimation factor:3
PLOTS:
INPUT SIGNAL
198
I/D SAMPLE RATE CONVERSION OUTPUT
199
Waveforms/Graphs:
200
Program – 3
Impulse response of first order and second order systems
Date:
Aim: To Calculate Unit Impulse Response (Unit Sample) of the givenLTI system.
Requirements: Personal Computer with SCILAB 5.5.2 software
Program:
// Continuous time System
clc;
close;
clear all;
s=%s; // first create a variable
num=36;
den=36+3*s+s^2;
//create a scilab continuous system LTI object
TF=syslin('c',num,den);
//TF = 36/ (36 + 3s + s^2);
ty=typeof(TF);// type of object is rational
t=linspace(0,5,500);
imp_res=csim('imp',t,TF);
plot(t,imp_res);
xgrid();
xtitle('Impulse response','time','response');
201
// Discrete time System
clc;
clear all;
close;
//Given 2nd order system
//y(n)=(3/8)y(n-1)+(2/3)y(n-2)+x(n)+(1/4)x(n-1)
OUTPUT:
h(n)=
1.
0.625
0.9010417
0.7545573
0.8836534
0.8344082
0.9020054
0.8945242
0.9367835
0.9476432
202
Waveforms/Graphs:
Result:Henceimpulse response of second order continuous and discrete time LTI systems are
found and plotted.
203
Program – 4
Implementation of LP/HP IIR filter
Date:
Aim: To design
i)Butterworth Lowpass IIR filter
ii)Chebyshev-I Highpass IIR filter
204
205
Waveforms/Graphs:
Result:HenceLP/HP digital IIR filters are designed and frequency response is plotted.
206
Program – 5
Date:
Program:
figure ;
207
row_f =3;
colum_f =3;
case 0
row_f =4;
colum_f =2;
else
row_f =4;
colum_f =1;
end
208