Professional Documents
Culture Documents
n
m
m n x m h
0
) ( ) (
Clearly, y (n) is a finite duration sequence of duration (n1+n2 -1) samples.
The convolution sum of two sequences can be found by using following steps
Step1: Choose an initial value of n, the starting time for evaluating the output
sequence y (n). If x (n) starts at n=n
1
and h (n) starts at n= n
2
then n = n
1
+ n
2
-1 is a
good choice.
Step2: Express both sequences in terms of the index m.
Step3: Fold h (m) about m=0 to obtain h (-m) and shift by n to the right if n is positive
and left if n is negative to obtain h (n-m).
Step4: Multiply two sequences x (n-m) and h (m) element by element and sum the
products to get y (n).
Step5: Increment the index n, shift the sequence x (n-m) to right by one sample and
repeat step4.
Step6: Repeat step5 until the sum of products is zero for all remaining values of n.
Program:
%Linear convolution of two sequences
a=input('enter the input sequence1=');
b=input('enter the input sequence2=');
n
1
=length (a)
n
2
=length (b)
x=0:1:n1-1;
Subplot (2, 2, 1), stem(x, a);
title ('INPUT SEQUENCE1');
xlabel ('---->n');
ylabel ('---->a (n)');
y=0:1:n2-1;
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 33
subplot (2, 2, 2), stem(y, b);
title ('INPUT SEQUENCE2');
xlabel ('---->n');
ylabel('---->b(n)');
c=conv (a, b)
n
3
=0:1:n1+n2-2;
subplot (2, 1, 2), stem (n3, c);
title ('CONVOLUTION OF TWO SEQUENCES');
xlabel ('---->n');
ylabel ('---->c (n)');
Output:
Enter the input sequence1= [2 3 4]
Enter the input sequence2= [1 2 3]
c = 2 7 16 17 12
Enter the input sequence1= [2 3 4]
Enter the input sequence2= [1 2 3]
n
1
= 3
n
2
=3
c = 2 7 16 17 12
Result: Linear convolution of two discrete sequences is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 34
Inference: The length of the Linear convolved sequence is n
1
+n
2
-1 where n
1
and
n
2
are lengths of sequences.
Questions & Answers
1. What do you understand by Linear Convolution.
a. The convolution of discrete time signals is known as discrete convolution. Let x
(n) be the input to an LTI system and y (n) be the output of the system. Let h (n) be
the response of the system to an impulse. The output y (n) can be obtained by
convolving the impulse response h (n) and the input signal x (n)
Y (n) =
m
m n x m h ) ( ) ( the above equation that gives the response y (n)
of an LTI system as a function of the input signal x (n) and the impulse response h
(n) is called a convolution sum.
2. What are the properties of convolution.
a. 1. Commutative property x (n) * h (n) = h (n) * x (n)
2. Associative property [x (n) * h
1
(n)] * h
2
(n) = x (n) * [h
1
(n) * h
2
(n)]
3. Distributive property X (n) * [h
1
(n) + h
2
(n)] = x (n) * h
1
(n) + x (n) * h
2
(n)].
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 35
3. TO VERIFY CIRCULAR CONVOLUTION
Aim: To compute the circular convolution of two discrete sequences.
Theory: Two real N-periodic sequences x(n) and h(n) and their circular or periodic
convolution sequence y(n) is also an N- periodic and given by,
=
=
1
0
)) (( ) ( ) (
N
m
N
m n x m h n y , for n=0 to N-1.
Circular convolution is some thing different from ordinary linear convolution
operation, as this involves the index ((n-m))N, which stands for a modula-N
operation. Basically both type of convolution involve same six steps. But the
difference between the two types of convolution is that in circular convolution the
folding and shifting (rotating) operations are performed in a circular fassion by
computing the index of one of the sequences with modulo-N operation. Either one of
the two sequences may be folded and rotated without changing the result of circular
convolution. That is,
=
=
1
0
)) (( ) ( ) (
N
m
N
m n h m x n y , for n=0 to (N-1).
If x (n) contain L no of samples and h (n) has M no of samples and that L > M, then
perform circular convolution between the two using N=max (L,M), by adding (L-M) no
of zero samples to the sequence h (n), so that both sequences are periodic with
number.
Two sequences x (n) and h (n), the circular convolution of these two sequences
can be found by using the following steps.
1. Graph N samples of h (n) as equally spaced points around an outer circle in
counterclockwise direction.
2. Start at the same point as h (n) graph N samples of x (n) as equally spaced
points around an inner circle in clock wise direction.
3. Multiply corresponding samples on the two circles and sum the products to
produce output.
4. Rotate the inner circle one sample at a time in counter clock wise direction
and go to step 3 to obtain the next value of output.
5. Repeat step No.4 until the inner circle first sample lines up with first sample of
the exterior circle once again.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 36
Program:
%circular convolution
a=input('enter the input sequence1=');
b=input('enter the input sequence2=');
n
1
=length (a)
n
2
=length (b)
n
3
=n
1
-n
2
N=max (n
1
, n2);
if (n
3
>0)
b= [b, zeros (1, n1-n
2
)]
n
2
=length (b);
else
a= [a, zeros (1, N-n
1
)]
n
1
=length (a);
end;
k=max (n
1
, n2);
a=a';
b=b';
c=b;
for i=1: k-1
b=circshift (b, 1);
c=[c, b];
end;
disp(c);
z=c*a;
disp ('z=')
disp (z)
subplot (2, 2, 1);
stem (a,'filled');
title ('INPUT SEQUENCE1');
xlabel ('---->n');
ylabel ('---->Amplitude')
subplot (2, 2, 2);
stem (b,'filled');
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 37
title ('INPUT SEQUENCE2');
xlabel ('---->n');
ylabel ('---->Amplitude');
subplot (2, 1, 2);
stem (z,'filled');
title ('CONVOLUTION OF TWO SEQUENCES');
xlabel ('---->n');
ylabel ('---->Amplitude');
Output:
Enter the input sequence1= [2 3 4 5]
Enter the input sequence2= [1 1 0]
n
1
=4
n
2
=3
n
3
=1
b =
1 1 0 0
1 0 0 1
1 1 0 0
0 1 1 0
0 0 1 1
z=
7
5
7
9
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 38
Result: Circular convolution of two discrete sequences is computed.
Inference: The length of the circularly convolved sequence is max (n
1
, n2) where
n
1
and n
2
are the lengths of given sequences.
Questions & Answers
1. Define circular convolution?
a. Let x
1
(n) and x
2
(n) are finite duration sequences both of length N with DFTs X
1
(k)
and x
2
(k).if X
3
(k)=X
1
(k)X
2
(k), then the sequence x
3
(n) can obtained by circular
convolution, defined as x
3
(n)=
N
N
m
m n x m x )) (( ) (
2
1
0
1
=
.
2. What do you understand by periodic convolution?
a. Let x1p (n) and x
2
p (n) with a period of N samples so that x
p
(n) =x
p
(n+lN); Then
discrete Fourier series of the sequence x
p
(n) is defined as X
p
(k)
=
=
1
0
/ 2
) (
N
n
N kn j
p
e n x
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 39
4. DESIGN FIR FILTER (LP/HP) USING WINDOWING
TECHNIQUE
a) USING RECTANGULAR WINDOW
Aim: To design FIR high pass filter using rectangular window.
Theory: The design frequency response H
d
(e
jw
) of a filter is periodic in frequency
and can be expanded in a Fourier series. The resultant series is given by
H
d
(e
jw
) =
n
jwn
d
e n h ) (
Where
H
d
(n) =
d e e H
n j j
) ( 2 / 1
and known as fourier coefficients having infinite length. One possible way of
obtaining FIR filter is to truncate the infinite fourier series at n = +/- [N-1/2], Where N
is the length of the desired sequence. But abrupt truncation of the Fourier series
results in oscillation in the passband and stopband. These oscillations are due to
slow convergence of the fourier series and this effect is known as the Gibbs
phenomenon. To reduce these oscillations, the Fourier coefficients of the filter are
modified by multiplying the infinite impulse response with a finite weighing sequence
(n) called a window.
where
(n) = (-n) 0 for |n| [ (N-1/2]/2]
=0 for |n|> (N-1/2]/2]
After multiplying window sequence (n) with h
d
(n), we get a finite duration
sequence h (n) that satisfies the desired magnitude response.
h (n) = h
d
(n) (n) for all |n| [N-1/2]
=0 for |n|> [N-1/2]
The frequency response H (e
jw
) so the filter can be obtained by convolution of H
d
(e
JW
)
and W (e
jw
) given by
H(e
jw
) = 1/
d e W e H
j j
d
) (
( ) ( 2
H
d
(e
jw
) * W (e
jw
)
Because both H
d
(e
jw
) and W (e
jw
) are periodic function, the operation often called as
periodic convolution.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 40
The rectangular window sequence is given by
WR (n) = 1 for (N-1/2 n (n-1)/2
= 0 otherwise
Program:
%Design of high pass filter using rectangular window
WC=0.5*pi;
N=25;
b=fir1 (N-1, wc/pi,'high', rectwin (N));
disp ('b=');
disp (b)
w=0:0.01: pi;
h=freqz (b, 1, w);
plot (w/pi, abs (h));
xlabel ('Normalised Frequency');
ylabel ('Gain in dB')
title ('FREQUENCY RESPONSE OF HIGHPASS FILTER USING
RECTANGULAR WINDOW');
Output:
b= Columns 1 through 17
-0.0000 0.0297 -0.0000 -0.0363 -0.0000 0.0467 -0.0000 -0.0654 -
0.0000 0.1090 -0.0000 -0.3269 0.5135 -0.3269 -0.0000 0.1090 -
0.0000
Columns 18 through 25
-0.0654 -0.0000 0.0467 -0.0000 -0.0363 -0.0000 0.0297 -0.0000
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 41
Result: FIR high pass filter is designed by using rectangular window.
Inference: Magnitude response of FIR high pass filter designed using
Rectangular window as significant sidelobes.
Questions & Answers
1. What are "FIR filters"?
a. FIR filters are one of two primary types of digital filters used in Digital Signal
Processing (DSP) applications (the other type being IIR).
2. What does "FIR" mean?
a. FIR" means "Finite Impulse Response".
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 42
3. Why is the impulse response "finite"?
a. The impulse response is "finite" because there is no feedback in the filter; if you
put in an impulse (that is, a single "1" sample followed by many "0" samples),
zeroes will eventually come out after the "1" sample has made its way in the delay
line past all the coefficients.
4. How do you pronounce "FIR"?
a. Some people say the letters F-I-R; other people pronounce as if it were a type of
tree. We prefer the tree. (The difference is whether you talk about an F-I-R filter or
a FIR filter.)
5. What is the alternative to FIR filters?
a. DSP filters can also be "Infinite Impulse Response" (IIR). IIR filters use feedback,
so when you input an impulse the output theoretically rings indefinitely.
6. How do FIR filters compare to IIR filters?
a. Each has advantages and disadvantages. Overall, though, the advantages of FIR
filters outweigh the disadvantages, so they are used much more than IIRs.
7. What are the advantages of FIR Filters (compared to IIR filters)?
a. Compared to IIR filters, FIR filters offer the following advantages:
They can easily be designed to be "linear phase" (and usually are).
Put simply, linear-phase filters delay the input signal, but dont distort
its phase.
They are simple to implement. On most DSP microprocessors, the
FIR calculation can be done by looping a single instruction.
They are suited to multi-rate applications. By multi-rate, we mean
either "decimation" (reducing the sampling rate), "interpolation"
(increasing the sampling rate), or both. Whether decimating or
interpolating, the use of FIR filters allows some of the calculations to
be omitted, thus providing an important computational efficiency.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 43
In contrast, if IIR filters are used, each output must be individually
calculated, even if it that output will discarded (so the feedback will be
incorporated into the filter).
They have desirable numeric properties. In practice, all DSP filters
must be implemented using "finite-precision" arithmetic, that is, a
limited number of bits. The use of finite-precision arithmetic in IIR
filters can cause significant problems due to the use of feedback, but
FIR filters have no feedback, so they can usually be implemented
using fewer bits, and the designer has fewer practical problems to
solve related to non-ideal arithmetic.
They can be implemented using fractional arithmetic. Unlike IIR filters,
it is always possible to implement a FIR filter using coefficients with
magnitude of less than 1.0. (The overall gain of the FIR filter can be
adjusted at its output, if desired.) This is an important consideration
when using fixed-point DSP's, because it makes the implementation
much simpler.
8. What are the disadvantages of FIR Filters (compared to IIR filters)?
a. Compared to IIR filters, FIR filters sometimes have the disadvantage that they
require more memory and/or calculation to achieve a given filter response
characteristic. Also, certain responses are not practical to implement with FIR
filters.
9. What terms are used in describing FIR filters?
Impulse Response - The "impulse response" of a FIR filter is actually
just the set of FIR coefficients. (If you put an "impulse" into a FIR filter
which consists of a "1" sample followed by many "0" samples, the
output of the filter will be the set of coefficients, as the 1 sample
moves past each coefficient in turn to form the output.)
Tap - A FIR "tap" is simply a coefficient/delay pair. The number of FIR
taps, (often designated as "N") is an indication of 1) the amount of
memory required to implement the filter, 2) the number of calculations
required, and 3) the amount of "filtering" the filter can do; in effect,
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 44
more taps means more stopband attenuation, less ripple, narrower
filters, etc.)
Multiply-Accumulate (MAC) - In a FIR context, a "MAC" is the
operation of multiplying a coefficient by the corresponding delayed
data sample and accumulating the result. FIRs usually require one
MAC per tap. Most DSP microprocessors implement the MAC
operation in a single instruction cycle.
Transition Band - The band of frequencies between passband and
stopband edges. The narrower the transition band, the more taps are
required to implement the filter. (A "small" transition band results in a
"sharp" filter.)
Delay Line - The set of memory elements that implement the "Z^-1"
delay elements of the FIR calculation.
Circular Buffer - A special buffer which is "circular" because
incrementing at the end causes it to wrap around to the beginning, or
because decrementing from the beginning causes it to wrap around to
the end. Circular buffers are often provided by DSP microprocessors
to implement the "movement" of the samples through the FIR delay-
line without having to literally move the data in memory. When a new
sample is added to the buffer, it automatically replaces the oldest one.
b) USING KAISER WINDOW
Aim: To design FIR low pass filter using Kaiser Window for different values of
Beeta and verify its characteristics.
Theory: The Kaiser window is given by
W
k
(n) = I
o
[ ) ( / ) ) 1 / 2 ( 1 (
0
2
I N n ] for |n| N-1/2
=0 otherwise
Where is an independent parameter.
I
o
(x) is the zeroth order Bessel function of the first kind
I
0
(x) = 1+
2 k
1
] (x/2) ! / 1 [
= k
k
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 45
Advantages of Kaiser Window
1. It provides flexibility for the designer to select the side lobe level and N.
2. It has the attractive property that the side lobe level can be varied
continuously from the low value in the Blackman window to the high value
in the rectangular window.
Program:
%Design of FIR lowpass filter using Kaiser Window
WC=0.5*pi;
N=25;
b=fir1 (N, wc/pi, kaiser (N+1, 0.5))
w=0:0.01: pi;
h=freqz (b, 1, w);
plot (w/pi, 20*log10 (abs (h)));
hold on
b=fir1 (N, wc/pi, kaiser (N+1, 3.5))
w=0:0.01: pi;
h=freqz (b, 1, w);
plot (w/pi, 20*log10 (abs (h)));
hold on
b=fir1 (N, wc/pi, kaiser (N+1, 8.5))
w=0:0.01: pi;
h=freqz (b, 1, w);
plot (w/pi, 20*log10 (abs (h)));
xlabel ('Normalised Frequency');
ylabel ('Magnitude in dB');
title ('FREQUENCY RESPONSE OF LOWPASS FILTER USING
KAISER WINDOW');
hold off
Output:
b = Columns 1 through 17
0.0170 -0.0186 -0.0206 0.0229 0.0258 -0.0294 -0.0341 0.0405
0.0497 -0.0641 -0.0899 0.1501 0.4507 0.4507 0.1501 -0.0899 -
0.0641
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 46
Columns 18 through 26
0.0497 0.0405 -0.0341 -0.0294 0.0258 0.0229 -0.0206 -0.0186
0.0170
b = Columns 1 through 17
0.0024 -0.0041 -0.0062 0.0089 0.0124 -0.0169 -0.0227 0.0305
0.0412 -0.0573 -0.0849 0.1471 0.4496 0.4496 0.1471 -0.0849 -
0.0573
Columns 18 through 26
0.0412 0.0305 -0.0227 -0.0169 0.0124 0.0089 -0.0062 -0.0041
0.0024
b = Columns 1 through 17
0.0000 -0.0002 -0.0006 0.0015 0.0032 -0.0062 -0.0109 0.0182
0.0293 - 0.0467 -0.0766 0.1416 0.4473 0.4473 0.1416 -0.0766 -
0.0467
Columns 18 through 26
0.0293 0.0182 -0.0109 -0.0062 0.0032 0.0015 -0.0006 -0.0002
0.0000
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 47
Result: FIR low pass filter is designed by using Kaiser Window for different values
of Beeta.
Inference: The response of stop band improves as beeta increases.
Questions & Answers
1. What are the design techniques of designing FIR filters?
a. There are three well-known methods for designing FIR filters with linear
phase.These are (1) window method (2) frequency sampling method (3) optimal or
minimax design.
2. What is the reason that FIR filter is always stable?
a. FIR filter is always stable because all its poles are at the origin.
3. What are the properties of FIR filter?
FIR filter is always stable.
A realizable filter can always be obtained.
FIR filter has a linear phase response.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 48
5. DESIGN IIR FILTER (LP/HP)
a)
Aim: To design IIR Butterworth low pass filter and verify its characteristics.
Theory: The most common technique used for designing IIR digital filters known
as indirect method, involves first designing an analog prototype filter and then
transforming the prototype to a digital filter. For the given specifications of a digital
filter, the derivation of the digital filter transfer function requires three steps.
1. Map the desired digital filter specifications into those for an equivalent
analog filter.
2. Derive the analog transfer function for the analog prototype.
3. Transform the transfer function of the analog prototype into an equivalent
digital filter transfer function.
There are several methods that can be used to design digital filters having an infinite
during unit sample response. The techniques described are all based on converting
an analog filter into digital filter. If the conversion technique is to be effective, it
should posses the following desirable properties.
1. The j-axis in the s-plane should map into the unit circle in the z-plane.
Thus there will be a direct relationship between the two frequency
variables in the two domains.
2. The left-half plane of the s-plane should map into the inside of the unit
circle in the z-plane. Thus a stable analog filter will be converted to a
stable digital filter.
Design a digital filter using impulse invariance method
1. For the given specifications, find H
a
(s), the transfer function of an analog
filter.
2. Select the sampling rate of the digital filter, T seconds per sample.
3. Express the analog filter transfer function as the sum of single-pole filters.
H
a
(s) =
N
K
k
p s ck
1
/
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 49
4. Compute the z-transform of the digital filter by using the formula
H (z) =
=
N
K
pkT
k
z e c
1
1
1 /
For high sampling rates use
H (z) =
=
N
K
pkT
k
z e Tc
1
1
1 /
Design digital filter using bilinear transform technique.
1. From the given specifications, find prewarping analog frequencies using formula
= 2/T tan w/2.
2. Using the analog frequencies find H (s) of the analog filter.
3. Select the sampling rate of the digital filter, call it T seconds per sample.
4. Substitute s= 2/T (1-z
-1
/1+ z
-1
) into the transfer function found in step2.
Program:
%Design of IIR Butterworth lowpass filter
alphap=input ('enter the pass band attenuation=');
alphas=input ('enter the stop band attenuation=');
fp=input ('enter the passband frequency=');
fs=input ('enter the stop band frequency=');
F=input ('enter the sampling frequency=');
omp=2*fp/F;
oms=2*fs/F;
[n, wn]=buttord (omp, oms, alphap, alphas)
[b, a]=butter (n, wn)
w=0:0.1: pi;
[h, ph]=freqz (b, a, w);
m=20*log (abs (h));
an=angle (h);
subplot (2, 1, 1);
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 50
plot (ph/pi, m);
grid on;
ylabel ('Gain in dB');
xlabel ('Normalised Frequency');
title (FREQUENCY RESPONSE OF BUTTERWORTH LOWPASS
subplot (2, 1, 2);
title (PHASE RESPONSE OF BUTTERWORTH LOWPASS FILTER);
plot (ph/pi, an);
grid on;
ylabel ('Phase in Radians');
xlabel ('Normalised Frequency');
Output:
Enter the pass band attenuation=0.4
Enter the stop band attenuation=60
Enter the pass band frequency=400
Enter the stop band frequency=800
Enter the sampling frequency=2000
n = 6
Wn =0.4914
b =0.0273 0.1635 0.4089 0.5452 0.4089 0.1635 0.0273
a = 1.0000 -0.1024 0.7816 -0.0484 0.1152 -0.0032 0.0018
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 51
Result: IIR Butterworth low pass filter is designed.
Inference: There are no ripples in the passband and stopband.
Questions & Answers
1. What are the advantages of IIR filters (compared to FIR filters)? What are IIR
filters? What does "IIR" mean?
a. IIR filters are one of two primary types of digital filters used in Digital Signal
Processing (DSP) applications (the other type being FIR). "IIR" means "Infinite
Impulse Response".
2. Why is the impulse response "infinite"?
a. The impulse response is "infinite" because there is feedback in the filter; if you put
in an impulse (a single "1" sample followed by many "0" samples), an infinite
number of non-zero values will come out (theoretically).
3. What is the alternative to IIR filters?
a. DSP filters can also be "Finite Impulse Response" (FIR). FIR filters do not use
feedback, so for a FIR filter with N coefficients, the output always becomes zero
after putting in N samples of an impulse response.IIR filters can achieve a given
filtering characteristic using less memory and calculations than a similar FIR filter.
4. What are the disadvantages of IIR filters (compared to FIR filters)?
They are more susceptible to problems of finite-length arithmetic, such
as noise generated by calculations, and limit cycles. (This is a direct
consequence of feedback: when the output isn't computed perfectly
and is fed back, the imperfection can compound.)
They are harder (slower) to implement using fixed-point arithmetic.
They don't offer the computational advantages of FIR filters for
multirate (decimation and interpolation) applications.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 52
b)
Aim: To design IIR Chebyshew type I high pass filter.
Program:
%Design of IIR Chebyshew type I high pass filter
alphap=input ('enter the pass band attenuation=');
alphas=input ('enter the stop band attenuation=');
fp=input ('enter the pass band frequency=');
fs=input ('enter the stop band frequency=');
F=input ('enter the sampling frequency=');
omp=2*fp/F;
oms=2*fs/F;
[n, wn]=cheb1ord (omp, oms, alphap, alphas)
[b, a]=cheby1 (n, wn, high)
w=0:0.1: pi;
[h, ph]=freqz (b, a, w);
m=20*log (abs (h));
an=angle (h);
subplot (2, 1, 1);
plot (ph/pi, m);
grid on;
ylabel ('Gain in dB');
xlabel ('Normalised Frequency');
title (FREQUENCY RESPONSE OF CHEBYSHEW TYPE I HIGH PASS FILTER);
subplot (2, 1, 2);
plot (ph/pi, an);
grid on;
ylabel ('Phase in Radians');
xlabel ('Normalised Frequency');
title (PHASE RESPONSE OF CHEBYSHEW TYPE I HIGH PASS FILTER);
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 53
Output:
enter the pass band attenuation=1
enter the stop band attenuation=15
enter the passband frequency=0.2*pi
enter the stop band frequency=0.1*pi
n = 3
Wn =0.2000
b = 0.4759 -1.4278 1.4278 -0.4759
a = 1.0000 -1.6168 1.0366 -0.1540
Result: IIR Chebyshew type I high pass filter is designed on DSP Processors.
Inference: The transition band is less in Chebyshev filter compared to Butterworth
filter.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 54
Questions & Answers
1. What are the parameters that can be obtained from the Chebyshev filter
specifications?
a. From the given Chebyshev filter specifications we can obtain the parameters like
the order of the filter N, , transition ratio k, and the poles of the filter.
2. Distinguish between Butterworth and Chebyshev (type-I) filter?
The magnitude response of Butterworth filter decreases monotonically as the
frequency increases from 0 to , where as the magnitude response of the
Chebyshev filter exhibits ripple in the passband and monotonically decreasing
in the stopband.
The transition band is more in Butterworth filter compared to Chebyshev filter.
The poles of the Butterworth filter lies on a circle whereas the poles of the
Chebyshev filter lies on an ellipse.
For the same specifications the number of poles in Butterworth filter is more
when compared to Chebyshev filter, i.e., the order of the Chebyshev filter is
less than that of Butterworth.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 55
6. N-POINT FFT ALGORITHM
Aim: To determine the N-point FFT of a given sequence.
Theory: The Fast Fourier transform is a highly efficient procedure for computing
the DFT of a finite series and requires less no of computations than that of direct
evaluation of DFT. It reduces the computations by taking the advantage of the fact
that the calculation of the coefficients of the DFT can be carried out iteratively. Due to
this, FFT computation technique is used in digital spectral analysis, filter simulation,
autocorrelation and pattern recognition. The FFT is based on decomposition and
breaking the transform into smaller transforms and combining them to get the total
transform. FFT reduces the computation time required to compute a discrete Fourier
transform and improves the performance by a factor 100 or more over direct
evaluation of the DFT. The fast fourier transform algorithms exploit the two basic
properties of the twiddle factor (symmetry property:
k
N
N k
N
w w =
+ 2 /
,
periodicity property:
k
N
N k
N
w w =
+
) and reduces the number of complex
multiplications required to perform DFT from N
2
to N/2 log
2
N. In other words, for
N=1024, this implies about 5000 instead of 10
6
multiplications a reduction factor of
200. FFT algorithms are based on the fundamental principal of decomposing the
computation of discrete fourier transform of a sequence of length N into successively
smaller discrete fourier transform of a sequence of length N into successively smaller
discrete fourier transforms. There are basically two classes of FFT algorithms. They
are decimation-in-time and decimation-in-frequency. In decimation-in-time, the
sequence for which we need the DFT is successively divided into smaller sequences
and the DFTs of these subsequences are combined in a certain pattern to obtain the
required DFT of the entire sequence. In the decimation-in-frequency approach, the
frequency samples of the DFT are decomposed into smaller and smaller
subsequences in a similar manner.
Radix 2 DIT FFT algorithm
1. The number of input samples N=2
M
, where, M is an integer.
2. The input sequence is shuffled through bit-reversal.
3. The number of stages in the flow graph is given by M=log
2
N.
4. Each stage consists of N/2 butterflies.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 56
5. Inputs/outputs for each butterfly are separated by 2
m-1
samples, where m
represents the stage index, i.e., for first stage m=1 and for second stage m=2
so on.
6. The no of complex multiplications is given by N/2 log
2
N.
7. The no of complex additions is given by N log
2
N.
8. The twiddle factor exponents are a function of the stage index m and is given
by . 1 2 ,... 2 , 1 , 0
2
1
= =
m
m
t
t
N
k
9. The no of sets or sections of butterflies in each stage is given by the formula
2
M-m.
10. The exponent repeat factor (ERF), which is the number of times the exponent
sequence associated with m is repeated is given by 2
M-m.
Radix 2 DIF FFT Algorithm
1. The number of input samples N=2
M
, where M is number of stages.
2. The input sequence is in natural order.
3. The number of stages in the flow graph is given by M=log
2
N.
4. Each stage consists of N/2 butterflies.
5. Inputs/outputs for each butterfly are separated by 2
M-m
samples, Where m
represents the stage index i.e., for first stage m=1 and for second stage m=2
so on.
6. The number of complex multiplications is given by N/2 log
2
N.
7. The number of complex additions is given by N log
2
N.
8. The twiddle factor exponents are a function of the stage index m and is given
by . 1 2 ,... 2 , 1 , 0 ,
2
1
= =
+
m m
m M
t
t
N
k
9. The number of sets or sections of butterflies in each stage is given by the
formula 2
m-1.
10. The exponent repeat factor (ERF), which is the number of times the
exponent sequence associated with m repeated is given by 2
m-1
.
For decimation-in-time (DIT), the input is bit-reversed while the output is in natural
order. Whereas, for decimation-in-frequency the input is in natural order while the
output is bit reversed order.
The DFT butterfly is slightly different from the DIT wherein DIF the complex
multiplication takes place after the add-subtract operation.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 57
Both algorithms require N log
2
N operations to compute the DFT. Both algorithms
can be done in-place and both need to perform bit reversal at some place during the
computation.
Program:
% N-point FFT algorithm
N=input ('enter N value=');
Xn=input ('type input sequence=');
k=0:1: N-1;
L=length (xn)
if (N<L)
error ('N MUST BE>=L');
end;
x1= [xn zeros (1, N-L)]
for c=0:1:N-1;
for n=0:1:N-1;
p=exp (-i*2*pi*n*C/N);
x2(c+1, n+1) =p;
end;
Xk=x1*x2';
end;
MagXk=abs (Xk);
angXk=angle (Xk);
subplot (2, 1, 1);
stem (k, magXk);
title ('MAGNITUDE OF DFT SAMPLES');
xlabel ('---->k');
ylabel ('-->Amplitude');
subplot (2, 1, 2);
stem (k, angXk);
title ('PHASE OF DFT SAMPLES');
xlabel ('---->k');
ylabel ('-->Phase');
disp (abs (Xk) =');
disp (magXk)
disp ('angle=');
disp (angXk)
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 58
Output:
enter N value=5
type input sequence= [1 1 0]
L= 3
x1 = 1 1 0 0 0
abs (Xk) = 2.0000 1.6180 0.6180 0.6180 1.6180
angle= 0 0.6283 1.2566 -1.2566 -0.6283
Result: N-point FFT of a given sequence is determined.
Inference: FFT reduces the computation time required to compute discrete
Fourier transform
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 59
Questions & Answers
1. What are the applications of FFT algorithms?
a. The applications of FFT algorithm includes
Linear filtering
Correlation
Spectrum analysis.
2. What is meant by radix-2 FFT?
a. The FFT algorithm is most efficient in calculating N- point DFT. If the number of
output points N can be expressed as a power of 2, that is, N=2
M,
where M is an
integer, then this algorithm is known as radix -2 FFT algorithm.
3. What is an FFT "radix"?
a. The "radix" is the size of FFT decomposition. In the example above, the radix was
2. For single-radix FFT's, the transform size must be a power of the radix. In the
example above, the size was 32, which is 2 to the 5th power.
4. What are "twiddle factors"?
a. "Twiddle factors" are the coefficients used to combine results from a previous
stage to form inputs to the next stage.
5. What is an "in place" FFT?
a. An "in place" FFT is simply an FFT that is calculated entirely inside its original
sample memory. In other words, calculating an "in place" FFT does not require
additional buffer memory (as some FFT's do.)
6. What is "bit reversal"?
a. "Bit reversal" is just what it sounds like: reversing the bits in a binary word from left
to write. Therefore the MSB's become LSB's and the LSB's become MSB's. But what
does that have to do with FFT's? Well, the data ordering required by radix-2 FFT's
turns out to be in "bit reversed" order, so bit-reversed indexes are used to combine
FFT stages. It is possible (but slow) to calculate these bit-reversed indices in
software; however, bit reversals are trivial when implemented in hardware. Therefore,
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 60
almost all DSP processors include a hardware bit-reversal indexing capability (which
is one of the things that distinguishes them from other microprocessors.)
7. What is "decimation in time" versus "decimation in frequency"?
a. FFT's can be decomposed using DFT's of even and odd points, which is called a
Decimation-In-Time (DIT) FFT, or they can be decomposed using a first-half/second-
half approach, which is called a "Decimation-In-Frequency" (DIF) FFT. Generally, the
user does not need to worry which type is being used.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 61
7. MATLAB PROGRAM TO GENERATE SUM OF SINUSOIDAL
SIGNALS
Aim: To generate sum of sinusoidal signals.
Theory:
Sinusoidal sequence:
X (n) = cos (w
0
n + ), n
Where is the phase in radians. A MATLAB function cos (or sin) is used to
generate sinusoidal sequences.
Signal addition: This is a sample-by-sample addition given by
{X1 (n)} + {x
2
(n)} = {x
1
(n) + x
2
(n)}
It is implemented in Matlab by the arithmetic operator +. However, the lengths of
x
1
(n) and x
2
(n) must be the same. If sequences are of unequal lengths, or if the
sample positions are different for equal length sequences, then we cannot directly
use the operator + . We have to first augment x
1
(n) and x
2
(n) so that they have the
same position vector n (and hence the same length). This requires careful attention
to MATLabs indexing operations. In particular, logical operation of intersection &
relational operations like <= and == and the find function are required to make
x
1
(n) amd x
2
(n) of equal length.
Program:
%Generation of sum of sinusoidal sequences
n=-4:0.5:4;
y1=sin (n)
subplot (2, 2, 1)
stem (n, y1,'filled')
grid on;
xlabel ('-->Samples');
ylabel ('--->Magnitude');
title ('SINUSOIDAL SIGNAL1');
y2=sin (2*n)
subplot (2, 2, 2)
stem (n, y2,'filled')
grid on;
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 62
xlabel ('-->Samples');
ylabel ('--->Magnitude');
title ('SINUSOIDAL SIGNAL2');
y3=y1+y2
subplot (2, 1, 2);
stem (n, y3,'filled');
xlabel ('-->Samples');
ylabel ('--->Magnitude');
title ('SUM OF SINUSOIDAL SIGNALS');
Output:
y1 = 0.7568 0.3508 -0.1411 -0.5985 -0.9093 -0.9975 -0.8415 -
0.4794
0 0.4794 0.8415 0.9975 0.9093 0.5985 0.1411 -0.3508 -
0.7568
y2 = -0.9894 -0.6570 0.2794 0.9589 0.7568 -0.1411 -0.9093 -
0.8415
0 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 0.6570
0.9894
y3 =-0.2326 -0.3062 0.1383 0.3605 -0.1525 -1.1386 -1.7508 -
1.3209
0 1.3209 1.7508 1.1386 0.1525 -0.3605 -0.1383 0.3062
0.2326
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 63
Result: Sum of sinusoidal signals is generated.
Inference: The lengths of x
1
(n) and x
2
(n) must be the same for sample-by-
sample addition.
Questions & Answers
1. What is deterministic signal? Give example.
a. A deterministic signal is a signal exhibiting no uncertainty of value at any given
instant of time. Its instantaneous value can be accurately predicted by specifying a
formula, algorithm or simply its describing statement in words.
Example; v (t) =A
o
sinwt
2. Define a periodic signal?
a. A signal x (n) is periodic with period N if and only if x (n+N) =x (n) for all n.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 64
8. MATLAB PROGRAM TO FIND FREQUENCY RESPONSE OF
ANALOG LP/HP FILTERS.
a)
Aim: To find frequency response of Butterworth analog low pass filter.
Theory: The magnitude function of the butterworth lowpass filter is given by
2 / 1 2
] ) / ( 1 /[ 1 ) (
N
c
j H + = N = 1, 2, 3,
Where N is the order of the filter and
c
is the cutoff frequency.
The following expression is used for the order of the filter.
P
S
P
S
N
=
log
1 10
1 10
log
1 . 0
1 . 0
Two properties of Butterworth lowpass filter
1. The magnitude response of the butterworth filter decreases
monotonically as the frequency increases from 0 to .
2. The magnitude response of the butterworth filter closely approximates
the ideal response as the order N increases.
3. The poles of the Butterworth filter lies on a circle.
Steps to design an analog butterworth lowpass filter
1. From the given specifications find the order of the filter N.
2. Round off it to the next higher integer.
3. Find the transfer function H (s) for
c
= 1 rad/sec for the value of N.
4. Calculate the value of cutoff frequency
c.
5. Find the transfer function H
a
(s) for the above value of
c
by substituting
s s/
c
in H(s).
Program:
%Design of Butterworth lowpass filter
alphap=input ('enter the pass band attenuation=');
alphas=input ('enter the stop band attenuation=');
fp=input ('enter the passband frequency=');
fs=input ('enter the stop band frequency=');
F=input ('enter the sampling frequency=');
omp=2*fp/F;
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 65
oms=2*fs/F;
[N, wn]=buttord (omp, oms, alphap, alphas,'s')
[b, a]=butter (n, wn)
w=0:0.01: pi;
[h, ph]=freqz (b, a, w);
m=20*log (abs (h));
an=angle (h);
subplot (2, 1, 1);
plot (ph/pi, m);
grid on;
ylabel ('Gain in dB');
xlabel ('Normalised Frquency');
title ('FREQUENCY RESPONSE OF BUTTERWORTH LOWPASS FILTER');
subplot (2, 1, 2);
plot (ph/pi, an);
grid on;
ylabel ('Phase in Radians');
xlabel ('Normalisd Frequency');
title ('PHASE RESPONSE OF BUTTERWORTH LOWPASS FILTER');
Output:
Enter the pass band attenuation=0.4
Enter the stop band attenuation=60
Enter the pass band frequency=400
Enter the stop band frequency=800
Enter the sampling frequency=2000
n = 12
Wn = 0.4499
b = 0.0003 0.0040 0.0220 0.0735 0.1653 0.2644 0.3085
0.2644
0.1653 0.0735 0.0220 0.0040 0.0003
a = 1.0000 -1.1997 2.2442 -1.7386 1.5475 -0.7945 0.4106
-0.1362
0.0412 -0.0080 0.0013 -0.0001 0.0000
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 66
Result: Butterworth analog low pass filter is designed and its frequency response
is found.
Inference: The magnitude response of the butterworth filter decreases
monotonically as the frequency increases.
Questions & Answers
1. Give any two properties of Butterworth lowpass filters?
The magnitude response of the Butterworth filter decreases monotonically as
the frequency increases from 0 to.
The magnitude response of the Butterworth filter closely approximates the
ideal response as the order N increases.
The poles of the Butterworth filter lies on a circle
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 67
b)
Aim: To find frequency response of Chebyshew type I analog high pass Filter.
Theory: There are two types of Chebyshev filters. Type I Chebyshev filters are all-
pole filters that exhibits equiripple behaviour in the passband and a monotonic
characteristics in the stopband. On the other hand, the family of type II Chebyshev
filter contains both poles and zeros and exhibits a monotonic behaviour in the
passband and equiripple behaviour in the stopband.
The magnitude square response of N
th
order type I filter can be expressed as
|H(j) |
2
= 1/1+
2
C
2
N
[/
p
] N = 1, 2,----
Where is a parameter of the filter related to the ripple in the passband and C
N
(x) is
the N
th
order Chebyshev polynomial defined as
C
N
(x) = cos (N cos
-1
x), |x| 1 (passband)
And
C
N
(x) = cosh (N cosh
-1
x), |x| > 1 (stopband)
Steps to design an analog Chebyshev lowpass filter
1. From the given specifications find the order of the filter N.
2. Round off it to the next higher integer.
3. Using the following formulas find the value of a and b, which are minor and
major axis of the ellipse respectively.
a =
p
[
1/N
-
-1/N
]
2 ;
b=
p
[
1/N
-
-1/N]
2
Where =
-1
+
-2
+ 1
= 10
0.1
p
- 1
p =
passband frequency
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 68
p
=
Maximum allowable attenuation in the passband
(For normalized Chebyshev filter
p
= 1 rad/sec)
4. Calculate the poles of Chebyshev filter which lies on an ellipse by using the
formula.
S
k
= a cos
k
+ jb sin
k
k= 1, 2, .N
Where
k
= /2 + [2k-1/2N] k= 1, 2, .N
5. Find the denominator polynominal of the transfer function using above poles.
6. The numerator of the transfer function depends on the value of N.
a) For N odd substitute s = 0 in the denominator polynominal and find
the value. This value is equal to the numerator of the transfer
function.
(For N odd the magnitude response |H(j)| starts at 1.)
b) For N even substitute s=0 in the denominator polynominal and divide
the result by 1+
2
. This value is equal to the numerator.
The order N of Chebyshev filter is given by
N= cos h
-1
[(10
0.1
s
-1)/ (10
0.1
p
-1)]/cos h
-1
(
s/ p
)
Where
s
is stopband attenuation at stopband frequency
s
and
p
is passband
attenuation at passband frequency
p
. The major minor axis of the ellipse is given
by
b=
p
[(
1/N
+
-1/N
)/2] and a =
p
[ (
1/N
-
-1/N
)/2]
Where =
-1
+ 1+
-2
And = (10
0.1
p
-1)
Program:
%Design of IIR Chebyshew type I high pass filter
alphap=input ('enter the pass band attenuation=');
alphas=input ('enter the stop band attenuation=');
wp=input ('enter the pass band frequency=');
ws=input ('enter the stop band frequency=');
[n, wn]=cheb1ord (wp/pi, ws/pi, alphap, alphas,'s')
[b, a]=cheby1 (n, alphap, wn,'high')
w=0:0.01: pi;
[h, ph]=freqz (b, a, w);
m=20*log (abs (h));
an=angle (h);
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 69
subplot (2, 1, 1);
plot (ph/pi, m);
grid on;
ylabel ('Gain in dB');
xlabel ('Normalised Frquency');
title ('FREQUENCY RESPONSE OF CHEBYSHEW TYPE I HIGHPASS
FILTER');
subplot (2, 1, 2);
plot (ph/pi, an);
grid on;
ylabel ('Phase in Radians');
xlabel ('Normalisd Frequency');
title ('PHASE RESPONSE OF CHEBYSHEW TYPE I HIGHPASS FILTER');
Output:
Enter the pass band attenuation=1
Enter the stop band attenuation=15
Enter the pass band frequency=0.2*pi
Enter the stop band frequency=0.1*pi
n =3
wn = 0.2000
b =0.4759 -1.4278 1.4278 -0.4759
a = 1.0000 -1.6168 1.0366 -0.1540
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 70
Result: Chebyshew type I analog high pass filter is designed and its frequency
response is observed.
Inference: Chebyshev approximation provides better characteristics near the
cutoff frequency and near the stop band edge.
Questions & Answers
1. How one can design digital filters from analog filters?
Map the desired digital filter specifications into those for an equivalent analog
filter.
Derive the analog transfer function for the analog prototype.
Transform the transfer function of the analog prototype into an equivalent
digital filter transfer function.
2. What are the properties of Chebyshev filter?
The magnitude response of the Chebyshev filter exhibits ripple either in
passband or in stopband according to type.
The poles of the Chebyshev filter lies on ellipse.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 71
9. POWER DENSITY SPECTRUM OF A SEQUENCE
Aim: To compute power density spectrum of a sequence.
Theory: PSD Power Spectral Density estimate.
Pxx = PSD(X, NFFT, Fs, WINDOW) estimates the Power Spectral Density of
a discrete-time signal vector X using Welch's averaged, modifiedperiodogram
method.X is divided into overlapping sections, each of which is detrended (according
to the detrending flag, if specified), then windowed by the WINDOW parameter, then
zero-padded to length NFFT. The magnitude squared of the length NFFT DFTs of
the sections are averaged to form Pxx. Pxx is length NFFT/2+1 for NFFT even,
(NFFT+1)/2 for NFFT odd, or NFFT if the signal X is complex. If you specify a scalar
for WINDOW, a Hanning window of that length is used. Fs is the sampling frequency
which doesn't affect the spectrum estimate but is used for scaling the X-axis of the
plots. [Pxx, F] = PSD(X, NFFT, Fs, WINDOW, NOVERLAP) returns a vector of
frequencies the same size as Pxx at which the PSD is estimated, and overlaps
the sections of X by NOVERLAP samples. [Pxx, Pxxc, F] = PSD(X, NFFT, Fs,
WINDOW, NOVERLAP, P) where P is a scalar between 0 and 1, returns the P*100%
confidence interval for Pxx. PSD(X, DFLAG), where DFLAG can be 'linear', 'mean' or
'none', specifies a detrending mode for the prewindowed sections of X. DFLAG can
take the place of any parameter in the parameter list (besides X) as long as it is last,
e.g. PSD(X,'mean'); PSD with no output arguments plots the PSD in the current
figure window, with confidence intervals if you provide the P parameter. The default
values for the parameters are NFFT = 256 (or LENGTH(X), whichever is smaller),
NOVERLAP = 0, WINDOW = HANNING (NFFT), Fs = 2, P = .95, and DFLAG =
'none'. You can obtain a default parameter by leaving it off or inserting an empty
matrix [], e.g. PSD(X, [], 10000).
Program:
%Power density spectrum of a sequence
x=input ('enter the length of the sequence=');
y=input ('enter the sequence=');
fs=input ('enter sampling frequency=');
N=input ('enter the value of N=');
q=input ('enter the window name1=');
m=input ('enter the window name2=');
s=input ('enter the window name3=');
pxx1=psd(y, N, fs, q)
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 72
plot (pxx1,'c');
hold on;
grid on;
pxx2=psd(y, N, fs, m)
plot (pxx2,'k');
hold on;
pxx3=psd(y, N, fs, s)
plot (pxx3,'b');
hold on;
xlabel ('-->Frequency');
ylabel ('-->Magnitude');
title ('POWER SPECTRAL DENSITY OF A SEQUENCE');
hold off;
Output:
Enter the length of the sequence=5
Enter the sequence= [1 2 3 4 5]
Enter sampling frequency=20000
Enter the value of N=4
Enter the window name1=rectwin (N)
Enter the window name2=Kaiser (N, 4.5)
Enter the window name3=triang (N)
pxx1 =25.0000
2.0000
1.0000
pxx2 =14.2828
5.7258
0.3065
pxx3 = 20.0000
3.4000
0.0000
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 73
Result: Power density spectrum of a sequence is computed.
Inference: Power spectral density does not have any phase information.
Questions & Answers
1. Define power spectral density?
a. The power spectral density is a measure of how the power in a signal changes
over frequency.
2. What is window function? What are the applications of window functions?
a. In signal processing, a window function is a function that is zero-valued outside of
some chosen interval. For instance, a function that is constant inside the interval
and zero elsewhere is called a rectangular window, which describes the shape of
its graphical representation. When another function or a signal (data) is multiplied
by a window function, the product is also zero-valued outside the interval.
Applications of window functions include spectral analysis, filter design and beam
forming.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 74
10. FFT OF A GIVEN 1-D SIGNAL
Aim: To find the FFT of a given 1-D signal and plot the characteristics.
Theory: The DFT of a sequence can be evaluated using the formula
1 - N k 0 ) ( ) (
1
0
/ 2
=
N
n
N nk j
e n x k X
Substituting W
N
=
N j
e
/ 2
, we have
1 - N k 0 ) ( ) (
1
0
=
=
N
n
nk
N
W n x k X
The Fast Fourier transform is a highly efficient procedure for computing the DFT of a
finite series and requires less no of computations than that of direct evaluation of
DFT. It reduces the computations by taking the advantage of the fact that the
calculation of the coefficients of the DFT can be carried out iteratively. Due to this,
FFT computation technique is used in digital spectral analysis, filter simulation,
autocorrelation and pattern recognition. The FFT is based on decomposition and
breaking the transform into smaller transforms and combining them to get the total
transform. FFT reduces the computation time required to compute a discrete Fourier
transform and improves the performance by a factor 100 or more over direct
evaluation of the DFT. The fast fourier transform algorithms exploit the two basic
properties of the twiddle factor (symmetry property:
k
N
N k
N
w w =
+ 2 /
,
periodicity property:
k
N
N k
N
w w =
+
) and reduces the number of complex
multiplications required to perform DFT from N
2
to N/2 log
2
N. In other words, for
N=1024, this implies about 5000 instead of 10
6
multiplications a reduction factor of
200. FFT algorithms are based on the fundamental principal of decomposing the
computation of discrete fourier transform of a sequence of length N into successively
smaller discrete fourier transform of a sequence of length N into successively smaller
discrete fourier transforms. There are basically two classes of FFT algorithms. They
are decimation-in-time and decimation-in-frequency. In decimation-in-time, the
sequence for which we need the DFT is successively divided into smaller sequences
and the DFTs of these subsequences are combined in a certain pattern to obtain the
required DFT of the entire sequence. In the decimation-in-frequency approach, the
frequency samples of the DFT are decomposed into smaller and smaller
subsequences in a similar manner.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 75
Radix 2 DIT FFT algorithm
11. The number of input samples N=2
M
, where, M is an integer.
12. The input sequence is shuffled through bit-reversal.
13. The number of stages in the flow graph is given by M=log
2
N.
14. Each stage consists of N/2 butterflies.
15. Inputs/outputs for each butterfly are separated by 2
m-1
samples, where m
represents the stage index, i.e., for first stage m=1 and for second stage m=2
so on.
16. The no of complex multiplications is given by N/2 log
2
N.
17. The no of complex additions is given by N log
2
N.
18. The twiddle factor exponents are a function of the stage index m and is given
by . 1 2 ,... 2 , 1 , 0
2
1
= =
m
m
t
t
N
k
19. The no of sets or sections of butterflies in each stage is given by the formula
2
M-m.
20. The exponent repeat factor (ERF), which is the number of times the exponent
sequence associated with m is repeated is given by 2
M-m.
Radix 2 DIF FFT Algorithm
11. The number of input samples N=2
M
, where M is number of stages.
12. The input sequence is in natural order.
13. The number of stages in the flow graph is given by M=log
2
N.
14. Each stage consists of N/2 butterflies.
15. Inputs/outputs for each butterfly are separated by 2
M-m
samples, Where m
represents the stage index i.e., for first stage m=1 and for second stage m=2
so on.
16. The number of complex multiplications is given by N/2 log
2
N.
17. The number of complex additions is given by N log
2
N.
18. The twiddle factor exponents are a function of the stage index m and is given
by . 1 2 ,... 2 , 1 , 0 ,
2
1
= =
+
m m
m M
t
t
N
k
19. The number of sets or sections of butterflies in each stage is given by the
formula 2
m-1.
20. The exponent repeat factor (ERF),Which is the number of times the exponent
sequence associated with m repeated is given by 2
m-1
.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 76
Program:
%To find the FFT of a given 1-D signal and plot
N=input ('enter the length of the sequence=');
M=input ('enter the length of the DFT=');
u=input ('enter the sequence u (n) =');
U=fft (u, M)
A=length (U)
t=0:1: N-1;
subplot (2, 2, 1);
stem (t, u);
title ('ORIGINAL TIME DOMAIN SEQUENCE');
xlabel ('---->n');
ylabel ('-->Amplitude');
subplot (2, 2, 2);
k=0:1:A-1;
stem (k, abs (U));
disp (abs (U) =');
disp (abs (U))
title ('MAGNITUDE OF DFT SAMPLES');
xlabel ('---->k');
ylabel ('-->Amplitude');
subplot (2, 1, 2);
stem (k, angle (U));
disp (angle (U) =')
disp (angle (U))
title ('PHASE OF DFT SAMPLES');
xlabel ('---->k');
ylabel ('-->phase');
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 77
Output:
Enter the length of the sequence=3
Enter the length of the DFT=3
Enter the sequence u (n) = [1 2 3]
U = 6.0000 -1.5000 + 0.8660i -1.5000 - 0.8660i
A = 3
abs (U) = 6.0000 1.7321 1.7321
angle (U) = 0 2.6180 -2.6180
Result: FFT of a given 1-D signal is determined and its magnitude and phase
plots are plotted.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 78
Inference: FFT reduces the computation time required to compute discrete
Fourier transform.
Questions & Answers
1. What is the FFT?
a. The Fast Fourier Transform (FFT) is simply a fast (computationally efficient) way to
calculate the Discrete Fourier Transform (DFT).
2. How does the FFT work?
a. By making use of periodicities in the sines that are multiplied to do the transforms,
the FFT greatly reduces the amount of calculation required. Functionally, the FFT
decomposes the set of data to be transformed into a series of smaller data sets to be
transformed. Then, it decomposes those smaller sets into even smaller sets. At each
stage of processing, the results of the previous stage are combined in special way.
Finally, it calculates the DFT of each small data set. For example, an FFT of size 32
is broken into 2 FFT's of size 16, which are broken into 4 FFT's of size 8, which are
broken into 8 FFT's of size 4, which are broken into 16 FFT's of size 2. Calculating a
DFT of size 2 is trivial. Heres a slightly more rigorous explanation: It turns out that it
is possible to take the DFT of the first N/2 points and combine them in a special way
with the DFT of the second N/2 points to produce a single N-point DFT. Each of
these N/2-point DFTs can be calculated using smaller DFTs in the same way. One
(radix-2) FFT begins, therefore, by calculating N/2 2-point DFTs. These are
combined to form N/4 4-point DFTs. The next stage produces N/8 8-point DFTs, and
so on, until a single N-point DFT is produced.
3. How efficient is the FFT?
a. The DFT takes N^2 operations for N points. Since at any stage the computation
required to combine smaller DFTs into larger DFTs is proportional to N, and there are
log2 (N) stages (for radix 2), the total computation is proportional to N * log2 (N).
Therefore, the ratio between a DFT computation and an FFT computation for the
same N is proportional to N / log2 (n). In cases where N is small this ratio is not very
significant, but when N becomes large, this ratio gets very large. (Every time you
double N, the numerator doubles, but the denominator only increases by 1.)
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 79
4. Are FFT's limited to sizes that are powers of 2?
a. No, The most common and familiar FFT's are "radix 2". However, other radices are
sometimes used, which are usually small numbers less than 10. For example, radix-4
is especially attractive because the "twiddle factors" are all 1, -1, j, or -j, which can be
applied without any multiplications at all. Also, "mixed radix" FFT's also can be done
on "composite" sizes. In this case, you break a non-prime size down into its prime
factors, and do an FFT whose stages use those factors. For example, an FFT of size
1000 might be done in six stages using radices of 2 and 5, since 1000 = 2 * 2 * 2 * 5
* 5 * 5. It might also be done in three stages using radix 10, since 1000 = 10 *10 *10.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 80
OTHER EXPERIMENTS
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 81
1. GENERATION OF BASIC SEQUENCES
Aim: To generate impulse, step and sinusoidal sequences.
Program:
%Generation of basic sequences
%generation of impulse sequence
t=-2:1:2;
v= [zeros (1, 2), ones (1, 1), zeros (1, 2)]
subplot (2, 2, 1);
stem (t, v,'m','filled');
grid on;
ylabel ('---->Amplitude');
xlabel ('--->n');
title (' IMPULSE SEQUENCE');
%generation of step sequence
t=0:1:5;
m= [ones (1, 6)]
subplot (2, 2, 2);
stem (t, m,'m','filled');
grid on;
ylabel ('---->Amplitude');
xlabel ('--->n');
title (' STEP SEQUENCE');
%generation of sinusoidal sequence
t=-4:1:4;
y=sin (t)
subplot (2, 1, 2);
stem (t, y,'m','filled');
grid on;
ylabel ('---->Amplitude');
xlabel ('--->n');
title ('SINUSOIDAL SEQUENCE');
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 82
Output:
v = 0 0 1 0 0
m = 1 1 1 1 1 1
y= 0.7568 -0.1411 -0.9093 -0.8415 0 0.8415 0.9093
0.1411
-0.7568
Result: Impulse, step and sinusoidal sequences are generated.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 83
2. DFT OF A SEQUENCE
Aim: To compute the DFT of a sequence.
Program:
%DFT of a sequence
N=input ('enter the length of the sequence=');
x=input ('enter the sequence=');
n= [0:1: N-1];
k= [0:1: N-1];
wN=exp (-j*2*pi/N);
nk=n'*k;
wNnk=wN. ^nk;
Xk=x*wNnk;
disp ('Xk=');
disp (Xk);
mag=abs (Xk)
subplot (2, 1, 1);
stem(k,mag);
grid on;
xlabel('--->k');
title ('MAGNITUDE OF FOURIER TRANSFORM');
ylabel ('Magnitude');
phase=angle (Xk)
subplot (2, 1, 2);
stem (k, phase);
grid on;
xlabel ('--->k');
title ('PHASE OF FOURIER TRANSFORM');
ylabel ('Phase');
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 84
Output:
Enter the length of the sequence=5
Enter the sequence= [1 2 3 4 5]
Xk= 15.0000 -2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000
0.8123i
-2.5000 - 3.4410i
mag = 15.0000 4.2533 2.6287 2.6287 4.2533
phase = 0 2.1991 2.8274 -2.8274 -2.1991
Result: DFT of a sequence is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 85
3. IDFT OF A SEQUENCE
Aim: To compute the IDFT of a sequence.
Program:
%IDFT of a sequence
Xk=input (enter X (K) =');
[N, M]=size (Xk);
if M~=1;
Xk=Xk.';
N=M;
end;
xn=zeros (N, 1);
k=0: N-1;
for n=0: N-1;
xn (n+1) =exp (j*2*pi*k*n/N)*Xk;
end;
xn=xn/N;
disp (x (n) = ');
disp (xn);
plot (xn);
grid on;
plot(xn);
stem(k,xn);
xlabel ('--->n');
ylabel ('-->magnitude');
title (IDFT OF A SEQUENCE);
Output:
Enter the dft of X (K) = [6 -1.5+0.86i -1.5-0.86i]
x (n) =1.0000
2.0035 + 0.0000i
2.9965 - 0.0000i
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 86
Result: IDFT of a given sequence is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 87
CODE COMPOSER STUDIO
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 88
TEXAS INSTRUMENT DSP STARTER KIT 6711DSK
A BRIEF INTRODUCTION
1 Introduction
The purpose of this documentation is to give a very brief overview of the structure of
the 6711DSK. Included is also a mini tutorial on how to program the DSP, download
programs and debug it using the Code Composer Studio software.
2 The DSP starter kit
The Texas Instrument 6711DSK is a DSP starter kit for the TMS320C6711 DSP chip.
The kit contains:
An emulator board which contains:
DSP chip, memory and control circuitry.
Input/output capabilities in the form of
_ An audio codec (ADC and DAC) which provides 1 input and 1 output
channel sampled at 8 kHz.
_ Digital inputs and outputs
_ A connector for adding external evaluation modules, like the PCM3003
Audio daughter card which has 2 analog in and 2 analog out sampled at
48 kHz.
A parallel port for interface to a host computer used for program
development, program download and debugging.
The Code Composer Studio (CCS) software which is an integrated development
environment (IDE) for editing programs, compiling, linking, download to target
(i.e., to the DSK board) and debugging. The CCS also includes the DSP/BIOS
real-time operating system. The DSP/BIOS code considerably simplifies the code
development for real-time applications which include interrupt driven and time
scheduled tasks.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 89
3 Usage overview
Working with the DSK involves the following steps:
The first step is the algorithm development and programming in C/C++ or
assembler. We will only consider coding in C in this document. The program is typed
using the editor capabilities of the CCS. Also the DSP/BIOS configuration is
performed in a special configuration window.
When the code is finished it is time to compile and link the different code parts
together. This is all done automatically in CCS after pressing the Build button. If
the compilation and linking succeeded the finished program is downloaded to the
DSK board.
The operation of DSK board can be controlled using CCS, i.e., CCS also works as
a debugger. The program can be started and stopped and single-step. Variables in
the program can be inspected with the Watch functionality. Breakpoints can be
inserted in the code.
4 Getting started with the 6711DSK and CCS
In this section you will be introduced to the programming environment and will
download and execute a simple program on the DSK.
4.1 Connecting the PC and DSK
The DSK is communicating with the host PC using the parallel-port interface.
1. Start Code Composer Studio (CCS) by clicking on the CCStudio 3.01 icon on the
workspace.
2. Check that the DSK is powered up. If not, power up the DSK by inserting the
AC power cable (mains) to the black AC/DC converter. Note: Never unplug the
power cable from the DSK card.
3. Make a connection between CCS and the DSK by selecting menu command
Debug! Connect. If connection fails perform following steps:
(a) Select menu command Debug! Reset Emulator
(b) Power cycle the DSK by removing the AC power cord from the AC/DC converter,
wait about a second and then reinsert.
(c) Select menu command Debug! Connect.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 90
4.2 Getting familiar with CCS
CCS arranges its operation around a project and the Project view window is
displayed to the left. Here you can find all files which are related to a certain project.
At the bottom of the CCS window is the status output view in which status information
will be displayed such as compile or link errors as well as other types of information.
Note that the window will have several tabs for different types of output.
4.3 Loading programs from CCS
One setting might need to be changed in CCS in order to automatically download the
program after compilation and linking (a build). You find the setting under menu
command Options! Customize and tab Program Load Options. Tick the box Load
Program after Build.
4.3.1 Project view and building an application
You open an existing project by right-clicking on the project folder and select the
desired .pjt file or select the command from the menu Project! Open....
Open the project intro.pjt which you find in the introfolder.
Press the + sign to expand the view. Several folders appear which contain all
the project specific files.
Open up the Source folder. Here you will find all the files with source code which
belongs to the project.
Double click on the intro.c file to open up an editor window with the file intro.c file
loaded.
Look around in the file. The code calculates the inner product between two integer
vectors of length COUNT by calling the function dotp and then prints the result
using the LOG printf command.
Compile, link and download the code selecting the Project! Build command or
use the associated button. If the download fails. Power cycle the DSK and retry
Project! Build.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 91
4.3.2 Running the code after a successful build command (compile, link and
download) the program is now resident in the DSK and ready for execution. A
disassembly window will appear showing the Assembly language instructions
produced by the compiler. You can minimize the window for now. At the bottom left
you will see the status CPU HALTED indicating that the CPU is not executing any
code. A few options are available depending on if you want to debug or just run the
code.
To simply run the code does:
Select Debug! Run to start the execution. At the bottom left you will see the status
CPU RUNNING indicating that the program is executed.
To stop the DSP select Debug! Halt.
If you want the restart the program do Debug! Restart followed by Debug! Run
Try to run the code in the intro project. To see the output from the LOG printf
commands you must enable the view of the Message Log Window. Do DSP/BIOS!
Message Log and select LOG0 in the pull-down menu.
4.3.3 CCS Debug
Single stepping for debugging the code do the following:
Select Debug! Go Main. This will run DSP/BIOS part of the code until the start
of the main function. A yellow arrow will appear to the left of the start of the
main function in the edit window for the intro.c file. The arrow indicates where
the program execution has halted.
Now you can step the code one line at the time. Three commands are available:
Debug! Step Into will execute the marked line if it is composed of simple
instructions or if the line has a function call, will step in to the called function.
Debug! Step Over will execute the marked line and step to the next line.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 92
Debug! Step Out will conclude the execution of the present function and halt
the execution at the next line of the calling function. Try to step through the code
using the step functions. View variables if you want to know the value of a particular
variable just put the cursor on top of the variable in the source window. The value will
after a short delay pop up next to the variable. Note that local variables in functions
only have defined values when the execution is located inside the function. Variables
can also be added to the Watch window which enables a concurrent view of several
variables. Mark the y variable in source code, right-click and select Add to Watch
Window. The watch window
will then add variable y to the view and show its contents. Also add the a variable
(which is a array) to the watch window. Since a is an array the value of a is an
address. Click on the +. This will show the individual values of the array. The watch
window will update its contents whenever the DSP is halted. It is also possible to
change the value of a variable in the DSK from the Watch window. Simply select the
numerical value you want to change and type in a new value. CCS will send the new
value to the DSK before starting the execution.
Break points Break points can also be used to halt the execution at a particular point
in the source code. To illustrate its use consider the intro. Place the cursor at the
line which has the return (sum); instruction in the dotp function. Right-click and
select Toggle breakpoint. A red dot will appear at that line indicating that a breakpoint
is set at that line. Try it out. First do Debug! Restart and then Debug! Run The
execution will halt at the line and we can investigate variables etc. To resume
execution simply issue Debug! Run command again. Shortcut buttons CCS offers a
number of shortcut buttons both for the build process as well as the debugging.
Browse around with the mouse pointer to find them. The balloon help function will
show what command a particular button is associated with, i.e., move the mouse
pointer over a button and wait for the balloon help to show up. Loading the values in
a vector into Matlab In the Lab you will need to load the coefficients of a FIR filter into
Matlab for further analysis. The filter coefficients are stored in vectors. Use the
following procedure:
1. Run the DSP program on the DSK.
2. Halt the execution when it is time to upload the vector.
3. In the File menu you find File! Data! Save In the file dialog assign a name to
the data file and select Float as Save as type.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 93
4. In the next dialog enter the name of the vector in the address field. When you tab
away from it it will change to the absolute memory address of the vector. In the
length box you enter the length of the variable. Note that you need to remove the 0x
prefix if you give the length using decimals numbers. The notation with 0x in the
beginning indicates that the number is a Hexadecimal number, i.e. it is based on a
base of 16 instead of the normal base of 10 in the decimal system.
5. Open the file in an editor and remove the first line and save again
6. In Matlab use the load command to load the saved file. The vector will get the
same name as the file name without the extension.
5 Debugging - limitations
The debugging features of the CCS are very handy during the code development.
However, several limitations are present.
Since the compiler will optimize the code, all lines in the C-code cannot be used as
breakpoints. Since the architecture has several parallel processing units the final
code might execute several lines of C in one clock cycle.
The processor also has memory cache which speeds up normal operations. This
means that when the DSP loads a particular memory location it will copy it into
the cache memory and then perform the operations (faster) using the cache. After
some time the cache will be written back again to the memory. This can sometimes
confuse CCS and variables in the Watch window can be erroneous.
The third important issue is when debugging code which is dependent on external
events, e.g., interrupt driven code. When halting such a code by a break point
several features are important to consider. Firstly, since the code is stopped all real-
time deadlines will be broken so future sampled inputs will be lost. Hence a restart
from the point of the break might cause unpredicted behavior.
Sometimes the code in the DSK which communicates with the CCS stops working.
When this happens it is necessary to power cycle, the DSK board in order to restart
the operation. Sometimes it is also necessary at the same time to restart CCS.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 94
PROCEDURE TO WORK ON CODE COMPOSER
STUDIO
To create the new project
Project new (File name.pjt, eg: vectors.pjt)
To create a source file
File newtype the code (save &give file name, eg: sum.c
To add source files to project
Project add files to projectsum.c
To add rts.lib file&hello.cmd:
Project add files to project rts6700.lib
Libraryfiles: rts6700.lib (path:c:\ti\c6000\cgtools\lib\rts6700.lib)
Note: select object&library in (*.o,*.1) in type of files
Project add files to projectshello.cmd
Cmd file which is common for all non real time programs.
(path:c\ti\tutorials\dsk6711\hello.1\hello.cmd)
Note: select linker command file (*.cmd) in type of files
Compile:
To compile: projectcompile
To rebuild: projectrebuild
Which will create the final.outexecutablefile (eg.vectors.out)
Procedure to load and run program:
Load the program to DSK: file load programvectors. Out
To execute project: Debugrun
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 95
C PROGRAMS
(USING64XX, 67XX SIMULATORS)
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 96
1. TO VERIFY LINEAR CONVOLUTION
Aim: Write a C program for linear convolution of two discrete sequences and
compute using code composer studio V2 (using simulators 64xx, 67xx, 6711)
software.
Program:
#include<stdio.h>
#include<math.h>
main ()
{
int x[20],h[20],y[20],N1,N2,n,m;
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N1);
printf ("enter the length of the sequence h (n) :");
scanf ("%d", &N2);
printf ("enter the sequence x (n) :");
for (n=0; n<N1; n++)
scanf ("%d", &x[n]);
printf ("enter the sequence h (n) :");
for (n=0; n<N2; n++)
scanf ("%d", &h[n]);
for (n=0; n<N1+N2-1; n++)
{
if (n>N1-1)
{
y[n]=0;
for(m=n-(N1-1);m<=(N1-1);m++)
y[n] =y[n] +x[m]*h [n-m];
}
else
{
y[n] =0;
for (m=0; m<=n; m++)
y[n] =y[n] +x[m]*h [n-m];
}
}
printf ("convolution of two sequences is y (n) :");
for (n=0; n<N1+N2-1; n++)
printf ("%d\t", y[n]);
}
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 97
Input:
Enter the length of the sequence x (n):4
Enter the length of the sequence h (n):3
Enter the sequence x (n):1 2 3 4
Enter the sequence h (n):5 6 7
Output:
Convolution of two sequences is y (n):5 16 34 52 45 28
Result: Linear convolution of two discrete sequences is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 98
2. TO VERIFY CIRCULAR CONVOLUTION
Aim: Write a C program for circular convolution of two discrete sequences and
compute using code composer studio V2 (using simulators 64xx, 67xx, 6711)
software.
Program:
#include<math.h>
#define pi 3.14
main ()
{
int x[20],h[20],y[20],N1,N2,N,n,m,k;
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N1);
printf ("enter the length of the sequence h (n) :");
scanf ("%d", &N2);
printf ("enter the %d samples of sequence x (n): N1);
for (n=0; n<N1; n++)
scanf ("%d", &x[n]);
printf ("enter the %d samples of sequence h (n): N2);
for (n=0; n<N2; n++)
scanf ("%d", &h[n]);
if (N1>N2)
{
N=N1;
for (n=N2; n<N; n++)
h[n]=0;
}
else
{
N=N2;
for(n=N1;n<N1;n++)
y[n]=0;
}
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 99
for(k=0;k<N;k++)
{
y[k]=0;
for (m=N-1; m>=0; m--)
{
if ((N+k-m)>=N)
{
y[k] =y[k] +x[m]*h [k-m];
}
else
y[k] =y[k] +x[m]*h [N+k-m];
}
}
printf ("\response is y (n) :");
for (n=0; n<N; n++)
printf ("\t%d", y[n]);
}
Input:
Enter the length of the sequence x (n):4
Enter the length of the sequence h (n):4
Enter the 4 samples of sequence x (n):2 1 2 1
Enter the 4 samples of sequence h (n):1 2 3 4
Output:
Response is y (n): 14 16 14 16
Result: Circular convolution of two discrete sequences is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 100
3. DFT OF A SEQUENCE
Aim: Write a C program for DFT of a sequence and compute using code composer
studio V2 (using simulators 64xx, 67xx, 6711) software.
Program:
%DISCRETE FOURIER TRANSFORM OF THE GIVEN SEQUENCE
#include<stdio.h>
#include<math.h>
#define pi 3.14
main ()
{
int x [20], N, n, k;
float Xre[20],Xim[20],Msx[20],Psx[20];
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N);
printf ("enter the %d samples of discrete sequence x (n): N);
for (n=0; n<N; n++)
scanf ("%d", &x[n]);
for(k=0;k<N;k++)
{
Xre[k]=0;
Xim[k]=0;
for(n=0;n<N;n++)
{
Xre[k]=Xre[k]+x[n]*cos(2*pi*n*k/N);
Xim[k]=Xim[k]+x[n]*sin(2*pi*n*k/N);
}
Msx[k]=sqrt(Xre[k]*Xre[k]+Xim[k]*Xim[k]);
Xim[k]=-Xim[k];
Psx[k]=atan(Xim[k]/Xre[k]);
}
printf ("discrete sequence is");
for (n=0; n<N; n++)
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 101
printf ("\nx(%d) =%d", n,x[n]);
printf ("\nDFT sequence is :");
for(k=0;k<N;k++)
printf("\nx(%d)=%f+i%f",k,Xre[k],Xim[k]);
printf("\nmagnitude is:");
for (k=0; k<N; k++)
printf ("\n%f",Msx[k]);
printf ("\nphase spectrum is");
for(k=0;k<n;k++)
printf("\n%f",Psx[k]);
}
Input:
Enter the length of the sequence x (n):4
Enter the 4 samples of discrete sequence x (n):1 2 3 4
Output:
Discrete sequence is:
x (0) =1
x (1) =2
x (2) =3
x (3) =4
DFT sequence is :
x (0) =10.000000+i0.000000
x (1) =-2.007959+i1.995211
x (2) =-1.999967+i-0.012741
x (3) =-1.976076+i-2.014237
Magnitude is: Phase spectrum is:
0.000000 10.000000
-0.782214 2.830683
0.006371 2.000007
0.794961 2.821707
Result: DFT of a given sequence is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 102
4. IDFT OF A SEQUENCE
Aim: Write a C program for IDFT of a sequence and compute using code composer
studio V2 (using simulators 64xx, 67xx, 6711) software.
Program:
% Inverse Discrete Foureir Transform
#include<stdio.h>
#include<math.h>
#define pi 3.1428
main()
{
int j, k, N, n;
float XKr[10],XKi[10],xni[10],xnr[10],t;
printf (" enter seq length: \n");
scanf ("%d", &N);
printf ("enter the real & imaginary terms of the sequence: \n");
for (j=0; j<N; j++)
{
scanf ("%f%f", &XKr[j], &XKi[j]);
}
for (n=0; n<N; n++)
{
xnr[n] =0; xni[n] =0;
for(k=0;k<N;k++)
{
t=2*pi*k*n/N;
xnr[n]=( xnr[n]+XKr[k]*cos(t) - XKi[k]*sin(t)) ;
xni[n]=( xni[n]+XKr[k]*sin(t) + XKi[k]*cos(t)) ;
}
xnr[n]=xnr[n]/N;
xni[n]=xni[n]/N;
}
printf("IDFT seq:");
for(j=0;j<N;j++)
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 103
{
printf("%f + (%f) i\n",xnr[j],xni[j]);
}
}
Input:
Enter seq length: 4
Enter the real & imaginary terms of the sequence:
3
0
0
-1
1
0
0
1
Output:
IDFT seq: 1.000000 + (0.000000) i
1.000000 + (0.000302) i
1.000603 + (0.000605) i
0.000006 + (-0.002717) i
Result: IDFT of a given sequence is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 104
5. N - POINT DISCRETE FOUREIR TRANSFORM
Aim: Write a C program for N - Point Discrete Foureir Transform of a sequence
and compute using code composer studio V2( using simulators 64xx,67xx,6711)
software.
Program:
% N - Point Discrete Foureir Transform
#include<stdio.h>
#include<math.h>
#define pi 3.142857
main ()
{
int j, k, n, N, l;
float XKr[10],XKi[10],xni[10],xnr[10],t;
printf (" enter seq length: \n");
scanf ("%d", &l);
printf ("enter the real & imaginary terms of the sequence: \n");
for (j=0; j<l; j++)
{
scanf ("%f%f", &xnr[j], &xni[j]);
}
printf (" enter required length: \n");
scanf ("%d", &N);
if (l<N)
{
for(j=l;j<N;j++)
xnr[j]=xni[j]=0;
}
for(k=0;k<N;k++)
{
XKr[k]=0; XKi[k]=0;
for(n=0;n<N;n++)
{
t=2*pi*k*n/N;
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 105
XKr[k]=( XKr[k]+xnr[n]*cos(t) + xni[n]*sin(t)) ;
XKi[k]=( XKi[k]+ xni[n]*cos(t) - xnr[n]*sin(t)) ;
}
}
printf (" The %d Point DFT seq: N);
for(j=0;j<N;j++)
{
printf("%3.3f + (%3.3f) i\n",XKr[j],XKi[j]);
}
}
Input:
Enter seq length:
3
Enter the real & imaginary terms of the sequence:
1
0
1
0
1
0
enter required length:
4
Out put:
The 4 Point DFT seq:3.000 + (0.000) i
-0.001 + (-0.999) i
1.000 + (-0.001) i
0.002 + (1.004) i
Result: 4 - Point Discrete Foureir Transform of a sequence is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 106
6. TO GENERATE SUM OF SINUSOIDAL SIGNALS
Aim: Write a C program to generate sum of sinusoidal signals and compute using
code composer studio V2 (using simulators 64xx, 67xx, 6711) software.
Program:
%SUM OF TWO SINUSOIDALS
#include<stdio.h>
#include<math.h>
main ()
{
int w1, w2, t;
float a, b, c;
printf ("enter the w1 value:");
scanf ("%d", &w1);
printf ("enter the w2 value:");
scanf ("%d", &w2);
printf ("sum of two sinusoidal :");
for(t=-5;t<5;t++)
{
b=sin(w1*t);
c=sin (w2*t);
a=b+c;
printf ("\n%f", a);
}
}
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 107
Input:
Enter the w1 value: 5
Enter the w2 value: 5
Output:
Sum of two sinusoidal:
0.264704
-1.825891
-1.300576
1.088042
1.917849
0.000000
-1.917849
-1.088042
1.300576
1.825891
Result: samples of sum of sinusoidal signals are generated.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 108
PROGRAMS USING TMS 320C 6711 DSK
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 109
1. TO VERIFY LINEAR CONVOLUTION
Aim: Write a C program for linear convolution of two discrete sequences and
compute using TMS 320C 6711 DSK.
Program:
#include<stdio.h>
#include<math.h>
main ()
{
int x[20],h[20],y[20],N1,N2,n,m;
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N1);
printf ("enter the length of the sequence h (n) :");
scanf ("%d", &N2);
printf ("enter the sequence x (n) :");
for (n=0; n<N1; n++)
scanf ("%d", &x[n]);
printf ("enter the sequence h (n) :");
for (n=0; n<N2; n++)
scanf ("%d", &h[n]);
for (n=0; n<N1+N2-1; n++)
{
if (n>N1-1)
{
y[n]=0;
for(m=n-(N1-1);m<=(N1-1);m++)
y[n] =y[n] +x[m]*h [n-m];
}
else
{
y[n] =0;
for (m=0; m<=n; m++)
y[n] =y[n] +x[m]*h [n-m];
}
}
printf ("convolution of two sequences is y (n) :");
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 110
for (n=0; n<N1+N2-1; n++)
printf ("%d\t", y[n]);
}
Input:
Enter the length of the sequence x (n):4
Enter the length of the sequence h (n):3
Enter the sequence x (n):1 2 3 4
Enter the sequence h (n):5 6 7
Output:
Convolution of two sequences is y (n):5 16 34 52 45 28
Result: Linear convolution of two discrete sequences is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 111
2. TO VERIFY CIRCULAR CONVOLUTION
Aim: Write a C program for circular convolution of two discrete sequences and
compute using using TMS 320C 6711 DSK.
Program:
#include<math.h>
#define pi 3.14
main ()
{
int x[20],h[20],y[20],N1,N2,N,n,m,k;
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N1);
printf ("enter the length of the sequence h (n) :");
scanf ("%d", &N2);
printf ("enter the %d samples of sequence x (n):", N1);
for (n=0; n<N1; n++)
scanf ("%d", &x[n]);
printf ("enter the %d samples of sequence h (n): N2);
for (n=0; n<N2; n++)
scanf ("%d", &h[n]);
if (N1>N2)
{
N=N1;
for (n=N2; n<N; n++)
h[n]=0;
}
else
{
N=N2;
for(n=N1;n<N1;n++)
y[n]=0;
}
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 112
for(k=0;k<N;k++)
{
y[k]=0;
for (m=N-1; m>=0; m--)
{
if ((N+k-m)>=N)
{
y[k] =y[k] +x[m]*h [k-m];
}
else
y[k] =y[k] +x[m]*h [N+k-m];
}
}
printf ("\response is y (n) :");
for (n=0; n<N; n++)
printf ("\t%d", y[n]);
}
Input:
Enter the length of the sequence x (n):4
Enter the length of the sequence h (n):4
Enter the 4 samples of sequence x (n):2 1 2 1
Enter the 4 samples of sequence h (n):1 2 3 4
Output:
Response is y (n): 14 16 14 16
Result: Circular convolution of two discrete sequences is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 113
3. FINDING DFT OF A SEQUENCE
Aim: Write a C program for DFT of a sequence and compute using TMS 320C
6711 DSK.
Program:
%DISCRETE FOURIER TRANSFORM OF THE GIVEN SEQUENCE
#include<stdio.h>
#include<math.h>
#define pi 3.14
main ()
{
int x [20], N, n, k;
float Xre[20],Xim[20],Msx[20],Psx[20];
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N);
printf ("enter the %d samples of discrete sequence x (n): N);
for (n=0; n<N; n++)
scanf ("%d", &x[n]);
for(k=0;k<N;k++)
{
Xre[k]=0;
Xim[k]=0;
for(n=0;n<N;n++)
{
Xre[k]=Xre[k]+x[n]*cos(2*pi*n*k/N);
Xim[k]=Xim[k]+x[n]*sin(2*pi*n*k/N);
}
Msx[k]=sqrt(Xre[k]*Xre[k]+Xim[k]*Xim[k]);
Xim[k]=-Xim[k];
Psx[k]=atan(Xim[k]/Xre[k]);
}
printf ("discrete sequence is:");
for (n=0; n<N; n++)
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 114
printf ("\nx (%d) =%d", n, x[n]);
printf ("\nDFT sequence is :");
for(k=0;k<N;k++)
printf("\nx(%d)=%f+i%f",k,Xre[k],Xim[k]);
printf ("\nmagnitude is:");
for (k=0; k<N; k++)
printf ("\n%f", Msx[k]);
printf ("\nphase spectrum is:");
for(k=0;k<n;k++)
printf("\n%f",Psx[k]);
}
Input:
Enter the length of the sequence x (n):4
Enter the 4 samples of discrete sequence x (n):1 2 3 4
Output:
Discrete sequence is:
x (0) =1
x (1) =2
x (2) =3
x (3) =4
DFT sequence is :
x (0) =10.000000+i0.000000
x (1) =-2.007959+i1.995211
x (2) =-1.999967+i-0.012741
x (3) =-1.976076+i-2.014237
Magnitude is: Phase spectrum is:
0.000000 10.000000
-0.782214 2.830683
0.006371 2.000007
0.794961 2.821707
Result: DFT of a given sequence is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 115
4. FINDING IDFT OF A SEQUENCE
Aim: Write a C program for IDFT of a sequence and compute using TMS 320C
6711 DSK.
Program:
% Inverse Discrete Foureir Transform
#include<stdio.h>
#include<math.h>
#define pi 3.1428
main ()
{
int j, k, N, n;
float XKr[10],XKi[10],xni[10],xnr[10],t;
printf (" enter seq length: \n");
scanf ("%d", &N);
printf ("enter the real & imaginary terms of the sequence: \n");
for (j=0; j<N; j++)
{
scanf ("%f%f", &XKr[j], &XKi[j]);
}
for (n=0; n<N; n++)
{
xnr[n] =0; xni[n] =0;
for(k=0;k<N;k++)
{
t=2*pi*k*n/N;
xnr[n]=( xnr[n]+XKr[k]*cos(t) - XKi[k]*sin(t)) ;
xni[n]=( xni[n]+XKr[k]*sin(t) + XKi[k]*cos(t)) ;
}
xnr[n]=xnr[n]/N;
xni[n]=xni[n]/N;
}
printf("IDFT seq:");
for(j=0;j<N;j++)
{
printf("%f + (%f) i\n",xnr[j],xni[j]);
}
}
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 116
Input:
Enter seq length:
4
Enter the real & imaginary terms of the sequence:
3
0
0
-1
1
0
0
1
Output:
IDFT seq: 1.000000 + (0.000000) i
1.000000 + (0.000302) i
1.000603 + (0.000605) i
0.000006 + (-0.002717) i
Result: IDFT of a given sequence is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 117
5. N - POINT DISCRETE FOUREIR TRANSFORM
Aim: Write a C program for N - Point Discrete Foureir Transform of a sequence and
compute using TMS 320C 6711 DSK.
Program:
% N - Point Discrete Foureir Transform
#include<stdio.h>
#include<math.h>
#define pi 3.142857
main ()
{
int j, k, n, N, l;
float XKr[10],XKi[10],xni[10],xnr[10],t;
printf (" enter seq length: \n");
scanf ("%d", &l);
printf ("enter the real & imaginary terms of the sequence: \n");
for (j=0; j<l; j++)
{
scanf ("%f%f", &xnr[j], &xni[j]);
}
Printf (" enter required length: \n");
Scanf ("%d", &N);
if (l<N)
{
for(j=l;j<N;j++)
xnr[j]=xni[j]=0;
}
for(k=0;k<N;k++)
{
XKr[k]=0; XKi[k]=0;
for(n=0;n<N;n++)
{
[
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 118
t=2*pi*k*n/N;
XKr[k]=( XKr[k]+xnr[n]*cos(t) + xni[n]*sin(t)) ;
XKi[k]=( XKi[k]+ xni[n]*cos(t) - xnr[n]*sin(t)) ;
}
}
Printf (" The %d Point DFT seq: N);
for(j=0;j<N;j++)
{
printf("%3.3f + (%3.3f) i\n",XKr[j],XKi[j]);
}
}
Input:
Enter seq length:
3
Enter the real & imaginary terms of the sequence:
1
0
1
0
1
0
Enter required length:
4
Out put:
The 4 Point DFT seq: 3.000 + (0.000) i
-0.001 + (-0.999) i
1.000 + (-0.001) i
0.002 + (1.004) i
Result: 4 - Point Discrete Foureir Transform of a sequence is computed.
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 119
6. TO GENERATE SUM OF SINUSOIDAL SIGNALS
Aim: Write a C program to generate sum of sinusoidal signals and compute using
TMS 320C 6711 DSK.
Program:
%SUM OF TWO SINUSOIDALS
#include<stdio.h>
#include<math.h>
main ()
{
int w1, w2, t;
float a, b, c;
printf ("enter the w1 value :");
scanf ("%d", &w1);
printf ("enter the w2 value :");
scanf ("%d", &w2);
printf ("sum of two sinusoidal :");
for(t=-5;t<5;t++)
{
b=sin(w1*t);
c=sin (w2*t);
a=b+c;
printf ("\n%f", a);
}
}
ELECTRONICS & COMMUNICATION ENGINEERING
DIGITAL SIGNAL PROCESSING LAB 120
Input:
Enter the w1 value: 5
Enter the w2 value: 5
Output:
Sum of two sinusoidal:
0.264704
-1.825891
-1.300576
1.088042
1.917849
0.000000
-1.917849
-1.088042
1.300576
1.825891
Result: Samples of sum of sinusoidal signals are obtained.
ELECTRONICS & COMMUNICATION ENGINEERING
121
REFERENCES
1. Rabiner, Lawrence R. & Gold, Bernard, Theory and application of digital
signal processing, Prentice-Hall (1975).
2. Proakis, J.G. and Manolakis, D.G., Digital signal processing: principles,
algorithms and applications, Macmillan (1996).
3. A. V. Oppenheim and R. W. Schafer, Digital Signal Processing, Prentice-Hall,
(1975).
4. Sanjit K.Mitra, Digital Signal Processing, A Computer based approach, Tata
McGraw-Hill, (1998).
5. Vinay K. Ingle and John G. Proakis, Digital Signal Processing using
MATLAB, BookWare Companion Series,(2001).
6. Rudra Pratap, Getting Started With MATLAB: A Quick Introduction for
Scientists and Engineers, Oxford University Press.
7. Avtar Singh and S.Srinivasan, Digital Signal Processing Implementations,
Penram International Publishing (India) Pvt. Ltd.