Вы находитесь на странице: 1из 68

K. S. SCHOOL OF ENGINEERING & MANAGEMENT

# 15, Mallasandra, Off Kanakapura Road,

Bangalore-560062, Karnataka, India.

DEPARTMENT OF ELECTRONICS & COMMUNICATION

ENGINEERING

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING Digital Signal Processing Lab Manual Sub Code: 10ECL57 Sem :

Digital Signal Processing Lab Manual

Sub Code: 10ECL57

Sem : V

Prepared By

Mr. Ravikiran B. A., Asst. Professor

Mrs. Vidhya R., Asst. Professor

Table of Contents

PART A

1 Verification of Sampling theorem.

2 Impulse response of a given system

3 Linear convolution of two given sequences.

4 Circular convolution of two given sequences

Autocorrelation of a given sequence and verification of its

5 properties.

Cross-correlation of given sequences and verification of

6 its properties.

7 Solving a given difference equation.

Computation of N point DFT of a given sequence and to

8 plot magnitude and phase spectrum.

9 Linear convolution of two sequences using DFT and

IDFT.

10 Circular convolution of two given sequences using DFT

and IDFT

11 Design and implementation of FIR filter to meet given

specifications.

12 Design and implementation of IIR filter to meet given

specifications.

1

4

7

11

15

18

21

23

26

29

32

36

PART B

About the DSP Trainer Kit

Using Code Composer Studio

1 Linear convolution of two given sequences.

2 Circular convolution of two given sequences

3 Computation of N point DFT of a given sequence.

4 Impulse Response of the First Order and Second Order

Systems

Viva Questions

44

47

56

58

60

62

64

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 1

VERIFICATION OF SAMPLING THEOREM

Aim: To write the MATLAB code for verifying Sampling Theorem.

Generate a sinusoidal wave of 1kHz. Calculate the Nyquist frequency, and verify

Sampling Theorem, showing output waveforms for undersampled, oversampled and right

sampled cases.

Theory:

Sampling is the process of converting an continuous time signal into a discrete time signal.

In sampling, the values of the continuous time signal is recorded at discrete intervals of time

(usually equidistant). The number of samples taken during one second is called the sampling

rate.

( )
(
)
= 1/
= 1/

Sampling is described by the relation:

) =

< <

Where

seconds.

( ) is the discrete-time signal obtained by sampling the analog signal every T

is known as the Sampling Frequency.

The Sampling Theorem states that :

( ) = sin
(
) = sin

frequency is

than

the

Theorem states that : ( ) = sin frequency is than the “A bandlimited signal can

“A bandlimited signal can be reconstructed exactly if it is sampled at a rate atleast twice

the maximum frequency component in it."

Assume

a

band-limited

signal

( ) = sin( ) = sin(2 ) with maximum

frequency component . The theorem says that, for a good reconstruction of the original

Sampling this signal at

continuous time signal, the sampling frequency must be at least 2 . This frequency is known

as the “Nyquist Rate”.

gives us the discrete time signal:

Now,

assuming

the

sampling

()= ()=
()=
()=

Nyquist

Frequency,

the

continuous time signal can be reconstructed accurately using the interpolation function:

reconstructed accurately using the interpolation function: sin 2 Then, approximated recovered signal can be written as:

sin 2

Then, approximated recovered signal can be written as:

DSP Laboratory (10ECL57) 5 t h Sem KSSEM, Bangalore Whenever the Sampling frequency is greater

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

Whenever the Sampling frequency is greater than or equal to the Nyquist Frequency, the signal can be reconstructed faithfully, capturing all the essential properties of the original continuous-time signal. However, when < 2 , we encounter a problem called “Aliasing”,

where distortion is caused by high frequencies overlapping low frequencies. A lot of data is

lost in this process and the signal cannot be recovered.

MATLAB CODE:

% Experiment 1 : Sampling Theorem Verification

clear all; close all; clc;

% Signal Parameters

f1 = 1000;

% Signal 1 Frequency = 1kHz

f2 = 1900;

% Signal 2 Frequency = 1.4 kHz

fmax = max(f1,f2);

% Maximum frequency component of signal

T

= 1/min(f1,f2);

% Signal Period should cover entire length

t

= 0:0.01*T:2*T;

% Time index

%

Generate the original signal and plot it:

 

x

= cos(2*pi*t*f1)+ cos(2*pi*t*f2);

% Composite Signal

subplot(2,2,1);

plot(t,x); grid on;

title('Continuous signal');

xlabel('t');

ylabel('x(t)');

% Oversampling Condition:

fs1 = 10*fmax;

n1 = 0:1/fs1:2*T;

x1 = cos(2*pi*f1*n1)+cos(2*pi*f2*n1);

subplot(2,2,2);

stem(n1,x1);

hold on;

plot(n1,x1,'r'); grid on;

hold off;

title('Oversampling Condition : Fs = 10F');

xlabel('n');

ylabel('x(n)');

% Right Sampling Condition:

fs2 = 2*fmax;

% Oversampling (fs > 2f)

% Time scale

% Generating sampled signal

% Nyquist Sampling (fs = 2f)

n2 = 0:1/fs2:2*T;

x2 = cos(2*pi*f1*n2)+cos(2*pi*f2*n2);

subplot(2,2,3);

stem(n2,x2);

hold on;

plot(n2,x2,'r'); grid on;

hold off;

title('Sampling at Nyquist Frequency : Fs = 2F');

xlabel('n');

ylabel('x(n)');

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

% Under Sampling Condition:

fs3 = 1.2*fmax;

% Undersampling (fs < 2f)

n3 = 0:1/fs3:2*T;

x3 = cos(2*pi*f1*n3)+cos(2*pi*f2*n3);

subplot(2,2,4);

stem(n3,x3);

hold on;

plot(n3,x3,'r'); grid on;

hold off;

title('Undersampling Condition : Fs = 1.2 f');

xlabel('n');

ylabel('x(n)');

OUTPUT:

Condition : Fs = 1.2 f' ); xlabel( 'n' ); ylabel( 'x(n)' ); OUTPUT : Dept

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 2

IMPULSE RESPONSE OF A GIVEN SYSTEM

Aim: To write the MATLAB code to find the impulse response of a given second-order

system whose difference equation representation is given.

system whose difference equation representation is given. Assume a second-order system represented by the following
system whose difference equation representation is given. Assume a second-order system represented by the following
system whose difference equation representation is given. Assume a second-order system represented by the following
system whose difference equation representation is given. Assume a second-order system represented by the following
system whose difference equation representation is given. Assume a second-order system represented by the following

Assume a second-order system represented by the following difference equation:

()=

()+

( 1)+

( 2)+

( 1)+

( 2)

Theory:

Impulse response of a system is defined as the output of a given system, when the input

applied to the system, is in the form of a unit impulse, or a Dirac delta function. The impulse

response completely characterizes the behaviour of any LTI system. The impulse response is

often determined from knowledge of the system configuration and dynamics, or can be

measured by applying and approximate impulse to the system input.

Discrete-time LTI systems can also be described using Difference Equations.

systems can also be described using Difference Equations. [ ] constant-coefficient difference equation can be of
[ ]
[
]

constant-coefficient difference equation can be of the form:

[ ]=

A linear

Where the integer N is termed the order of the difference equation, and corresponds to the

maximum memory involving the system output. The order generally represents the number of

energy storage devices in a physical system.

We can calculate the impulse response of the system using Z-transforms as shown in the

following example:

( ( ) + 3 ( 1) 0.12 ( 2) = ( ( ) +
(
( ) + 3 ( 1) 0.12 ( 2)
=
(
(
) + 3
(
) 0.12
(
)[1 + 3
0.12
] =
(
2) ( ) ]
2)
(
)
]

Consider a difference equation:

) = ( ) + 0.2 ( 1) 1.5 ( 2) 3 ( 1) + 0.12 (

This can be rewritten in the standard form as:

) + 0.2 ( 1) 1.5 ( 2)

Finding the Z-transform of the equation:

Or:

( ) = ( ) + 0.2

) 1.5

)[1 + 0.2

1.5

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

Transfer Function of the system can be obtained as : ( ) [1 + 3
Transfer Function of the system can be obtained as :
(
)
[1 + 3
0.12
]
( )=
=
(
) [1+0.2
1.5
]
By long division, we get:
(
) = 1 2.8
+ 7.02
21.4
+ 65.03
By taking Inverse-Z transform, we can obtain the Impulse Response as:
= [1 2.8 7.02 21.4 65.03]
[
]

MATLAB CODE:

% Experiment 2 : Impulse Response of a Given Second-Order System

clear all; close all; clc;

%

Accept Input and Output signal Co-efficients:

b

= input('Enter the coefficients of x(n) in 1-D Matrix Form: ');

a

= input('Enter the coefficients of y(n) in 1-D Matrix Form: ');

N

= input('Enter the number of samples of impulse response desired: ');

%

Calculate Impulse Response using IMPZ function:

%

[H,T] = IMPZ(B,A,N) computes N samples of the impulse response, using

%

coefficients B and A from difference equation representation.

[h,t] = impz(b,a,N);

%Plot and Display impulse response co-efficients:

stem(t,h);

title('Impulse Response Plot');

ylabel('h(n)'); xlabel('n');

disp('Impulse Response Coefficients:');

disp(h);

OUTPUT:

Enter the coefficients of x(n) in 1-D Matrix Form: [1 0.2 -1.5]

Enter the coefficients of y(n) in 1-D Matrix Form: [1 3 -0.12]

Enter the number of samples of impulse response desired: 5

Impulse Response Coefficients:

1.0000

-2.8000

7.0200

-21.3960

65.0304

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

DSP Laboratory (10ECL57) 5 t h Sem KSSEM, Bangalore Dept of ECE Page | 6

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 3

LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES

Aim: To write the MATLAB code to perform Linear Convolution upon two given discrete

time signals.

Theory:

Convolution is the process used to find the response of a Linear Time Invariant system to a

given input, assuming we already know the impulse response of that system. In case of

continuous-time signals, we can find the system response using the Convolution Integral,

( ) and ( ) (
(
) and
(
)
(

while in case of discrete-time systems, the response can be calculated using the Convolution

Sum.

Let

) be two discrete-time signals. The convolution sum of the two signals

1() 2( ) 2(
1() 2( )
2(

can be calculated using the formula:

()= 1() 2()=

If 1(

is a M- point sequence and

) is an N point sequence, then the convolved

sequence,

) is a (M+N-1) point sequence.

We can perform the convolution by different methods:

1. Using MATLAB’s “CONV” function :

MATLAB has a built-in function called “convfunction, which basically performs a

linear convolution of any two given sequences.

2. Using the Linear Convolution Sum formula :

Here, we use the convolution sum formula and substitute values of and in the

convolution sum formula and substitute values of and in the calculate the resultant signal values. 1

calculate the resultant signal values.

1 and

expression, and calculate the values of the convolved signal. Alternatively, we can

perform the signal inversion-time shift-superposition method, by which we can

Assume two discrete-time sequences

by:

2 in a Linear Time Invariant System, given

2 is (N = 3). Therefore,

1( ) = {1, 2, 1, 3} and 2( ) = {2,3, 2}

We see that length of sequence

1 is (M = 4) and that of sequence

the length of the convolved sequence will be (M+N-1 = 6).

Using any of the above given methods, we see that the resultant convolved sequence can be

given by:

) = 1(

2( ) = { 2

7

2

1 11 6}

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

MATLAB CODE:

1. Using “conv” function:

%% Linear Convolution using CONV command

clear all; close all; clc;

% Accept input signal sequences

x1 = input('Enter Input Sequence for Signal x1(n): ');

x2 = input('Enter Input Sequence for Signal x2(n): ');

%Perform Linear Convolution using CONV command

y=conv(x1,x2);

%Plot Input and Convolved Signals

subplot(3,1,1);

stem(x1);

title('Input Signal x1(n)');

xlabel('n'); ylabel('x1(n)');

subplot(3,1,2);

stem(x2);

title('Input Signal x2(n)');

xlabel('n'); ylabel('x2(n)');

subplot(3,1,3);

stem(y);

title('Convolved Signal y(n) = x1(n)*x2(n)');

xlabel('n'); ylabel('y(n)');

% Display the convolved Sequence in Command Window

disp('Convolved sequence:');

disp(y);

2. Using Convolution Sum formula:

%% Linear Convolution without using CONV command

clear all; close all; clc;

x1 = input('Enter Input Sequence for Signal x1(n): ');

n1 = length(x1);

x2 = input('Enter Input Sequence for Signal x2(n): ');

n2=length(x2);

N

= n1+n2-1;

%Length of Convolved Sequence

T

= 1:N;

% Create Time Index

%Zero padding to make sequences of length N

x1=[x1 zeros(1,N-n1)];

x2=[x2 zeros(1,N-n2)];

%Initializing Output sequence of zeros.

y = zeros(1,N);

%Performing Linear Convolution:

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

for n = 1:N

% y(n) = 0R; for k = 1:n

y(n)=y(n)+x1(k)*x2(n-k+1);

end

end

% Plot Input and Output Sequences:

subplot(3,1,1);

stem(T,x1);

title('Input Signal x1(n)');

xlabel('n'); ylabel('x1(n)');

subplot(3,1,2);

stem(T,x2);

title('Input Signal x2(n)');

xlabel('n'); ylabel('x2(n)');

subplot(3,1,3);

stem(T,y);

title('Convolved Signal y(n) = x1(n)*x2(n)');

xlabel('n'); ylabel('y(n)');

% Display the convolved Sequence in Command Window

disp('Convolved sequence:');

disp(y);

OUTPUT:

Enter Input Sequence for Signal x1(n): [1 2 -1 3]

Enter Input Sequence for Signal x2(n): [2 3 -2]

Convolved sequence:

2

7

2

-1

11

-6

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

DSP Laboratory (10ECL57) 5 t h Sem KSSEM, Bangalore Dept of ECE Page | 10

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 4

CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES

Aim: To write the MATLAB code to perform Circular Convolution upon two given discrete

time signals.

Theory:

The Circular convolution, also known as cyclic convolution, of two aperiodic functions occurs

when one of them is convolved in the normal way with a periodic summation of the other

function. Circular convolution is only defined for finite length functions (usually equal in

length), continuous or discrete in time. In circular convolution, it is as if the finite length

functions repeat in time, periodically. Because the input functions are now periodic, the

convolved output is also periodic.

are now periodic, the convolved output is also periodic. Circular convolution sum can be calculated using
are now periodic, the convolved output is also periodic. Circular convolution sum can be calculated using

Circular convolution sum can be calculated using the formula:

For

()= 1() 2()=

1() 2( )

= 0,1, . , 1

Circular convolution can be performed in different ways :

1. Using the expression for linear convolution sum, but assuming the signal repeats

periodically. This can be done by changing the negative indices of (n-k) to repetitions

of the latter portions of the original aperiodic signal.

2. Convolution in time domain corresponds to multiplication in frequency domain. To

make use of this property, we can calculate the DTFT of each of the aperiodic signals,

multiply these in the frequency domain, and find the IDFT of the product, to get the

periodic convolved signal in time domain.

2( = {1,2,3,4} ) (0) = 1( ) 2 ( ) (1) = 1( )
2( = {1,2,3,4}
)
(0) =
1( )
2 ( )
(1) =
1( ) 2 (1
)

Let us take the case of two discrete-time aperiodic signals given by:

1( ) = {2,1,2,1} and

Using the formula with N = 4.

For m = 0:

= 14

For m = 1:

= 16

For m = 2:

DSP Laboratory (10ECL57) 5 th Sem KSSEM, Bangalore (2) = 1( ) 2 (2 )
DSP Laboratory (10ECL57)
5 th Sem
KSSEM, Bangalore
(2) =
1(
) 2 (2
)
= 14
For m = 3:
(3) =
1(
) 2 (3
)
= 16
So, we get the circular convolution sum as:
(
) = {14,16,14,16}

MATLAB CODE:

1. Using Convolution Sum Formula:

%% Circular Convolution using Formula

clear all; close all; clc;

x1 = input('Enter Input Sequence for Signal x1(n): ');

n1 = length(x1);

x2 = input('Enter Input Sequence for Signal x2(n): ');

n2=length(x2);

N

= max(n1,n2);

% Length of Convolved Sequence

T

= 1:N;

% Create Time Index

%Zero padding to make sequences of length N

x1=[x1 zeros(1,N-n1)];

x2=[x2 zeros(1,N-n2)];

%Initializing Output sequence of zeros.

y = zeros(1,N);

%Performing Linear Convolution:

for m=1:N

for n=1:N

i=m-n+1;

from 1

if(i<=0)

i=N+i;

%(m-n+1) since we're taking index

end

y(m)=y(m)+x1(n)*x2(i); %Convolution Sum Formula

end

end

% Plot Input and Output Sequences:

subplot(3,1,1);

stem(T,x1);

title('Input Signal x1(n)');

xlabel('n'); ylabel('x1(n)');

subplot(3,1,2);

stem(T,x2);

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

title('Input Signal x2(n)'); xlabel('n'); ylabel('x2(n)');

subplot(3,1,3);

stem(T,y);

title('Convolved Signal y(n) = x1(n)*x2(n)');

xlabel('n'); ylabel('y(n)');

% Display the convolved Sequence in Command Window

disp('Convolved sequence:');

disp(y);

2. Using “ cconv” function.

%% Circular Convolution using CCONV command

clear all; close all; clc;

% Accept input signal sequences

x1 = input('Enter Input Sequence for Signal x1(n): ');

x2 = input('Enter Input Sequence for Signal x2(n): ');

n=max(length(x1),length(x2));

%Perform Linear Convolution using CONV command

y=cconv(x1,x2,n);

%Plot Input and Convolved Signals

subplot(3,1,1);

stem(x1);

title('Input Signal x1(n)');

xlabel('n'); ylabel('x1(n)');

subplot(3,1,2);

stem(x2);

title('Input Signal x2(n)');

xlabel('n'); ylabel('x2(n)');

subplot(3,1,3);

stem(y);

title('Convolved Signal y(n) = x1(n)*x2(n)');

xlabel('n'); ylabel('y(n)');

% Display the convolved Sequence in Command Window

disp('Convolved sequence:');

disp(y);

OUTPUT:

Enter Input Sequence for Signal x1(n): [2 1 2 1]

Enter Input Sequence for Signal x2(n): [1 2 3 4]

Convolved sequence:

14

16

14

16

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

DSP Laboratory (10ECL57) 5 t h Sem KSSEM, Bangalore Dept of ECE Page | 14

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 5

AUTOCORRELATION OF A GIVEN SEQUENCE

Aim: To write the MATLAB code to perform Autocorrelation on a given signal and to verify

its properties.

Theory:

In signal processing, Correlation is a measure of similarity of two waveforms, as a function

of a time-lag applied to one of them. This is also known as a sliding dot product or sliding

inner-product. It is commonly used for searching a long-signal for a shorter, known feature.

Auto-correlation is a special form of Correlation, in which a signal is cross-convolved with

itself. It is a mathematical tool for finding repeating patterns, such as the presence of a

periodic signal which has been buried under noise, or identifying the missing fundamental

frequency in a signal implied by its harmonic frequencies. It is often used in signal processing

Auto-correlation of a signal ( ) is given by the formula: ()= ()( ) In
Auto-correlation of a signal
( ) is given by the formula:
()=
()( )
In case of finite-duration signals, we can write:
|
|
()=
()( )
Where
= ,
= 0
0
and
= 0, =
Assuming our signal is of the form
(
) +
(
)
Energy in the signal is given by:
[ ()+
(
)] =
()+
=
(0)+
(0)+2
This can be written as:
|
( )|
| (0)| =
.
Assume a signal
(
( ) = {4,11,20,30, 20,11,4}

for analyzing functions or series of values, such as time domain signals.

=0,±1,±2,

< 0.

()( )
()( )

( )+2

() 0

That is, autocorrelation sequence of a signal attains its maximum value at zero lag. This is

consistent with the notion that a signal matches perfectly with itself at zero shift.

) = {1,2,3,4}. Its autocorrelation sequence can be calculated as:

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

= ( )
= (
)

Energy of the signal is given by:

= 1 + 2 + 3 + 4

= 30 =
= 30 =

(0)

Hence, it is an energy signal.

We see that the Total energy of the signal is equal to the amplitude of the autocorrelation

signal at the origin.

MATLAB CODE:

% Experiment 5 : Autocorrelation of a Signal.

clear all; close all; clc;

%

Accept user-defined input sequence and define time index

x

= input('Enter a finite-length signal sequence : ');

n

= 0:length(x)-1;

%

Perform Autocorrelation using xcorr function.

rxx = xcorr(x,x);

% Generate Time Index for Autocorrelation sequence, about origin

n2 = -length(x)+1:length(x)-1;

disp('Autocorrelation Sequence : ');

disp(int8(rxx));

% Plot the Original Signal and Autocorrelation Sequence

subplot(2,1,1);

stem(n,x);

title('Input Signal');

xlabel('n'); ylabel('x(n)');

subplot(2,1,2);

stem(n2,rxx);

title('Autocorrelation Sequence');

xlabel('n'); ylabel('rxx(l)');

grid on;

%

Verifying Autocorrelation properties:

E

= sum(x.^2);

% Energy of signal.

mid = ceil(length(rxx)/2);

E0 = rxx(mid);

midpoint

fprintf('Energy of Input Signal : %d\n',E);

fprintf('Amplitude of Midpoint of Autocorrelation Sequence :

%d\n',E0);

% Find index of centre of sequence

% Detect Amplitude of Sequence

% Verify Autocorrelation Property by comparing Energy values

if int8(E0) == int8(E)

disp('Autocorrelation Energy Property is verified');

else

disp('Autocorrelation Energy Property is not verified');

end

%Type conversion for approximation

% Verify that the Signal is even. rxx_r = rxx(mid:length(rxx));

%Right Side of AC Sequence

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

rxx_l = rxx(mid:-1:1);

if rxx_r == rxx_l

%Left Side of AC Sequence

disp('Autocorrelation Sequence is Even. Hence, verified.');

else

disp('Autocorrelation Sequence is not Even. Hence, not

verified.');

end

OUTPUT:

Enter a finite-length signal sequence : [1 2 3 4]

Autocorrelation Sequence :

4

11

20

30

20

11

4

Energy of Input Signal : 30

Amplitude of Midpoint of Autocorrelation Sequence : 30

Autocorrelation Energy Property is verified

Autocorrelation Sequence is Even. Hence, verified.

30 Autocorrelation Energy Property is verified Autocorrelation Sequence is Even. Hence, verified. Dept of ECE Page

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 6

CROSS - CORRELATION OF A GIVEN SEQUENCE

Aim: To write the MATLAB code to perform cross-correlation on a given signal and to verify

its properties.

Theory:

Cross-correlation is a process, in which a signal is convolved with another signal. It is

commonly used for searching a long-signal for a shorter, known feature. It also has

applications in pattern recognition, single particle analysis, electron tomographic averaging,

cryptanalysis, and neurophysiology. Cross-correlation of two signals 1( ) and 2( ) is

()= ()( ) In case of finite-duration signals, we can write: | | ()= ()(
()=
()( )
In case of finite-duration signals, we can write:
|
|
()=
()( )
Where
= ,
= 0
0
and
= 0, =
Assuming our signal is of the form
( ) +
(
)
Energy in the signal is given by:
[ ()+ ( )] =
()+
=
(0)+
(0)+2
This can be written as:
( )
(
0)
( 0) =
.

given by the formula:

=0,±1,±2,

< 0.

()( )
()( )

( )+2

() 0

Note that the shape of the autocorrelation sequence does not change with amplitude scaling

of input signals. Only the amplitude of the autocorrelation sequence changes accordingly.

of the autocorrelation sequence changes accordingly. Cross-correlation satisfies the property: ( ) = ( − )

Cross-correlation satisfies the property:

( ) =

( − )
( − )

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

MATLAB CODE:

% Experiment 6 : Cross-correlation of two Signals.

clear all; close all; clc;

% Accept user-defined input sequences and define time index for it

x1 = input('Enter a finite-length signal sequence X1(n): ');

n1 = 0:length(x1)-1;

x2 = input('Enter a finite-length signal sequence X2(n): ');

n2 = 0:length(x2)-1;

x= max(x1,x2);

% Perform Cross - Correlation using xcorr function.

rxy = xcorr(x1,x2);

% rxy(l)

ryx = xcorr(x2,x1);

% ryx(l)

% Generate Time Index for Cross - Correlation sequence, about origin

n3 = -length(x)+1:length(x)-1;

disp('Cross - Correlation Sequence rxy(l): ');

disp(int8(rxy));

disp('Cross - Correlation Sequence ryx(l): ');

disp(int8(ryx));

% Plot the Original Signal and Cross - Correlation Sequence

subplot(3,1,1);

stem(n1,x1);

title('Input Signal 1');

xlabel('n'); ylabel('x1(n)');

subplot(3,1,2);

stem(n2,x2);

title('Input Signal 2');

xlabel('n'); ylabel('x2(n)');

subplot(3,1,3);

stem(n3,rxy);

title('Cross - Correlation Sequence');

xlabel('n'); ylabel('rxy(l)');

grid on;

% Verifying Cross-correlation properties:

E1 = sum(x1.^2);

E2 = sum(x2.^2);

mid = ceil(length(rxy)/2);

E0 = abs(max(rxy));

fprintf('Energy of Input Signal X1 : %d\n',E1);

fprintf('Energy of Input Signal X2 : %d\n',E2);

fprintf('Max Amplitude of Cross - Correlation Sequence : %d\n',E0);

% Energy of signal 1.

% Energy of signal 2.

% Find index of centre of sequence

% Detect Max Amplitude of Sequence

% Verify Cross - Correlation Property by comparing Energy values

% Max amplitude of Sequence should be less than sqrt(E1*E2).

if int8(E0) <= int8(sqrt(E1*E2))

%Type conversion to 8-bit

int

 

disp('Cross - Correlation Energy Property is verified');

else

 

disp('Cross - Correlation Energy Property is not verified');

end

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

% Verify Signal property : rxy(l)=ryx(-l). if rxy == fliplr(ryx)

disp('Since rxy(l) = ryx(-l), Cross - Correlation property is

verified.');

else

disp('Cross - Correlation property is not verified.');

end

OUTPUT:

Enter a finite-length signal sequence X1(n): [4 3 2 1]

Enter a finite-length signal sequence X2(n): [1 2 3 4]

Cross - Correlation Sequence rxy(l):

16

24

25

20

10

4

1

Cross - Correlation Sequence ryx(l):

1

4

10

20

25

24

16

Energy of Input Signal X1 : 30

Energy of Input Signal X2 : 30

Max Amplitude of Cross - Correlation Sequence : 25

Cross - Correlation Energy Property is verified

Since rxy(l) = ryx(-l), Cross - Correlation property is verified.

Energy Property is verified Since rxy(l) = ryx(-l), Cross - Correlation property is verified. Dept of

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 7

SOLVING A GIVEN DIFFERENCE EQUATION

Aim: To write the MATLAB code to solve a given difference equation, given the co-efficients

and initial values.

Let us consider the difference equation as y (n) 3/2 y (n-1) + ½ y (n-2) = x (n). Given

x(n) = (1/4)

n *u(n). Assume initial conditions as y(-1) = 4, y(-2) = 10.

Theory:

Consider x(n) = (1/4)

n *u(n).

Let n take values from 0 to 5,

n=0:5

n=0, x(0)=1

n=1, x(1)=0.25

n=2, x(2)=0.0625

n=3, x(3)=0.0156

n=4, x(4)=0.0039

n=5, x(5)=0.0010

For n=0;

y(0) - 3/2 y(0-1) + 1/2 y(0-2) = x(0)

Substituting the initial conditions and the value of x(0) in the above equation we get,

y(0) = 1 + 6 - 5 = 2

Similarly,

For n=1; y(1) = 0.25 + 3 - 2 = 1.2500

For n=2; y(2) = 0.0625 + 1.875 -1 = 0.9375

For n=3; y(3) = 0.0156 + 1.40625 - 0.625 = 0.7969

For n=4; y(4) = 0.0039 + 1.19535 - 0.46625 = 0.7365

For n=5; y(5) = 0.0010 + 1.09575 - 0.3982 = 0.6982

MATLAB CODE:

%Experiment 7 : Difference Equation Solving

clear all; close all; clc;

%Accept Difference Equation Coefficients from Input

b

= input('Enter the coefficients of input x(n) : ');

a

= input('Enter the coefficients of output y(n) : ');

y

= input('Enter the initial conditions y(-1), y(-2),

: ');

%Calculate Initial Conditions using filtic

z = filtic(b,a,y);

%Ignore if No Initial Conditions

%Enter Input sequence samples.

x

= [1 1/4 1/16

1/64 1/256

1/1024];

n

= 0:length(x)-1;

%Time Base for plotting

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

%Calculate output using initial conditions

Yout = filter(b,a,x,z);

%Use filter(b,a,x) if no IC

%Display output sequence

disp('Difference Equation Solution : y(n) : ');

disp(Yout);

%Plot Input and Output

subplot(2,1,1);

stem(n,x);

title('Input Sequence x(n)');

xlabel('n'); ylabel('x(n)');

subplot(2,1,2);

stem(n,Yout);

grid on;

title('Output Sequence y(n)');

xlabel('n'); ylabel('y(n)');

OUTPUT:

Enter the coefficients of input x(n) : 1

Enter the coefficients of output y(n) : [1 -3/2 1/2]

Enter the initial conditions y(-1), y(-2),

: [4 10]

Difference Equation Solution : y(n) :

2.0000

0.6982

1.2500

0.9375

0.7969

0.7305

y(-2), : [4 10] Difference Equation Solution : y(n) : 2.0000 0.6982 1.2500 0.9375 0.7969 0.7305

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 8

COMPUTATION OF N- POINT DFT

Aim: Computation of N point DFT of a given sequence and to plot magnitude and phase

spectrum.

Theory:

DFT stands for Discrete Fourier Transform. It is used to find the amplitude and phase

spectrum of a discrete time sequence.

The N-point DFT of a finite-length sequence x(n) of length N, is given by X(k) as

x(n)

N-DFT

sequence x(n) of length N, is given by X(k) as x(n) N-DFT X(k) Basic equation to

X(k)

Basic equation to find the DFT of a sequence is given below.

) =

( )
(
)

For example: Find the DFT of the sequence x(n) = {0,1,2,3}

In this case N=4. For k=0, ( ) = ( 0) + ( 1) +
In this case N=4.
For k=0,
(
)
=
( 0) +
( 1) +
( 2) +
( 3) = 0 + 1 + 2 + 3 = 6
( 0) =
For k=1,
.
(
)
=
(
( 1) =
1)
+
( 1)
+
( 2)
+
(
3)
= - j- 2 + 3j = -2 + j2
Similarly, For k=2, ( ) ( 2) = = 0-1+2-3 = -2
Similarly,
For k=2,
(
)
( 2) =
= 0-1+2-3 = -2

=

( 1) . + ( 1) + ( 2) + ( 3)
( 1)
. + ( 1)
+
( 2)
+
( 3)

For k=3,

X(3) = -2 j2

Hence, X(k) = {6, -2+j2, -2, -2-j2}

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

MATLAB CODE:

%Experiment 8 : N-Point DFT

clear all; close all; clc;

%Accept Input sequence from user

xn = input ('Enter the sequence x(n) : ');

xn=xn';

N = length(xn);

Xk = zeros(N, 1);

%Initialize zero matrix for DFT sequence

%Calculate DFT using formula

n = 0:N-1;

for k = 0:N-1

Xk(k+1) = exp(-j*2*pi*k*n/N)*xn;

end

%Display DFT Sequence

disp('DSP Sequence : X(k) :');

disp(int8(Xk));

%Plot Signals

n = 0:N-1;

%Time base

% Input Sequence

subplot (2,2,[1:2]);

stem(n, xn);

title('Input Sequence x(n)');

xlabel('n');ylabel('x(n)');

% Output Magnitude Plot

subplot (2,2,3);

stem(n, abs(Xk));

grid on;

title('Magnitude Plot of DFT : |X(k)|');

xlabel('n');ylabel('|X(k)|');

% Output Phase Plot

subplot(2,2,4);

stem(n, angle(Xk)');

grid on;

title('Phase Plot of DFT : angle(X(k))');

xlabel('n');ylabel('Angle');

OUTPUT:

Enter the sequence x(n) : [0 1 2 3]

DSP Sequence : X(k) :

6.0000 + 0.0000i

-2.0000 + 2.0000i

-2.0000 - 0.0000i

-2.0000 - 2.0000i

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

DSP Laboratory (10ECL57) 5 t h Sem KSSEM, Bangalore Dept of ECE Page | 25

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 9

LINEAR CONVOLUTION USING DFT AND IDFT

Aim: To calculate the Linear Convolution of two sequences using DFT and IDFT

Theory:

An interesting property of the Discrete Fourier Transforms, is the effect it has on

convolution. Convolution of two signals in the time domain translates to a multiplication of

their Fourier transforms in the frequency domain. In this procedure, we find the discrete

Fourier transforms of the individual signals, multiply them, and apply an Inverse Fourier

Transform upon the product, to get the convolved signal in the time domain.

If x(n) and h(n) are the two sequences of length ‘l’ and ‘m’ respectively. then X(k) and

H(k) their DFT’s of length N=L+M-1.

Y(k)=x(k)h(k)

Therefore the linear convolution of two sequence is the N point IDFT of Y(k).

Ex: Find the linear convolution of x(n)={1,2} and h(n)={1,2,3} using DFT and IDFT method.

Soln: Given,

x(n)={1,2}

h(n)={1,2,3}

N=L+M-1

here L = 2, M = 3

Therefore, N=4

x(n)={1,2,0,0} and h(n)={1,2,3,0}

Finding X(k) using DIT FFT algorithm:

X(k) = {3 , 1-2j , -1 , 1+2j }

Finding H(k) using DIT FFT algorithm

H(k) = {6 , -2-2j , 2 , -2+2j }

Product Y(k) is calculated as :

Y(k) = X(k)H(k)

= { 18 , − 6 + 2j , − 2 , 6 − 2j }

Finding y(n) using DIT FFT algorithm:

y( n ) = { 1 , 4 , 7 , 6 }

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

MATLAB CODE

% Experiment 9 : Linear Convolution using Fourier Transforms

clear all; close all; clc;

%Accept input sequences

x1 = input('Enter Input Sequence for Signal x1(n): ');

n1 = length(x1);

x2 = input('Enter Input Sequence for Signal x2(n): ');

n2=length(x2);

N

= n1+n2-1;

% Length of convolved sequence

T

= 1:N;

%Calculate N-point DFT and IDFT.

y1=fft(x1,N);

% N-point DFT of x1

y2=fft(x2,N);

% N-point DFT of x2

y3=y1.*y2;

% Multiplication in time domain

y=ifft(y3,N);

% N-point IDFT of y to recover result

% Plot Input and Output Sequences:

subplot(3,1,1);

stem(x1);

title('Input Signal x1(n)');

xlabel('n'); ylabel('x1(n)');

subplot(3,1,2);

stem(x2);

title('Input Signal x2(n)');

xlabel('n'); ylabel('x2(n)');

subplot(3,1,3);

stem(y);

title('Convolved Signal y(n) = x1(n)*x2(n)');

xlabel('n'); ylabel('y(n)');

% Display the convolved Sequence in Command Window

disp('Convolved sequence:');

disp(y);

OUTPUT

Enter Input Sequence for Signal x1(n): [1 2]

Enter Input Sequence for Signal x2(n): [1 2 3]

Convolved sequence:

1

4

7

6

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

DSP Laboratory (10ECL57) 5 t h Sem KSSEM, Bangalore Dept of ECE Page | 28

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 10

CIRCULAR CONVOLUTION USING DFT AND IDFT

Aim: To calculate the Circular Convolution of two sequences using DFT and IDFT

Theory:

Convolution in time domain corresponds to multiplication in frequency domain. To make use

of this property, we can calculate the DTFT of each of the aperiodic signals, multiply these in

the frequency domain, and find the IDFT of the product, to get the periodic convolved signal

in time domain.

Example: Find the circular convolution of x(n)={1,2,3,4} and h(n)={4,3,2} using DFT and

IDFT method.

Solution: Given two signals, x(n)={1,2,3,4} and h(n)={4,3,2}

Finding X(k) using DIT FFT algorithm

X(k) = {10 , -2-2j , -2 , -2-2j }

Finding H(k) using DIT FFT algorithm

H(k) = { 9 , 2-3j , 3 , 2+3j }

Y(k) = X(k)H(k)

Y(k) ={ 90 , 2+10j , -6 , 2-10j }

Finding y(n) using DIT FFT algorithm

y( n ) = { 22 , 19 , 20 , 29 }

MATLAB CODE

% Experiment 10 - Circular Convolution using Fourier Transforms

clear all; close all; clc;

%Accept input sequences

x1 = input('Enter Input Sequence for Signal x1(n): ');

n1 = length(x1);

x2 = input('Enter Input Sequence for Signal x2(n): ');

n2=length(x2);

N=max(n1,n2);

% Length of convolved sequence

T = 1:N;

x1=[x1 zeros(1,N-n1)];

x2=[x2 zeros(1,N-n2)];

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

%Calculate N-point DFT and IDFT.

y1=fft(x1,N);

% N-point DFT of x1

y2=fft(x2,N);

% N-point DFT of x2

y3=y1.*y2;

% Multiplication in time domain

y=ifft(y3,N);

% N-point IDFT of y to recover result

% Plot Input and Output Sequences:

subplot(3,1,1);

stem(x1);

title('Input Signal x1(n)');

xlabel('n'); ylabel('x1(n)');

subplot(3,1,2);

stem(x2);

title('Input Signal x2(n)');

xlabel('n'); ylabel('x2(n)');

subplot(3,1,3);

stem(y);

title('Convolved Signal y(n) = x1(n)*x2(n)');

xlabel('n'); ylabel('y(n)'); grid on;

% Display the convolved Sequence in Command Window

disp('Convolved sequence:');

disp(y);

OUTPUT

Enter Input Sequence for Signal x1(n): [1 2 3 4]

Enter Input Sequence for Signal x2(n): [4 3 2]

Convolved sequence:

22

19

20

29

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

DSP Laboratory (10ECL57) 5 t h Sem KSSEM, Bangalore Dept of ECE Page | 31

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 11

DESIGN AND IMPLEMENTATION OF FIR FILTER

Aim: To design and implement a FIR Filter for the given specifications.

Theory:

A linear-phase is required throughout the passband of the filter to preserve the shape of the

given signal in the passband. A causal IIR filter cannot give linear-phase characteristics and

only special types of FIR filters that exhibit center symmetry in its impulse response give the

linear-space. An FIR filter with impulse response h(n) can be obtained as follows:

h(n) = h (n) 0≤n≤N-1

d

= 0 otherwise ……………….(a)

The impulse response h (n) is truncated at n = 0, since we are interested in causal FIR Filter. It

is possible to write above equation alternatively as

d

h(n) = h (n)w(n) ……………….(b)

d

where w(n) is said to be a rectangular window defined by

w(n) = 1 0≤n≤N-1

= 0 otherwise

Taking DTFT on both the sides of equation(b), we get

H(ω) = H (ω)*W(ω)

d

Hamming window:

equation(b), we get H(ω) = H (ω)*W(ω) d Hamming window : ( 2п ≤ − 1
equation(b), we get H(ω) = H (ω)*W(ω) d Hamming window : ( 2п ≤ − 1

( 2п

≤

− 1

0 ≤
0 ≤

The impulse response of an N-term Hamming window is defined as follows:

/ (

− 1 ) )

0. 54 – 0. 46

0

) =

Problem: Using MATLAB design an IIR filter to meet the following specifications choosing

Hamming window:

Window length, N = 27

Stop band attenuation = 50dB

Cut-off frequency = 100 Hz

Sampling frequency = 1000 Hz

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

MATLAB CODE

% Experiment 11 : Designing a FIR Filter (Hamming Window)

close all; clear all; clc;

%

Accept Filter Parameters from User

N

= input('Enter the window length N : ');

fc = input('Enter the cut-off frequency fc (Hz) : ');

Fs = input('Enter the sampling frequency Fs (Hz) : ');

Wc = 2*fc/ Fs;

Wh = hamming(N);

window

%Nyquist Frequency

%Create a N-point symmetric Hamming

%

Generate a FIR filter based on Hamming Window created

b

= fir1(N-1, Wc ,Wh);

%

Calculate Frequency Response of Filter designed.

%

h - Frequency Response values

w = Frequencies

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

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

%Magnitude of Response

% Display Values

disp('Hamming Window Co-efficients : ');

disp(Wh);

disp('Unit Sample Response of FIR Filter h(n) : ');

disp(b);

% Plot Frequency response of Butterworth Filter.

freqz(b);

title('Hamming Filter Frequency Response');

OUTPUT

Enter the window length N : 27

Enter the cut-off frequency fc (Hz) : 100

Enter the sampling frequency Fs (Hz) : 1000

Hamming Window Co-efficients :

0.0800

0.0934

0.1327

0.1957

0.2787

0.3769

0.4846

0.5954

0.7031

0.8013

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

0.8843

0.9473

0.9866

1.0000

0.9866

0.9473

0.8843

0.8013

0.7031

0.5954

0.4846

0.3769

0.2787

0.1957

0.1327

0.0934

0.0800

Unit Sample Response of FIR Filter h(n) :

Columns 1 through 7

0.0019

0.0023

0.0022

-0.0000

-0.0058

-0.0142

-0.0209

Columns 8 through 14

 

-0.0185

0.0000

0.0374

0.0890

0.1429

0.1840

0.1994

Columns 15 through 21

 

0.1840

0.1429

0.0890

0.0374

0.0000

-0.0185

-0.0209

Columns 22 through 27

 

-0.0142

-0.0058

-0.0000

0.0022

0.0023

0.0019

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

DSP Laboratory (10ECL57) 5 t h Sem KSSEM, Bangalore Dept of ECE Page | 35

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROGRAM 12

DESIGN AND IMPLEMENTATION OF IIR FILTER

Aim: To design and implement a IIR Filter for the given specifications.

Theory:

A desired frequency response is approximated by a transfer function expressed as a ratio of

polynomials. This type of transfer function yields an impulse response of infinite duration.

Therefore, the analog filters are commonly referred to as infinite impulse response (IIR)

filters.

The main classes of analog filters are -

1.Butterworth Filter.

2.Chebyshev Filter.

These filters differ in the nature of their magnitude responses as well as in their design and

implementation.

BUTTERWORTH FILTERS:

Butterworth filters have very smooth passband, which we pay for with a relatively wide

transition region. A Butterworth filter is characterized by its magnitude frequency response,

where N is the order of the filter and Ωc is defined as the cutoff frequency where the filter

magnitude is 1/√2 times the dc gain (Ω=0)

is defined as the cutoff frequency where the filter magnitude is 1/ √2 times the dc

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

Butterworth filter tables N=1; (s + 1)

N=2; (s 2 +0.5 s +1)

N=3; (s 2 +s+1)(s+1)

N=4; (s 2 +0.76536s+1)(s +1.864776s+2)

2

N=5; (s+1)( s +0.6180s+1)( s +1.6180s+1)

2

2

CHEBYSHEV FILTERS:

Chebyshev filters are equiripple in either the passband or stopband. Hence the magnitude

response oscillates between the permitted minimum and maximum values in the band a

number of times depending upon the order of filters. There are two types of chebyshev filters.

The chebyshev I filter is equiripple in passband and monotonic in the stopband, whereas

Chebyshev II is just the opposite.

The Chebyshev low-pass filter has a magnitude response given by

Chebyshev II is just the opposite. The Chebyshev low-pass filter has a magnitude response given by

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PROBLEM 1: BUTTERWORTH FILTER:

Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band

edge at 2000Hz for a sampling frequency of 8000Hz, variation of gain within pass band 1db

and stopband attenuation of 15 db. Use Butterworth prototype design and Bilinear

Transformation.

MATLAB CODE :

% Experiment 12 : Design of IIR Filter (Butterworth Filter)

clear all; close all; clc;

% Accept Input Parameters from user

Rp = input('Enter Passband Attenuation in dB : ');

Rs = input('Enter Stopband Attenuation in dB : ');

fp = input('Enter Passband Frequency in Hz : ');

fs = input('Enter Stopband Frequency in Hz : ');

Fs = input('Enter Sampling Frequency in Hz : ');

% Calculate Sampled Frequency values

Wp=2* fp / Fs ;

Ws=2* fs / Fs ;

% Calculate Butterworth filter order and cutoff frequency:

% N = Minimum order of Filter

Wn = Cutoff Frequencies

[N,Wn] = buttord(Wp,Ws,Rp,Rs);

% Butterworth Filter Design (z = zeros

[z,p] = butter(N,Wn);

p = poles)

% Display Filter parameters :

disp('Order of Butterworth Filter : ');

disp(N);

disp('Butterworth Window Cutoff Frequency : ');

disp(Wn);

% Plot Frequency Response of Filter

freqz(z,p);

title('Butterworth frequency response');

OUTPUT:

Enter Passband Attenuation in dB : 1

Enter Stopband Attenuation in dB : 15

Enter Passband Frequency in Hz : 1500

Enter Stopband Frequency in Hz : 2000

Enter Sampling Frequency in Hz : 8000

Order of Butterworth Filter :

6

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

Butterworth Window Co-efficient :

0.4104

KSSEM, Bangalore Butterworth Window Co-efficient : 0.4104 PROBLEM 2: CHEBYSHEV FILTER: Using MATLAB design an IIR

PROBLEM 2: CHEBYSHEV FILTER:

Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band

edge at 2000Hz for a sampling frequency of 8000Hz, variation of gain within pass band 1 db

and stopband attenuation of 15 db. Use Chebyshev prototype design and Bilinear

Transformation.

DESIGN:

W1 = (2*pi* F1 )/ Fs = 2*pi*100)/4000 = 0.05Π rad

W2 = (2*pi* F2 )/ Fs = 2*pi*500)/4000 =0.25Π rad

Prewarp:

T=1sec

Ω1 = 2/T tan (w1/2)

= 0.157 rad/sec

Ω2 = 2/T tan (w2/2)

= 0.828 rad/sec

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

Order:

(10ECL57) 5 t h Sem KSSEM, Bangalore Order: 10 έ = έ = 0.765 A= 10

10

έ =

έ = 0.765

A= 10 -As/20 , A = 10 20/20 , A=10

− 1

g= (A2 - 1) / έ , g = 13.01 Ωr= Ω2 / Ω1 Ωr=0.828/0.157
g= (A2 - 1) / έ , g = 13.01
Ωr= Ω2 / Ω1 Ωr=0.828/0.157 = 5.27 rad\sec
n = log
+
(
)
/ log
+
10
10
r

n= 1.388

Therefore n= 2.

Cut-off Frequency:

( –
(

) }

Ωc = Ωp = Ω1 = 0.157 rad\sec

Normalized Transfer Function:

H(s)=[bo / 1+ έ 2 ] / [ s 2 +b 1 s+b 0 ]

2

= 0.505/[ s +0.8s+0.036]

Denormalized Transfer Function:

H(s)= Hn(s) | s-s/Ωc H(s)= Hn(s) | s-s/0.157

2

H(s) = 0.0125 / [s +0.125s+0.057]

Apply BLT:

H(Z) = H(s)|

s=(2/T)[(1-z-1)/(1+z-1)]

H(Z) = 0.0125+0.025Z

-1

+ 0.0125 Z

4.2769-7.96Z -1 + 3.76Z-2

-2

H(Z) = 0.0029+0.0052Z

-1

+ 0.0029 Z

1-1.86Z -1 + 0.88Z -2

-2

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

MATLAB CODE:

% Experiment 12B : Design of IIR Filter (Chebyshev Filter)

clear all; close all; clc;

% Accept Input Parameters from user

Rp = input('Enter Passband Attenuation in dB : ');

Rs = input('Enter Stopband Attenuation in dB : ');

fp = input('Enter Passband Frequency in Hz : ');

fs = input('Enter Stopband Frequency in Hz : ');

Fs = input('Enter Sampling Frequency in Hz : ');

% Calculate Sampled Frequency values

Wp=2* fp / Fs ;

Ws=2* fs / Fs ;

% Calculate Chebyshev filter order and cutoff Frequency:

% N = Minimum order of Filter

Wn = Cutoff Frequencies

[N,Wn]=cheb1ord(Wp,Ws,Rp,Rs);

% Chebyshev Filter Design (z = zeros

[z,p]=cheby1(N,Rp,Wn);

p = poles)

% Display Filter parameters :

disp('Order of Chebyshev Filter : ');

disp(N);

disp('Chebyshev Window Cutoff Frequency : ');

disp(Wn);

% Plot Frequency Response of Filter :

freqz(z,p);

title('Chebyshev Frequency response');

OUTPUT:

Enter Passband Attenuation in dB : 1

Enter Stopband Attenuation in dB : 15

Enter Passband Frequency in Hz : 1500

Enter Stopband Frequency in Hz : 2000

Enter Sampling Frequency in Hz : 8000

Order of Chebyshev Filter :

4

Chebyshev Window Cutoff Frequency :

0.3750

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

DSP Laboratory (10ECL57) 5 t h Sem KSSEM, Bangalore Dept of ECE Page | 42

DSP Laboratory (10ECL57)

5 th Sem

KSSEM, Bangalore

PART B:

Exercises using the

DSP Kit

DSP Laboratory (10ECL57)

V Semester

KSSEM, Bangalore

Package content:

TMS320C6748 DSP BOARD

KSSEM, Bangalore Package content: TMS320C6748 DSP BOARD The C6748 DSP Experimenter Kit packaged for Universities

The C6748 DSP Experimenter Kit packaged for Universities (TMDSEXPL138-UNV)

provides everything academics need to get started with teaching and projects using the TI

TMS320C6000 DSP. The TI TMS320C6000 family of DSPs is popular for use in Real-time DSP

coursesThe Experimenter Kit for Universities is a low-cost, flexible development platform for the

OMAP-L138 which is a low-power dual core processor based on C6748 DSP plus an ARM926EJ-S

32-bit RISC MPU.

The C6748 DSP kit has a TMS320C6748 DSP onboard that allows full-speed verification of

code with Code Composer Studio. The C6748 DSP kit provides:

A USB Interface

128MB DDRAM and ROM

An analog interface circuit for Data conversion

(AIC) An I/O port

Embedded JTAG emulation support

Connectors on the C6748 DSP kit provide DSP external memory interface (EMIF) and peripheral signals that enable its functionality to be expanded with custom or third party daughter boards.

DSP Laboratory (10ECL57)

V Semester

KSSEM, Bangalore

The C6748 DSP kit includes a stereo codec. This analog interface circuit (AIC) has the following characteristics:

High-Performance Stereo Codec

Interfaces directly to digital or analog microphones

Supports 8-96 ksps sampling rates

• High SNR (100-102dB DAC, 92dB ADC)

Integrated PLL supporting a wide range of audio clocks

Low-power headphone, speaker and playback modes for portable systems

Programmable digital audio effectsinclude 3D sound, bass, treble, EQ and de-emphasis

Software

Control

Via

TI

Interface to TI McASPs.

McASP-Compatible

Multiprotocol

Serial

Port.Glueless

Audio-Data Input/Output Via TI McASP-Compatible Programmable Audio Interface

16/20/24/32-Bit Word Lengths.

The C6748DSP kit has the following features:

The 6748 DSP KIT kit is a low-cost standalone development platform that enables customers

to evaluate and develop applications for the TI C67XX DSP family. The DSP KIT also serves

as a hardware reference design for the TMS320C6748 DSP. Schematics, logic equations and

application notes are available to ease hardware development and reduce time to market.

An on-board AIC3106 codec allows the DSP to transmit and receive analog signals.

McASP is used for the codec control interface and for data. Analog audio I/O is done through

two 3.5mm audio jacks that correspond to line input, and line. The analog output is driven to

the line out .McASP1 can be re-routed to the expansion connectors in software.

The DSP KIT includes 2 LEDs and 8 DIP switches as a simple way to provide the user with

interactive feedback.

On-board voltage

regulators provide the 1.26V DSP core voltage, 3.3V digital and 3.3V analog voltages. A

voltage supervisor monitors the internally generated voltage, and will hold the board in reset

until the supplies are within operating specifications and the reset button is released.

An included 5V external power supply is used to power the board.

Code Composer communicates with the DSP KIT through an embedded JTAG emulator with a

USB host interface. The DSP KIT can also be used with an external emulator through the

external JTAG connector.

TMS320C6748 DSP Features

Highest-Performance Floating-Point Digital Signal Processor (DSP):

Eight 32-Bit Instructions/Cycle

DSP Laboratory (10ECL57)

V Semester

KSSEM, Bangalore

32/64-Bit Data Word

375/456-MHz C674x Fixed/Floating-Point

Up to 3648/2746 C674x MIPS/MFLOPS

Rich Peripheral Set, Optimized for Audio

Highly Optimized C/C++ Compiler

Extended Temperature Devices Available

Advanced Very Long Instruction Word (VLIW) TMS320C67x™ DSP Core

Eight Independent Functional Units:

Two ALUs (Fixed-Point)

Four ALUs (Floating- and Fixed-Point)

Two Multipliers (Floating- and Fixed-Point)

Load-Store Architecture With 64 32-Bit General-Purpose Registers

Instruction Packing Reduces Code Size

All Instructions Conditional

Instruction Set Features

Native Instructions for IEEE 754

Single- and Double-Precision

Byte-Addressable (8-, 16-, 32-Bit Data)

8-Bit Overflow Protection

Saturation; Bit-Field Extract, Set, Clear; Bit-Counting; Normalization

67x cache memory.

256K-Byte L2 unified Memory RAM\Cache.

Real-Time Clock With 32 KHz Oscillator and Separate Power Rail.

Three 64-Bit General-Purpose Timers

32K-Byte L1P Program Cache (Direct-Mapped)

32K-Byte L1D Data Cache (2-Way)

Integrated Digital Audio Interface Transmitter (DIT) Supports:

S/PDIF, IEC60958-1, AES-3, CP-430 Formats

Up to 16 transmit pins

Enhanced Channel Status/User Data

Two Inter-Integrated Circuit Bus (I

Extensive Error Checking and Recovery

2

3 64-Bit General-Purpose Timers (each configurable as 2 32-bit timers)

Flexible Phase-Locked-Loop (PLL) Based Clock Generator Module

C Bus™) .

(PLL) Based Clock Generator Module C B us™) . IEEE-1149.1 (JTAG ) Boundary-Scan-Compatible 3.3-V I/Os, 1.2

IEEE-1149.1 (JTAG ) Boundary-Scan-Compatible

3.3-V I/Os, 1.2

3.3-V I/Os, 1.4-V Internal (GDP)(300 MHz only)

LCD Controller

Two Serial Peripheral Interfaces (SPI) Each With Multiple Chip-Selects

Two Multimedia Card (MMC)/Secure Digital (SD) Card Interface with Secure Data I/O

-V Internal (GDP & PYP)

(SDIO) Interfaces

One Multichannel Audio Serial Port.

Two Multichannel Buffered Serial Ports

DSP Laboratory (10ECL57)

V Semester

KSSEM, Bangalore

General Procedure to work on Code Composer Studio V4 for non-real time projects

1. Launch ccs

Launch the CCS v4 icon from the Desktop or goto All Programs ->Texas Instruments -

>CCSv4

or goto All Programs ->Texas Instruments - >CCSv4 2 . Choose the location for the workspace,

2.

Choose the location for the workspace, where your project will be saved.

for the workspace, where your project will be saved. 3 . Click the CCS icon from

3.

Click the CCS icon from the welcome page to go the workbench, it is marked in the below

picture.

. Click the CCS icon from the welcome page to go the workbench, it is marked

4. Configure ccs to your target

A. From the Target menu select New target Configuration

Target -> New target Configuration.

It will open a window like given below.

Specify any arbitrary target name. For Eg., 6748config.ccxml (Extension should be

.ccxml)

Click Finish then you will get configuration window for the created target.

you will get configuration window for the created target . B. 1. Select the C onnection

B.

1.

Select the Connection: Texas instruments XDS100v1 USB Emulator

2.

Select the Device: TMS320C6748. To make search easier type 6748 in device block.

*
*

Check the box

TMS320C674

8 and finally

Click Save.

C. Next goto Advanced tab give the suitable Gel file path as shown below.

Advanced tab give the suitable Gel file path as shown below. Follow the path. “C :\6748support\c6748.ge

Follow the path.

“C:\6748support\c6748.gel”

D.

Go to view option and select the Target Configuration:

View->Target Configuration.

A wizard will open in the workspace expand the User Defined folder and you can find your

target, Right click on 6748config.ccxml and select the Launch Selected Configuration.

and select the Launch Selected Configuration. E . Connect CCS to the target Goto Target ->

E. Connect CCS to the target

Goto Target -> Connect Target

Connect CCS to the target Goto Target -> Connect Target Now our target is successfully configured

Now our target is successfully configured and connected.

In future we no need to repeat these steps. If we are working with the same hardware we

can just open the already configured target and launch the selected configuration and

connect it.

5. Creating the New Project

Step P1:

Change the Perspective Debug to C/C++ from the right corner of the CCS

Step P2:

Go to File New CCS Project.

corner of the CCS Step P2: Go to File New CCS Project. Step P3: Specify the

Step P3:

Specify the name of the project in the

space provided .and Click Next

Eg., Project Name: Hello World

the name of the project in the space provided .and Click Next Eg., Project Name: Hello
the name of the project in the space provided .and Click Next Eg., Project Name: Hello
Select the project type Project Type: C6000 Click Next *However our target is based on

Select the project type

Project Type: C6000

Click Next

Select the project type Project Type: C6000 Click Next *However our target is based on C6000

*However our target is based on C6000 family, Based on the family we need to select the

Project

Type.

Based on the family we need to select the Project Type. Set the project settings window

Set the project settings window as shown below.

we need to select the Project Type. Set the project settings window as shown below. Click

Click finish

6. To write the program select one new file.

A.Go to File New Source File.

select one new file. A. Go to File New Source File. B. Specify the arbitrary source

B. Specify the arbitrary source file name. It should be in the source folder (current project

name.).

It should be in the source folder (current project name.). Note: Extension of the source file

Note:

Extension of the source file must be the language what we preferred to write the code.

Eg: