DSP Lab Manual 2023
DSP Lab Manual 2023
ENGINEERING DEPARTMENT
SEMESTER :_________________________________
SESSION :_________________________________
S. Date of Date of
Name of Experiment Signature
No. Experiment Submission
1 Introduction to MATLAB
Apparatus
Used
MATLAB SOFTWARE
INTRODUCTION TO MATLAB
Key Features:
High-level language for technical computing.
Development environment for managing code, files, and data.
Interactive tools for iterative exploration, design, and problem solving.
Mathematical functions for linear algebra, statistics, Fourier analysis,
Filtering, optimization, and numerical integration.
2-D and 3-D graphics functions for visualizing data.
Tools for building custom graphical user interfaces.
Functions for integrating MATLAB based algorithms with external
applications and languages, such as C, C++, Fortran, Java, COM, and Microsoft®
Excel®.
MATLAB Windows:
MATLAB works with through three basic windows
Write a Program for the generation of basic signals such as unit impulse, unit
Aim step, ramp, exponential, sinusoidal and cosine.
Apparatus
Used
MATLAB SOFTWARE
PROGRAMS: -
1. Unit Impulse: -
% Program for the generation of unit impulse signal
clc;
clear all;
close all;
t = -2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot (2,2,1);
stem (t,y);
ylabel ('Amplitude-->');
xlabel ('(a)n-->');
Output: -
2. Unit Step Sequence: -
Output: -
Output: -
Output: -
Output: -
6. Cosine Sequence: -
Output: -
Result :- We successfully generated basic signals such as unit impulse, unit step, ramp,
exponential, sinusoidal and cosine.
Experiment No.:- 3
Apparatus
Used
MATLAB
THEORY:
In this equation, x1(k), x2(n-k) and y(n) represent the input to and output from the system at time
n. Here we could see that one of the inputs is shifted in time by a value every time it is multiplied
with the other input signal. Linear Convolution is quite often used as a method of implementing
filters of various types.
Program:
clc;
clear all;
close all;
disp('linear convolution program');
x=input('enter i/p x(n):');
m=length(x);
h=input('enter i/p h(n):');
n=length(h);
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
title('i/p sequence x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
title('i/p sequence h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('convolution of x(n) & h(n) is y(n):');
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end
y
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is :');
xlabel('---->n');
ylabel('---->y(n)');grid;
Output :
Result :- Successfully verified the Linear Convolution of two sequences using FFT using
MATLAB.
Experiment No.:- 4
Apparatus
Used
MATLAB
THEORY:
Circular convolution is another way of finding the convolution sum of two input signals. It
resembles the linear convolution, except that the sample values of one of the input signals is
folded and right shifted before the convolution sum is found. Also note that circular convolution
could also be found by taking the DFT of the two input signals and finding the product of the two
frequency domain signals. The Inverse DFT of the product would give the output of the signal in
the time domain which is the circular convolution output. The two input signals could have been
of varying sample lengths. But we take the DFT of higher point, which ever signals levels to. For
example, If one of the signal is of length 256 and the other spans 51 samples, then we could only
take 256 point DFT. So the output of IDFT would be containing 256 samples instead of 306
samples, which follows N1+N2 – 1 where N1 & N2 are the lengths 256 and 51 respectively of the
two inputs. Thus the output which should have been 306 samples long is fitted into 256 samples.
The256 points end up being a distorted version of the correct signal. This process is called
circular convolution.
Program:
clc;
clear all;
close all;
disp('circular convolution program');
x=input('enter i/p x(n):');
m=length(x);
h=input('enter i/p sequence h(n)');
n=length(h);
subplot(2,2,1),
stem(x);
title('i/p sequence x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');
grid;
subplot(2,2,2),
stem(h);
title('i/p sequence h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');
grid;
if(m-n~=0)
if(m>n)
h=[h,zeros(1,m-n)];
n=m;
end
x=[x,zeros(1,n-m)];
m=n;
end
y=zeros(1,n);
y(1)=0;
a(1)=h(1);
for j=2:n
a(j)=h(n-j+2);
end
%circular convolution
for i=1:n
y(1)=y(1)+x(i)*a(i);
end
for k=2:n
y(k)=0;
% circular shift
for j=2:n
x2(j)=a(j-1);
end
x2(1)=a(n);
for i=1:n
if(i<n+1)
a(i)=x2(i);
y(k)=y(k)+x(i)*a(i);
end
end
end
y
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is:');
xlabel('---->n');
ylabel('---->y(n)');grid;
Output :
Result :- Successfully verified the Circular Convolution of two sequences using FFT using
MATLAB.
Experiment No.:- 5
Aim Implement IIR Butterworth analog Low Pass for a 4 KHz cut off frequency
Apparatus
Used
MATLAB SOFTWARE
OUTPUT:
Apparatus
Used
MATLAB SOFTWARE
THEORY: Interpolate 1-D data using the FFT method and visualize the result. Generate some
sample points in the interval for the function. Use a spacing interval dx to ensure the data is
evenly spaced. Plot the sample points.
dx = 3*pi/30;
x = 0:dx:3*pi;
f = sin(x).^2 .* cos(x);
plot(x,f,'o')
N = 200; % Use FFT interpolation to find the function value at 200 query points.
y = interpft(f,N);
dy = dx*length(x)/N; % Calculate the spacing of the interpolated data from the spacing of the
sample points with dy = dx*length(x)/N, where N is the number of interpolation points.
x2 = 0:dy:3*pi; % Truncate the data in y to match the sampling density of x2.
y = y(1:length(x2));
hold on
plot(x2,y,'.') % Plot the results
title('FFT Interpolation of Periodic Function')
OUTPUT:
Apparatus
Used
MATLAB SOFTWARE
MATLAB CODE:
Clc;
Clear all;
Close all;
t = -2:0.05:2;
x=input('enter the input number');
fr1=697;
fr2=770;
fr3=852;
fr4=941;
fc1=1209;
fc2=1336;
fc3=1477;
fc4=1633;
y0 = sin(2*pi*fr4*t) + sin(2*pi*fc2*t); % 0
y1 = sin(2*pi*fr1*t) + sin(2*pi*fc1*t); % 1
y2 = sin(2*pi*fr1*t) + sin(2*pi*fc2*t); % 2
y3 = sin(2*pi*fr1*t) + sin(2*pi*fc3*t); % 3
y4 = sin(2*pi*fr2*t) + sin(2*pi*fc1*t); % 4
y5 = sin(2*pi*fr2*t) + sin(2*pi*fc2*t); % 5
y6 = sin(2*pi*fr2*t) + sin(2*pi*fc3*t); % 6
y7 = sin(2*pi*fr3*t) + sin(2*pi*fc1*t); % 7
y8 = sin(2*pi*fr3*t) + sin(2*pi*fc2*t); % 8
y9 = sin(2*pi*fr3*t) + sin(2*pi*fc3*t); % 9
y_start = sin(2*pi*fr4*t) + sin(2*pi*fc1*t); % *
y_canc = sin(2*pi*fr4*t) + sin(2*pi*fc3*t); % #
if (x==1)
plot(t,y1)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==2)
plot(t,y2)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==3)
plot(t,y3)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==4)
plot(t,y4)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==5)
plot(t,y5)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==6)
plot(t,y6)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==7)
plot(t,y7)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==8)
plot(t,y8)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==9)
plot(t,y9)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==0)
plot(t,y0)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==11)
plot(t,y_start)
xlabel('time(t)')
ylabel('amplitude')
elseif (x==12)
plot(t,y_canc)
xlabel('time(t)')
ylabel('amplitude')
else
disp('enter the correct input')
end
OUTPUT:
INPUT:
Enter the input number = 7
Apparatus
Used
MATLAB SOFTWARE
Single-Precision Format
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.
Double-Precision Format
The IEEE double-precision floating-point format is a 64-bit word divided into a 1-bit sign
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 format is shown in
the following figure-
Apparatus
Used
MATLAB SOFTWARE
THOERY:
MATLAB CODE:
N=4;
x=[1,1,1,1];
t=0:N-1;
subplot(311)
stem(t,x);
xlabel('time (s)');
ylabel('Amplitude');
title('input sequence');
subplot(312);
stem(0:N-1,abs(fft(x)));
xlabel('frequency');
ylabel('|x(k)|');
title('magnitude response');
subplot(313);
stem(0:N-1,angle(fft(x)));
xlabel('frequency');
ylabel('phase');
title('phase response');
OUTPUT:
Apparatus
TMS320C6713 DSP Processors
Used
DSP Processors such as Texas instruments and Analog Devices Contains - CPU
- RAM
-ROM
- I/O ports
- Timer
Optimized for – fast arithmetic
- Extended precision
- Dual operand fetch
- Zero overhead loop
- Circular buffering
Feature Use
Fast-Multiply Most DSP algorithms, including filtering, transforms, etc. are
accumulate multiplication- intensive
Multiple – access Many data-intensive DSP operations require reading a program
memory instruction and multiple data items
Specialized Efficient handling of data arrays and first-in, first-out buffers in
addressing modes memory
Specialized program Efficient control of loops for many iterative DSP algorithms. Fast
control interrupt handling for frequent I/O
On-chip peripherals On-chip peripherals like A/D converters allow for small low cost
and I/O system designs. Similarly I/O
The C67xx DSP architecture is built around eight major 16-bit buses (four
program/data buses and four address buses):
_ The program bus (PB) carries the instruction code and immediate operands from program
memory.
_ Three data buses (CB, DB, and EB) interconnect to various elements, such as the CPU,
data address generation logic, program address generation logic, on-chip peripherals, and
data memory.
_ The CB and DB carry the operands that are read from data memory.
_ The EB carries the data to be written to memory.
_ Four address buses (PAB, CAB, DAB, and EAB) carry the addresses needed for
instruction execution.
The CPU is common to all C67xE devices. The C67x CPU contains:
The C67x DSP performs 2s-complement arithmetic with a 40-bit arithmetic logic unit
(ALU) and two 40-bit accumulators (accumulators A and B). The ALU can also
perform Boolean operations. The ALU uses these inputs:
The ALU can also function as two 16-bit ALUs and perform two 16-bit operations
simultaneously.
Accumulators
Accumulators A and B store the output from the ALU or the multiplier/adder block.
They can also provide a second input to the ALU; accumulator A can be an input to
the multiplier/adder. Each accumulator is divided into three parts:
_ Guard bits (bits 39–32)
_ High-order word (bits 31–16)
_ Low-order word (bits 15–0)
Instructions are provided for storing the guard bits, for storing the high- and the low-
order accumulator words in data memory, and for transferring 32-bit accumulator
words in or out of data memory. Also, either of the accumulators can be used as
temporary storage for the other.
Barrel Shifter
The C67x DSP barrel shifter has a 40-bit input connected to the accumulators or to
data memory (using CB or DB), and a 40-bit output connected to the ALU or to data
memory (using EB). The barrel shifter can produce a left shift of 0 to 31 bits and a
right shift of 0 to 16 bits on the input data. The shift requirements are defined in the
shift count field of the instruction, the shift count field (ASM) of status register ST1,
or in temporary register T (when it is designated as a shift count register).The barrel
shifter and the exponent encoder normalize the values in an accumulator in a single
cycle. The LSBs of the output are filled with 0s, and the MSBs can be either zero
filled or sign extended, depending on the state of the sign-extension mode bit (SXM)
in ST1. Additional shift capabilities enable the processor to perform numerical scaling,
bit extraction, extended arithmetic,and overflow prevention operations.
Multiplier/Adder Unit