EC3492-DIGITAL SIGNAL LABORATORY Manual
EC3492-DIGITAL SIGNAL LABORATORY Manual
AIM:
To generate a discrete time signal sequence (Unit step, Unit ramp, Sine, Cosine, Exponential, Unit
impulse) using MATLAB function.
APPARATUS REQUIRED:
PROCEDURE:
Start the Program
Get the dimension of ‘a’
Discrete output is obtained for a>=0 and zeros of all other values.
Output is generated in stem format
Terminate the process.
1
%Program for generation of cosine wave
t=0:0.01: pi;
y=cos(2*pi*t);
subplot(3,1,3);
stem(t,y);
ylabel('amplitude');
xlabel('time period');
title('cosine wave')
2
%Program for generation of unit ramp signal
n1=input('enter the sample length of unit ramp sequence');
t=0:n1;
subplot(2,2,3);
stem(t,t);
ylabel('amplitude');
xlabel('sequence');
title('unit ramp')
OUTPUT:
3
Enter the sample length of unit step sequence 8
Enter the length of ramp sequence 6
Enter the length of the exponential sequence 8
Enter the n value 5
amplitude
0.5 0.5
0 0
-4 -2 0 2 4 0 2 4 6 8
time period sequence
17
unit ramp x 10 exponential sequence
6 3
amplitude
amplitude
4 2
2 1
0 0
0 2 4 6 0 2 4 6 8
sequence time period
RESULT:
Thus the MATLAB programs for discrete time signal sequence (Unit step, Unit ramp, Sine, Cosine,
Exponential, Unit impulse) using MATLAB function written and the results were plotted.
EXP.NO : 2
LINEAR AND
4 CIRCULAR CONVOLUTIONS
DATE :
AIM:
To write MATLAB programs for Linear And Circular Convolutions
APPARATUS REQUIRED:
PROCEDURE:
Start the MATLAB program.
Open new M-file
Type the program
Save in current directory
Compile and Run the program
If any error occurs in the program correct the error and run it again
For the output see command window\ Figure window
Stop the program.
PROGRAM:
6
%computation of circular convoluted sequence
for n=1:N;
y(n)=0;
for i=1:N;
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+g(i)*h(j);
end
end
figure;
subplot(3,1,1);
stem(g);
ylabel('amplitude');
xlabel('n1..>');
title('input sequence')
subplot(3,1,2);
stem(h);
ylabel('amplitude');
xlabel('n2');
title('impulse sequence')
subplot(3,1,3);
stem(y);
ylabel('amplitude');
xlabel('n3');
disp('the resultant signal is');
7
OUTPUT : LINEAR CONVOLUTION
input sequence
4
amlitude
0
1 1.5 2 2.5 3 3.5 4
n1....>
impulse signal
4
amlitude
0
1 1.5 2 2.5 3 3.5 4
n2....>
40
amlitude
20
0
1 2 3 4 5 6 7
n3
8
OUTPUT : CIRCULAR CONVOLUTION
Enter the input sequence [1 2 2 1]
Enter the impulse sequence [4 3 2 1]
The resultant signal is
y = [ 15 17 15 13 ]
input sequence
2
amplitude
0
1 1.5 2 2.5 3 3.5 4
n1..>
impulse sequence
4
amplitude
0
1 1.5 2 2.5 3 3.5 4
n2
20
amplitude
10
0
1 1.5 2 2.5 3 3.5 4
n3
RESULT:
Thus the MATLAB programs for linear convolution and circular convolution written and the results
were plotted.
EXP.NO : 3
AUTO CORRELATION AND CROSS CORRELATION
DATE : 9
AIM:
To write MATLAB programs for auto correlation and cross correlation
APPARATUS REQUIRED:
PROCEDURE:
Start the MATLAB program.
Open new M-file
Type the program
Save in current directory
Compile and Run the program
If any error occurs in the program correct the error and run it again
For the output see command window\ Figure window
Stop the program.
clc;
clear all;
close all;
x=input('Enter the sequence 1: ');
h=input('Enter the sequence 2: ');
y=xcorr(x,h);
figure;
subplot(3,1,1); stem(x);
10
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 1');
subplot(3,1,2);
stem(fliplr(y));
stem(h);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 2');
subplot(3,1,3);
stem(fliplr(y));
xlabel('n->');
ylabel('Amplitude->');
title('Output sequence');
disp('The resultant is');
fliplr(y);
11
PROGRAM: (Auto Correlation Function)
clc;
close all;
clear all;
x=input('Enter the sequence 1: ');
y=xcorr(x,x);
figure;
subplot(2,1,1);
stem(x);
ylabel('Amplitude->');
xlabel('n->');
title('Input sequence');
subplot(2,1,2);
stem(fliplr(y));
ylabel('amplitude');
xlabel('n->');
title('Output sequence');
disp('the resultant is ');
fliplr(y);
12
RESULT:
Thus the MATLAB programs for auto correlation and cross correlation written and the results were
plotted
EXP.NO : 4
FREQUENCY
13 ANALYSIS USING DFT
DATE :
AIM:
To write MATLAB programs for Frequency Analysis using DFT
APPARATUS REQUIRED:
PROCEDURE:
Start the MATLAB program.
Open new M-file
Type the program
Save in current directory
Compile and Run the program
If any error occurs in the program correct the error and run it again
For the output see command window\ Figure window
Stop the program.
OUTPUT:
INPUT:
type length of DFT=32
type sampling period=64
type the sinusoidal freq=11
15
OUTPUT:
RESULT:
Thus the Spectrum Analysis of the signal using DFT is obtained using MATLAB.
APPARATUS REQUIRED:
PROCEDURE:
Start the MATLAB program.
Open new M-file
Type the program
Save in current directory
Compile and Run the program
If any error occurs in the program correct the error and run it again
For the output see command window\ Figure window
Stop the program.
17
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;
end;
y=boxcar(n1);
%lowpass 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.....>');
%highpass 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];0
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
18
subplot(2,2,3);
plot(o/pi,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.....>');
OUTPUT
19
%program for the design of FIR lowpass, high pass, band pass, band stop filter
using hanning 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;
end;
Y=hanning(n1);
%lowpass 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');
%highpass filter
20
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];
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....>');
%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....>')
OUTPUT:
21
RESULT:
Thus the program to design FIR low pass, high pass, band pass and band stop Filters using
Rectangular & Hanning Window was written and response of the filter using MATLAB was
executed.
APPARATUS REQUIRED:
PROCEDURE:
Start the MATLAB program.
Open new M-file
Type the program
Save in current directory
Compile and Run the program
If any error occurs in the program correct the error and run it again
For the output see command window\ Figure window
Stop the program.
PROGRAM:
% Butterworth filter
% get the input values
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband frequency');
ws=input('enter the stopband frequency');
fs=input('enter the sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
%filter order
23
[n,wn]=buttord(w1,w2,rp,rs);
%lowpass filter
%either coefficient
[b,a]=butter(n,wn);
%frequency response
[h,w]=freqz(b,a,512);
subplot(2,2,1);
plot(w,abs(h));
xlabel('normalized frequency');
ylabel('abs(h)');
title('lpf')
%high pass filter
%filter coefficient
[b,a]=butter (n,wn,'high');
%frequency response
[h,w]=freqz(b,a,512);
subplot(2,2,2);
plot(w,abs(h));
xlabel('normalised frquency');
ylabel('abs(h)');
title('hpf')
%band pass filter
%filter coefficient
wn1=[w1 w2];
[b,a]=butter(n,wn1);
%frequency response
[h,w]=freqz(b,a,512);
subplot(2,2,3);
plot(w,abs(h));
xlabel('normalised frequency');
ylabel('abs(h)');
title('bpf')
24
%band pass filter
%filter coefficient
wn2=[w1 w2];
[b,a]=butter(n,wn2,'stop');
%frequency response
[h,w]=freqz(b,a,512);
subplot(2,2,4);
plot(w,abs(h));
xlabel('normalised frequency');
ylabel('abs(h)');
title('bsf')
% chebyshew filter
OUTPUT
26
IIR : (BUTTERWORTH FILTER)
abs(h)
abs(h)
0.5 0.5
Enter the stop band frequency 3000
Enter the sampling frequency 8000
0 0
0 1 2 3 4 0 1 2 3 4
normalized frequency normalised frquency
bpf bsf
1 1
abs(h)
abs(h)
0.5 0.5
0 0
0 1 2 3 4 0 1 2 3 4
normalised frequency normalised frequency
abs(H)
0.5 0.5
Enter the stop band frequency 3000
Enter the sampling frequency 8000
0 0
0 1 2 3 4 0 1 2 3 4
normalised frequency normalised frequency
BPF BSF
1 1
abs(H)
abs(H)
0.5 0.5
0 0
0 1 2 3 4 0 1 2 3 4
normalised frequency normalised frequency
27
RESULT:
Thus the program to design IIR Butterworth & Chebyshew Filter (LPF/HPF/BPF/BSF) by using
MATLAB was executed.
EXP.NO : 7
STUDY OF ARCHITECTURE
28 OF DIGITAL SIGNAL PROCESSOR
DATE :
AIM:
To study the architecture of digital signal processor TMS320C6678/6718.
29
A programmable DSP device should provide instructions similar to a conventional microprocessor. The
instruction set of a typical DSP device should include the following,
a. Arithmetic operations such as ADD, SUBTRACT, MULTIPLY etc
b. Logical operations such as AND, OR, NOT, XOR etc
c. Multiply and Accumulate (MAC) operation
d. Signal scaling operation
In addition to the above provisions, the architecture should also include,
a. On chip registers to store immediate results
b. On chip memories to store signal samples (RAM)
c. On chip memories to store filter coefficients (ROM)
Multipliers
The advent of single chip multipliers paved the way for implementing DSP functions on a VLSI
chip. Parallel multipliers replaced the traditional shift and add multipliers now days. Parallel
multipliers take a single processor cycle to fetch and execute the instruction and to store the result.
They are also called as Array multipliers.
The key features to be considered for a multiplier are
a. Accuracy
b. Dynamic range
c. Speed
Shifters
Shifters are used to either scale down or scale up operands or the results.
Barrel Shifters
In conventional microprocessors, normal shift registers are used for shift operation. As it requires one
clock cycle for each shift, it is not desirable for DSP applications, which generally involves more
shifts. In other words, for DSP applications as speed is the crucial issue, several shifts are to be
accomplished in a single execution cycle. This can be accomplished using a barrel shifter, which
connects the input lines representing a word to a group of output lines with the required shifts
determined by its control inputs.
Multiply and Accumulate Unit
30
Most of the DSP applications require the computation of the sum of the products of a series of
successive multiplications. In order to implement such functions a special unit called a multiply and
Accumulate (MAC) unit is required.
Arithmetic and Logic Unit
A typical DSP device should be capable of handling arithmetic instructions like ADD, SUB, INC,
DEC etc., and logical operations like AND, OR, NOT, XOR etc.
On-chip Memories
In order to have a faster execution of the DSP functions, it is desirable to have some memory located
on chip. As dedicated buses are used to access the memory, on chip memories are faster. Speed and
size are the two key parameters to be considered with respect to the on-chip memories.
Speed:
On-chip memories should match the speeds of the ALU operations in order to maintain the single
cycle instruction execution of the DSP.
Size:
In a given area of the DSP chip, it is desirable to implement as many DSP functions as possible. Thus
the area occupied by the on-chip memory should be minimum so that there will be a scope for
implementing more number of DSP functions on-chip.
RESULT:
Thus the functional architecture of TMS320C6678/6718 Digital Signal Processor was studied.
APPARATUS REQUIRED:
TMS320C6678/6718 DSP processor
ADDRESSING MODES:
The addressing modes on the DSP are linear, circular using BK0, and circular using BK1. The
addressing mode is specified by the addressing mode register (AMR).All registers can perform linear
addressing. Only eight registers can perform circularaddressing: A4-A7 is used by the D1 unit and
B4-B7 is used by the D2 unit. No other unitscan perform circular addressing.
LDB (U)/LDH (U)/LDW, STB/STH/STW, LDNDW, LDNW, STNDW, STNW, LDDW,STDW,
ADDAB/ ADDAH/ ADDAW/ ADDAD and SUBAB/SUBAH/SUBAW instructions all use AMR to
determine what type of addresscalculations are performed for these registers. There is no SUBAD
instruction.
ADDRESSING MODE REGISTER (AMR)
For each of the eight registers (A4-A7, B4-B7) that can perform linear or circular addressing, the
addressing mode register (AMR) specifies the addressing mode. A 2-bit field for each register selects
the address modification mode: linear (the default) or circular mode. With circular addressing, the
field also specifies which BK (block size) field to use for a circular buffer. The mode select & block
size fields are choosing by writing values to AMR. The register details about AMR are available at
TMS320C6678 DSP CPU and Instruction Set Reference Guide.
32
For integer addition and subtraction instructions, linear mode simply shifts the src1/cst operand to
the left by 3, 2, 1, or 0 for double word, word, half word, or byte data sizes, respectively, and then
performs the add or subtract specified.
CIRCULAR ADDRESSING MODE
The BK0 and BK1 fields in AMR specify the block sizes for circular addressing
LD and ST Instructions
As with linear address arithmetic, offsetR/cst is shifted left by 3, 2, 1, or 0 according to the data size,
and is then added to or subtracted from base R to produce the final address.Circular addressing
modifies this slightly by only allowing bits N through 0 of the result to be updated, leaving bits 31
through N + 1 unchanged after address arithmetic. The resulting address is bounded to 2(N + 1)
range, regardless of the size of the offsetR/cst. The circular buffer size in AMR is not scaled; for
example, a block-size of 8 is 8 bytes, not 8 times the data size (byte, half word, and word). So, to
perform circular addressing on an array of 8 words, a size of 32 should be specified, or N = 4.
Example shows an LDW performed with register A4 in circular mode and BK0 = 4, so the buffer
size is 32 bytes, 16 half words, or 8 words. The value in AMR for this example is 0004 0001h.
RESULT:
Thus, the various addressing mode of DSP processor TMS320C6678/6718 was studied
APPARATUS REQUIRED
ARDUINO CODE
34
PROCEDURE
Initialize Constant value in the code.
These signals are output to the two DAC channels using the analogWrite() function.
OUTPUT
RESULT :
Thus various elementary signals and random noise are generated using Arduino Due Board.
EXP.NO : 10 DESIGN AND DEMONSTRATION OF FIR FILTER FOR LOW PASS AND
DATE : HIGH PASS FILTERING
35
AIM :
To design and demonstrate of FIR Filter for Low pass, High pass filtering using Arduino.
APPARATUS REQUIRED
ARDUINO CODE
LOW PASS FILTER
36
OUTPUT
//Global Variables
int sensorPin = 0;
int sensorValue = 0;
float EMA_a = 0.3;
int EMA_S = 0;
int highpass = 0;
void setup(){
Serial.begin(115200)
EMA_S = analogRead(sensorPin);
}
void loop(){
sensorValue = analogRead(sensorPin);
EMA_S = (EMA_a*sensorValue) + ((1-EMA_a)*EMA_S);
highpass = sensorValue - EMA_S;
Serial.println(highpass);
delay(20);
}
OUTPUT
37
PROCEDURE
Initialize Constant value in the code.
These signals are output to the two DAC channels using the analogWrite() function.
RESULT :
Thus FIR Filter for Low pass & High pass filtering using Arduino Due Board was designed
and demonstrated.
EXP.NO : 11 DESIGN AND DEMONSTRATION OF IIR FILTERS FOR LOW PASS &
38
HIGH PASS FILTERING
DATE :
AIM :
To design the Butterworth and Chebyshev IIR filter for low pass, high pass filtering using the DSP
Processor and simulation software CCS Compiler.
APPARATUS REQUIRED
3. Create a New Target Configuration, by selecting the tab File->New and clicking Target
Configuration File.
4. Enter a configuration file name (say "evmc6678l_xds100v1.ccxml") in the file name field and
hit finish button (the procedure assumes you are using On-boardXDS100 - class USB emulation).
5. Select the connection type as "Texas Instruments XDS100v1 USB emulator" forXDS100 or
"Blackhawk XDS560v2-USB Mezzanine Emulator" for XDS560 inthe drop down list and enter
device number (6678) in the Board or Device to select TMS320C6678
7. In the Initialization script, browse for the evmc6678l.gel file from the directory
39
<CCS Installation Directory>\ccsv6\ccs_base\emulation\boards\evmc6678l\gel as shown below:
10. Right click on the configuration file and select Launch Selected Configuration.This will
launch the configuration and open the debug view.
11. The first step isto create a project in CCS for this example. To do so follow the steps below.
16. Now that we have a project, we are going to create a source file that will use the MCSDK
Platform Library to
17. Select File->New->Source File, enter Source File name as IIR_Filter.c, and then click Finish.
40
22. Run the program using F5.
PROGRAM
//IIR LOW PASS
#include "L138_LCDK_aic3106_init.h"
#include "math.h"
#define N 2
#define wc 250
int i,w,c;
float H[1000];
float mul(float,int);
int main(void)
{
L138_initalise_intr(FS_8000_HZ,ADC_GAIN_0DB,DAC_AT TEN_0DB,LCDK_LINE_INPUT);}
interrupt void interrupt4(void)
{
for(w=0;w<=1000;w++)
{
H[w]=1/sqrt(1+mul((w/(float)wc),2*N));
printf("\nH[%d]=%f",w,H[w]);
}
}
float mul(float a,int x)
{
for(i=0;i<x-1;i++)
{
a*=a;
}
return(a);
}
OUTPUT:
41
PROCEDURE
42
Start the program.
If any error occurs in the program correct the error and run it again
RESULT :
Thus an IIR filter was designed and demonstrated using DSP Processor and the frequency
response were plotted.
43
EXP.NO : 12 IMPLEMENT AN UP-SAMPLING AND DOWN-SAMPLING OPERATION
DATE : USING DSP PROCESSOR
AIM :
To implement the up sampling and down sampling process using DSP Processor using composer
software CCS.
APPARATUS REQUIRED
1. Set the EVM Boot Mode to "No Boot" and power on the EVM
3. Create a New Target Configuration, by selecting the tab File->New and clicking Target
Configuration File.
4. Enter a configuration file name (say "evmc6678l_xds100v1.ccxml") in the file name field and
hit finish button (the procedure assumes you are using On-boardXDS100 - class USB emulation).
5. Select the connection type as "Texas Instruments XDS100v1 USB emulator" forXDS100 or
"Blackhawk XDS560v2-USB Mezzanine Emulator" for XDS560 inthe drop down list and enter
device number (6678) in the Board or Device to select TMS320C6678
7. In the Initialization script, browse for the evmc6678l.gel file from the directory
10. Right click on the configuration file and select Launch Selected Configuration.This will
launch the configuration and open the debug view.
11. The first step is to create a project in CCS for this example. To do so follow the steps below.
12. Select Project Type: as C6000 & Device Variant: as Generic C66xx Device
15. Now that we have a project, we are going to create a source file that will use the MCSDK
Platform Library to
16. Select File->New->Source File, enter Source File name as ID_Process.c, & then click Finish.
45
PROGRAM
OUTPUT
46
/* program to perform Decimation */
OUTPUT :
47
PROCEDURE
Start the program.
If any error occurs in the program correct the error and run it again
RESULT :
Thus the implementation of down sampling and up sampling along with sampling rate
conversion was performed using DSP Processor and the output is verified using code
composer studio
48