Lab Manual 2020-21
Lab Manual 2020-21
Lab Manual
Digital Signal Processing
(KEC-553)
MOOCs).
2. Write a Program for the generation of basic signals such as unit impulse, unit step, ramp,
3. Implement IIR Butterworth analog Low Pass for a 4 KHz cut off frequency.
11. To study about DSP Processors and architecture of TMS320C6713 DSP processor.
12.2 Study of FIR filter design using window method: Low pass and high pass filter.
12.3 Study of FIR filter design using window method: Band pass and Band stop filter.
13. Implementation of FFT of given sequence and obtain the magnitude and phase response
of the same.
Aim: Introduction to MATLAB or Open Source Software, Scilab (Using Spoken Tutorial
MOOCs).
MATLAB Windows:
MATLAB works with through these basic windows
Command Window
This is the main window .it is characterized by MATLAB command promp when you launch
the application program MATLAB puts you in this window all commands including those for
user-written programs ,are typed in this window at the MATLAB prompt
Graphics Window
The output of all graphics commands typed in the command window are flushed to
the graphics or figure window, a separate gray window with white background color the
user can create as many windows as the system memory will allow.
Edit Window
This is where you write edit, create and save your own programs in files called M files.
Input-output
MATLAB supports interactive computation taking the input from the screen and
flushing, the output to the screen. In addition it can read input files and write output
files
Data Type
The fundamental data –type in MATLAB is the array. It encompasses several distinct
data objects- integers, real numbers, matrices, character strings, structures and cells.
There is no nee d to declare variables as real or complex, MATLAB automatically sets
the variable to be real.
Dimensioning
Dimensioning is automatic in MATLAB. No dimension statements are required for
vectors or arrays. We can find the dimensions of an existing matrix or a vector with the
size and length commands.
Where to work in MATLAB?
All programs and commands can be entered either in the
a) Command window
b) As an M file using MATLAB editor
Operations on vector and matrices in MATLAB
MATLAB utilizes the following arithmetic operators:
+ Addition
- Subtraction
* Multiplication
/ Division
^ Power Operator
QUESTIONS-
1. List out the operators that MATLAB allows?
MATLAB allows following Operators
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operations
• Set Operations
• While Loop
• For Loop
• Nested Loops
• Scripts: It is a file with .m extension. In these files, it writes series of command that
you want to execute together. It does not accept inputs and do not return any outputs
• Functions: They are also files with .m extension. Functions can accept inputs and
return outputs.
Aim: Write a Program for the generation of basic signals such as unit impulse, unit step,
ramp, exponential, sinusoidal and cosine.
Apparatus:
Program:-
(a). Program for the generation of UNIT impulse signal
clc;
close all;
clear all;
t = -3:1:3;
y = [zeros(1,3),ones(1,1),zeros(1,3)];
subplot(2,2,1);
stem(t,y);
ylabel('Amplitude------>');
xlabel('(a)n ------>');
title('Unit Impulse Signal');
t = 0:n2;
a = input('Enter the Amplitude');
%a=1%
y2 = exp(a*t);
subplot(2,2,4);
stem(t,y2);
ylabel('Amplitude------>');
xlabel('(d)n ------>');
title('Exponential sequence');
disp('Unit impulse signal');y
disp('Unit step signal');y1
disp('Unit Ramp signal');x
disp('Exponential signal');y2
Command Window
Edit Window
Graphics Window
TANIA GUPTA ECE LAB MANUAL DSP LAB (KEC-553)
Experiment No. 3
AIM: Implement IIR Butterworth analog Low Pass for a given sequence
THEORY:
The Butterworth filter is a type of signal processing filter designed to have a frequency
response as flat as possible in the passband. It is also referred to as a maximally flat magnitude
filter. Butterworth showed that a low pass filter could be designed whose cut-off frequency
was normalized to 1 radian per second and whose frequency response (gain) was where ω is
the angular frequency in radians per second and n is the number of poles in the filter—equal to
the number of reactive elements in a passive filter. The frequency response of the Butterworth
filter is maximally flat (i.e. has no ripples) in the passband and rolls off towards zero in the
stopband.
PROGRAM:
clc;
close all;
clear all;
format long
rp=input('enter the passband ripple');
rs=input('enter stopband ripple');
wp=input('enter passband freq');
ws=input('enter stopband freq');
fs=input('enter sampling freq');
w1=2*wp/fs;
w2=2*ws/fs;
%Analog LPF
[n,wn]= buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(3)
plot(om/pi,m);
title('**** Analog Output Magnitude *****');
ylabel('gain in db...>');
xlabel('normalised freq..>');
figure(2)
plot(om/pi,an);
title('**** Analog Output Phase ****');
xlabel('normalised freq..>');
ylabel('phase in radians...>');
n
wn
TANIA GUPTA ECE LAB MANUAL DSP LAB (KEC-553)
Output Value:
INPUT:
rp = 0.500
rs = 100
wp = 1500
ws = 3000
fs = 10000
Output:
n = 13
wn = 0.32870936151976
RESULT: Butter worth Digital and analog low pass IIR filters are implemented using
MATLAB.
QUESTIONS-
1. Define IIR filters?
The impulse responses of recursive filters are composed of sinusoids that exponentially
decay in amplitude. In principle, this makes their impulse responses infinitely long.
However, the amplitude eventually drops below the round-off noise of the system, and
the remaining samples can be ignored. Because of this characteristic, recursive filters
are also called Infinite Impulse Response or IIR filters. In comparison, filters carried
out by convolution are called Finite Impulse Response or FIR filters.
Experiment No 4
PROGRAM
%Blackman Window
% 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;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=blackman(n1);
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,3,1);
plot(o/pi,m);
ylabel('Gain in DB---->');
xlabel('Normalized frequency');
title('Low Pass');
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,3,2);
plot(o/pi,m);
ylabel('Gain in DB---->');
xlabel('Normalized frequency');
title('High Pass');
%Hamming 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=hamming(n1);
Output
For Blackman:
Enter the passband ripple .03
Enter the stop band ripple 0.01
Enter the passband freq 2000
Enter the stopband freq 2500
Enter the sampling freq 7000
Waveform:
For Hamming:
Waveform:
RESULT:
QUESTIONS-
Experiment No.5
Let x(n) be a finite duration sequence. The N-point DFT of the x(n) is expressed by
𝑁−1
(𝑋(𝑘)) = ∑𝑛=0 x(n)𝑒 −𝑗2𝜋𝑛𝑘/𝑁
1 𝑁−1
(𝑥(𝑛) = ∑𝑛=0 X(k)𝑒 𝑗2𝜋𝑛𝑘/𝑁 n=0,1 ,…N-1 ----------------------------------(2)
𝑁
Program:
DFT
clc;
close all;
clear all;
xn=input('enter 8 inputs');
N=length(xn);
n=0:N-1;
k=0:N-1;
wn=exp((-1i*2*pi*n'*k)/N);
xf=wn*xn';
subplot(2,2,1);
stem(abs(xf));
title('dft magnitude respone');
ylabel('magnitude');
xlabel('frequncy');
IDFT
WN=exp((1i*2*pi*n'*k)/N);
pn=WN*xf/N;
subplot(2,2,2);
stem(abs(pn));
title('idft magnitude respone'
ylabel('magnitude');
xlabel('time');
Result:
Questions
QUESTIONS-
PROGRAM:-
clc;
clear all;
close;
disp('enter the length of the first sequence m=');
m=input('');
disp('enter the length of first sequence x[m]=');
for i=1:m
x(i)=input('');
end
disp('enter the length of the second sequence n=');
n=input('');
disp('enter the length of second sequence h[n]=');
for j=1:n
h(j)=input('');
end
y=conv(x,h);
figure;
subplot(3,1,1);
stem(x);
ylabel ('amplitude---->');
xlabel('n---->');
title('x(n) Vs n');
subplot(3,1,2);
stem(h);
ylabel('amplitude---->');
xlabel('n---->');
title('h(n) Vs n');
subplot(3,1,3);
stem(y);
ylabel('amplitude---->');
xlabel('n---->');
title('y(n) Vs n');
disp('linear convolution of x[m] and h[n] is y');
INPUT:--
OUTPUT:-
Linear convolution of x[m] and h[n] is y=
1 4 10 20 35 56 70 76 73 60 36
RESULT :- Thus the program for linear convolution is written using MATLAB and verified.
QUESTIONS-
PROGRAMME:-.
clc;
clear all;
close;
m=input('');
for i=1:m
x(i)=input('');
end
n=input('');
for j=1:n
h(j)=input('');
end
y=cconv(x,h);
figure;
subplot(3,1,1);
stem(x);
ylabel ('amplitude---->');
xlabel('n---->');
title('x(n) Vs n');
subplot(3,1,2);
stem(h);
ylabel('amplitude---->');
xlabel('n---->');
title('h(n) Vs n');
subplot(3,1,3);
stem(y);
ylabel('amplitude---->');
xlabel('n---->');
title('y(n) Vs n');
OUTPUT:
59 62 59 50 35 50
CONCLUSION: Thus the program for Circular convolution is written using MATLAB and
verified.
QUESTIONS-
2. What is Convolution
Convolution is the technique of adding two signals in the time domain. We can easily
do that by changing the domain of the signal from time domain to frequency domain
using FFT.
PROGRAM
% Generate some sample points in the interval [0,3π] for the function f(x)=sin2(x)cos(x).
Use a spacing interval dx to ensure the data is evenly spaced. Plot the sample points. Plot
the results.
dx = 3*pi/30;
x = 0:dx:3*pi;
f = sin(x).^2 .* cos(x);
plot(x,f,'o')
%Use FFT interpolation to find the function value at 200 query points.
N = 200;
y = interpft(f,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. Truncate the
data in y to match the sampling density of x2.
dy = dx*length(x)/N;
x2 = 0:dy:3*pi;
y = y(1:length(x2));
Waveform:
Figure: Sample Points of the function
RESULT:
Program:
QUESTIONS-
If you know the generation of sine wave, you can compose any tune in the MATLAB with
the help of tone generation program.
Experiment No 10
Program:
1.
(a) % created a 1-by-1 array of type double for the value you just stored in x
x = 25.783;
whos x
(b) % created a 1-by-1 array of type single for the value you just stored in y
y = single(10);
whos y
isfloat(x)
3.
% Converts a signed integer to double precision floating point
4.
% Creating a single precision data
y = int64(-589324077574); % Create a 64-bit integer
5. % Double precision operation( performs operation on data of type double and char.
Result is of type char
class(c)
(b) char(c)
6. %Single Precision Operation
x = single([1.32 3.47 5.28]) .* 7.5;
class(x)
Result:
1.
(a) Name Size Bytes Class
2. Logical
1
3. x =
-5.8932e+11
4.
x=
single
-5.8932e+11
5. ans =
double
ans =
UPPERCASE
6. ans =
single
QUESTIONS-
Theory:
TMS320C50 Architecture Overview
1. Introduction:
It is needless to say that in order to utilize the full feature of the DSP chip TMS320C50, the
DSP engineer must have a complete knowledge of the DSP device. This chapter is an
introduction to the hardware aspects of the TMS320C50. The important units of TMS320C50
are discussed.
The TMS320C50 is a 16-bit fixed point digital signal processor that combines the flexibility
of a high speed controller with the numerical capability of an array processor, thereby offering
an inexpensive alternative to multichip bit-slice processors. The highly paralleled architecture
and efficient instruction set provide speed and flexibility capable of executing 10 MIPS
(Million Instructions per Second). The TMS320C50 optimizes speed by implementing
functions in hardware that other processors implement through microcode or software. This
hardware intensive approach provides the design engineer with processing power previously
unavailable on a single chip.
The TMS320C50 is the third generation digit l signal processor in the TMS320 family. Its
powerful instruction set, inherent flexibility, high-speed number-crunching capabilities, and
innovative architecture have made this high-performance, cost-effective processor the ideal
solution to many telecommunications, computer, commercial, industrial, and military
applications.
* 32-bit arithmetic logic unit (ALU), 32-bit accumulator (ACC), and 32-bit accumulator
buffer (ACCB)
* Eight auxiliary registers with a dedicated auxiliary register arithmetic unit for indirect
addressing.
* 0- to 16-bit left and right data barrel-shifters and a 64-bit incremental data shifter
* Full-duplex synchronous serial port for direct communication between the `C5x and
another serial device
* Interval timer with period, control, and counter registers for software stop, start, and
reset
* Sixteen software programmable wait-state generators for program, data, and I/O
memory spaces.
4. Architecture:
The multiplier performs a 16 x 16-bit two's complement multiplication with a 32-bit result in
a single instruction cycle. The multiplier consists of three units: the T-Register, P-Register, and
multiplier array. The 16-bit T-Register temporarily stores the multiplicand and the P-Register
stores the 32-bit product. Multiplier values either come from the data memory or are derived
immediately from the MPY (multiply immediate) instruction word. The fast on-chip multiplier
allows the device to perform fundamental operations such as convolution, correlation, and
filtering. Two multiply/accumulate instructions in the instruction set fully utilize the
computational bandwidth of the multiplier, allowing both operands to be processed
simultaneously.
4.3 Shifters:
A 16-bit scaling shifter is available at the accumulator input. This shifter produces a left shift
of 0 to 16-bits on the input data to accumulator.
TMS320C50 also contains a shifter at the accumulator output. This shifter provides a left shift
of 0 to 7, on the data from either the ACCH or ACCL register, right, before transferring the
product to accumulator.
Since the TMS320C50 uses Harvard architecture, data and program memory reside in two
separate spaces. Additionally TMS320C50 has one more memory space called I/O memory
space. The total memory capacity of TMS320C50 is 64KW each of Program, Data and I/O
memory. The 64KW of data memory is divided into 512 pages with each page containing 128
words. Only one page can be active at a time. One data page selection is done by setting data
page pointer. TMS320C50 has 1056 words of dual access on chip data RAM and 9K words of
single access Data/Program RAM. The 1056 words of on chip data memory is divided as three
blocks B0, B1 & B2, of which B0 can be configured as program or data RAM.
Out of the 64KW of total program memory, TMS320C50 has 2K words of on-chip program
ROM. The TMS320C50 offers two modes of operation defined by the state of the MC/MP pin:
the microcomputer mode (MC/MP = 1) or the microprocessor mode (MC/MP = 0). In the
microcomputer mode, on-chip ROM is mapped into the memory space with upto 2K words of
memory available. In the microprocessor mode all 64K words of program memory are external.
The TMS320C50 has three external maskable user interrupts available for external devices that
interrupt the processor. The TMS320C50 contains an eight-level hardware stack for saving the
contents of the program counter during interrupts and subroutine calls. Instructions are
available for saving the device's complete context. PUSH and POP instructions permit a level
of nesting restricted only by the amount of available RAM.
A full-duplex on-chip serial port provides direct communication with serial devices such as
codecs, serial A/D converters and other serial systems. The interface signals are compatible
with codecs and many others serial devices with a minimum of external hardware.
4.7 Input and Output: The 16-bit parallel data bus can be utilised to perform I/O functions in
two cycles. The I/O ports are addressed by the four LSBs on the address lines, allowing 16
input and 16 output ports. In addition, polling input for bit test and jump operations (BIO) and
three interrupt pins (INT0 - INT2) have been incorporated for multitasking.
Software Overview
This chapter illustrates the use of program and execution mainly in the standalone mode.
1. Standalone Mode
2. Monitor program
3. Serial Mode
In "Standalone Mode" the Micro-50 EB works with a 104 keys keyboard and 16x2 LCD
display and line assembler. With this configuration, the student can enter his program through
the keyboard and edit and display it on the LCD display. The user can enter the Mnemonics
using the Line Assembler, and debug the program to run it on Micro-50 EB.
"Monitor Program" is used to enter data directly into Data or Program memory, display the
data etc. It has several commands to enter the user program, for editing and debugging.
In "Serial Mode", it works with a IBM PC computer and program entry and debugging is done
at the PC level.
QUESTIONS-
Aim: Implementation of FFT of given sequence and obtain the magnitude and phase response
of the same.
PROGRAM
%To compute the FFT for the given sequence and plot magnitude and phase response
clc;
clear all;
close all;
%exponential sequence
n=input('enter the length of input sequence: ');
t=0:1:n;
y=input('enter the input sequence');
disp(y);
subplot(3,1,1);
stem(t,y);
grid;
title('input sequence');
xlabel('time');
ylabel('amplitude');
disp(y);
xn=y;
N=input('enter the length of the FFT sequence: ');
xk=fft(xn,N);
magxk=abs(xk);
angxk=angle(xk);
k=0:N-1;
subplot(3,1,2);
stem(k,magxk);
grid;
xlabel('k');
ylabel('|x(k)|');
title('magnitude response')
subplot(3,1,3);
stem(k,angxk);
grid;
disp(xk);
xlabel('k');
ylabel('arg(x(k))');
title('angular response')
Output
enter the length of input sequence: 5
1 2 -1 -2 0 3
Columns 1 through 4
Columns 5 through 8
Waveform:
RESULT:
QUESTIONS-
1. What is the difference between DFT and FFT?
A DFT (Discrete Fourier Transform) is simply the name given to the Fourier Transform when
it is applied to digital (discrete) rather than an analog (continuous) signal. An FFT (Fast Fourier
Transform) is a faster version of the DFT that can be applied when the number of samples in
the signal is a power of two. An FFT computation takes approximately N * log2(N) operations,
whereas a DFT takes approximately N^2 operations, so the FFT is significantly faster.
PROGRAM
%Rectangular Window
% 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;
end
y=rectwin(n1);
Output
For Rectangular:
Enter the passband ripple .05
Enter the stop band ripple 0.04
Enter the passband freq 1500
Enter the stopband freq 2000
Enter the sampling freq 9000
Waveform:
RESULT:
QUESTIONS-