0% found this document useful (0 votes)
53 views

DSP Lab Record

The document describes performing linear convolution of two sequences using MATLAB. It begins with introducing linear convolution and its properties. The algorithm involves getting the sample values and lengths of the input sequences x[n] and h[n], determining the time vectors, and calculating the output sequence y[n] using the convolution expression. An example convolution calculation is shown. The procedure then explains running the MATLAB program to take input, perform the convolution, and display the output graphically.

Uploaded by

Likhita Uttam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

DSP Lab Record

The document describes performing linear convolution of two sequences using MATLAB. It begins with introducing linear convolution and its properties. The algorithm involves getting the sample values and lengths of the input sequences x[n] and h[n], determining the time vectors, and calculating the output sequence y[n] using the convolution expression. An example convolution calculation is shown. The procedure then explains running the MATLAB program to take input, perform the convolution, and display the output graphically.

Uploaded by

Likhita Uttam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 97

DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT –01
INTRODUCTION TO MATLAB
AIM :
To generate and plot sum of sinusoidal signals using MATLAB.

EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:

Sinusoidal signal:
A signal, which is continuous in nature is known as continuous signal. General format of a
sinusoidal signal is
x(t)=Asin(ωt+ϕ)

Here,
A = amplitude of the signal
ω = Angular frequency of the signal Measured in radians
φ = Phase angle of the signal Measured in radians
The tendency of this signal is to repeat itself after certain period of time, thus is called periodic
signal. The time period of signal is given as;
T=2πω

The diagrammatic view of sinusoidal signal is shown below.

1
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

A continuous-time signal x(t) is said to be periodic with period T if it satisfy the condition

x (t+T) = x(t) for all t -∞<t

A signal is periodic if the above condition is not satisfied for at least one value of T.

The smallest value of T that satisfies the above condition is known as fundamental period.

Complex exponential and sinusoidal signals are examples for continuous time periodic signals.
Consider a sinusoidal signal.

x(t)=Asin(wt+θ)

Where A is the amplitude, w is the frequency in radians per second (rad/sec), and θ the phase
in radians. The frequency f0 in hertz is given by f0 = w /2π or periodic signal we have

X(t+T)=x(t)

For x(t)=Asin(wt+θ)

X (t+T) = Asin [w(t+T)+ θ)]

= Asin[wt+wT+θ]

From the Above equations ,

wT = 2π , T =2π/ w

Thus the sinusoidal is periodic with period 2π/ w.

Sum of Sinusoidal Signals:


The sum of two periodic signals x1(t) and x2(t) with periods T1 and T2 respectively may or may
not be periodic, then the ratio T1/T2 can be written as the ratio a/b of two integers a and b. If
T1/T2 = a/b, then bT1 = aT2, and since a and b are integers, x1(t) and x2(t) are periodic with
period bT1. If a and b are co prime (i. e. a and b have no common integer factors other than 1)
then T = bT1 is the fundamental period of the sum of two signals.

2
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

ALGORITHM :
Step : 1 Get/Read the frequencies of sinusoidal signals.

Step : 2 Get/Read the amplitudes of sinusoidal signals.

Step : 3 Generate sinusoidal signals.

Step : 4 Add the sinusoidal signals.

Step : 5 Plot the graph of all sinusoidal signals and sum signal.

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.

PROGRAM :
clc;
clear all;
close all;
t=0:0.01:3;
freq1 = input('Frequency of first signal :');
freq2 = input('Frequency of second signal :');
freq3 = input('Frequency of third signal :');
amp1 = input('Amplitude of first signal :');
amp2 = input('Amplitude of second signal :');
amp3 = input('Amplitude of third signal :');
sig1 = amp1 * sin(2*pi*freq1*t);
sig2 = amp2 * sin(2*pi*freq2*t);
sig3 = amp3 * sin(2*pi*freq3*t);

3
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

final_sig = sig1 + sig2 + sig3;


subplot(4,1,1);
plot(t,sig1);
xlabel('Time');
ylabel('Amplitude');
title('Sine 1');
subplot(4,1,2);
plot(t,sig2);
xlabel('Time');
ylabel('Amplitude');
title('Sine 2');
subplot(4,1,3);
plot(t,sig1);
xlabel('Time');
ylabel('Amplitude');
title('Sine 3');
subplot(4,1,4);
plot(t,final_sig);
xlabel('Time');
ylabel('Amplitude');
title('Resultant signal');

4
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Input :
Frequency of 1st signal: 5

Amplitude of 1st signal : 10

Frequency of 1st signal: 15

Amplitude of 1st signal : 2

Frequency of 1st signal: 4

Amplitude of 1st signal : 6

Output :

5
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Result:
Sum of Sinusoidal Signals is performed using MATLAB Software.

6
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

7
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO – 2
LINEAR CONVOLUTION OF TWO SEQUENCES
AIM :
To perform the linear convolution of given sequences using MATLAB.

EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:

Convolution
Convolution is a mathematical operation used to express the relation between input and
output of an LTI system. It relates input, output and impulse response of an LTI system as
y (t) = x(t) * h(t)
Where y (t )= output of LTI
x (t) = input of LTI
h (t) = impulse response of LTI
There are two types of convolutions:
● Continuous convolution
● Discrete convolution

Continuous Convolution

y(t) = x(t) * h(t)

Output signal is obtained by convolving input signal and impulse response.

8
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Discrete Convolution

y[n] = x[n] * h[n]

Output signal is obtained by convolving input signal and impulse response.


By using convolution we can find zero state response of the system.
Limits of Convoluted Signal
If two signals are convoluted then the resulting convoluted signal has following range:
Sum of lower limits < t < sum of upper limits
The linear convolution (or correlation) of two sequences of lengths P and Q, respectively, will
produce a third sequence of length P + Q − 1. 
PROPERTIES OF LINEAR CONVOLUTION
x(n) = Excitation Input signal

y(n) = Output Response

h(n) = Unit sample response

1. Commutative Law: (Commutative Property of Convolution)

x(n) * h(n) = h(n) * x(n)

2. Associate Law: (Associative Property of Convolution) 

[ x(n) * h1(n) ] * h2(n) = x(n) * [ h1(n) * h2(n) ]

3. Distribute Law: (Distributive property of convolution) 

x(n) * [ h1(n) + h2(n) ] = x(n) * h1(n) + x(n) * h2(n)

Causality and stability are also properties of Linear Convolution.

9
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Algorithm :
Step : 1 Get/Read the samples of x[n] to x.

Step : 2 Get/Read the samples of h[n] to h.

Step : 3 Get/Read the length of x to L.

Step : 4 Get/Read the length of h to M.

Step : 5 Get/Read the starting time of x[n] to N1.

Step : 6 Get/Read the starting time of h[n] to N3.

Step : 7 Determine N2= N1+L-1 and N4= N3+M-1.

Step : 8 Define time vector n as N1:N2.

Step : 9 Plot the Graph of x[n].

Step : 10 Define time vector n as N3:N4.

Step : 11 Plot the Graph of h[n].

Step : 12 Define time vector n as N1+N3:N2+N4.

Step : 13 Determine the convolution of x and h using

y[n] = ∑ X(k) H(n-k)

Use two for loops for the above expression

Step : 14 Plot the graph of y[n].

10
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

THEORITICAL CALCULATIONS:

Input sequence x[n]: [2 3 4 2]

Impulse Response h[n]: [3 4 1 2]

y[n] = x[n] * h[n]

Linear convolution using Tabulation method:

X[n]

2 3 4 2

3 6 9 12 6

h[n] 4 8 12 16 8

1 2 3 4 2

2 4 6 8 4

y[n] = [(6) , (8+9) , (2+12+12) , (4+3+16+6) , (6+4+8) , (8+2) , (4)]

Resultant output sequence is

y[n] = [6 17 26 29 18 10 4]

11
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.

PROGRAM :
clc;

clear all;

close all;

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

n1= input('Enter the position of 1st sample of x[n]');

h = input('Enter the sequence h[n] :');

n3= input('Enter the position of 1st sample of h[n]');

n2=length(x);

n4=length(h);

n5=n1+n2-1;

n6=n3+n4-1;

y=conv(x,h);

n=n1:n5;

subplot(3,1,1);

stem(n,x);
12
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

xlabel('Time');

ylabel('Amplitude');

title('Input sequence x[n]')

n=n3:n6;

subplot(3,1,2);

stem(n,h);

xlabel('Time');

ylabel('Amplitude');

title('Impulse responce h[n]');

n=n1+n3:n5+n6;

subplot(3,1,3);

stem(n,y);

xlabel('Time');

ylabel('Amplitude');

title('output sequence y[n]');

disp(y);

13
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Input :
Enter the sequence x[n] : [2 3 4 2]

Enter the position of 1st sample of x[n] : -1

Enter the sequence h[n] : [3 4 1 2]

Enter the position of 1st sample of h[n] : 0

Output :
Linear convolution of x[n] and h[n] is

y[n] = [6 17 26 29 18 10 4]

14
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

15
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
Linear convolution of given sequences is performed and output is verified theoretically
and practically using MATLAB.

16
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

17
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO – 3
CIRCULAR CONVOLUTION OF TWO SEQUENCE
AIM :
To perform the circular convolution of given sequences using MATLAB.

EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:
x[n] and h[n] are two finite sequences of length N with DFTs denoted by X[k] and H[k],
respectively. Let us form the product

W[k] = X[k]H[k],

and determine the sequence w[n] of length N for which the DFT is W[k].

First, extend x[n] and h[n] to periodic sequences with period N, x h ˜[n] and [n], respectively. ˜
Then, the periodic convolution of x h ˜[n] and [n] corresponds to multiplication of the
corresponding periodic sequences of Fourier series coefficients.

w[n] = w˜[n]RN [n]


N −1
¿ ∑ ❑ x [m]h[n−m]
m =0

N −1
¿ ∑ ❑ x [m] h[((n−m))N ]
m =0

This operation is called circular convolution and is denoted as

18
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Algorithm :
Step : 1 Get/Read the samples of x[n] to x.

Step : 2 Get/Read the samples of h[n] to h.

Step : 3 Get/Read the length of x to L.

Step : 4 Get/Read the length of h to M.

Step : 5 Find the maximum of both signals and store it to N.

Step : 6 If x>h pad zeros to h else pad zeros to x.

Step : 7 Perform circular convolution between x and h and store it to y.

Step : 8 Define time vector n as 0:N-1.

Step : 9 Plot the Graph of x[n].

Step : 10 Define time vector n as 0:N-1.

Step : 11 Plot the Graph of h[n].

Step : 12 Define time vector n as 0:N-1.

Step : 13 Plot the graph of y[n].

19
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

THEORITICAL CALCULATIONS:

20
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window..

PROGRAM :
clc;
clear all;
close all;
x=input('Enter input sequence x[n] :');
h=input('Enter the sequence h[n] :');
n1=length(x);
n2=length(h);
N=max(n1,n2);
if n1>n2
    h=[h,zeros(1,n1-n2)];
else
    x=[x,zeros(1,n2-n1)];
end
y=cconv(x,h,N);
 
n=0:N-1;
subplot(3,1,1);

21
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

stem(n,x);
xlabel('n----->');
ylabel('Amplitude');
title('Input sequence x[n]:');
n=0:N-1
subplot(3,1,2);
stem(n,h);
xlabel('n----->');
ylabel('Amplitude');
title('Impulse sequence h[n]:');
n=0:N-1;
subplot(3,1,3);
stem(n,y);
xlabel('n----->');
ylabel('Amplitude');
title('Output sequence y[n]:');
disp(y);

22
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Input :

Output :
Circular convolution of x[n] and h[n] is

23
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
Circular convolution of given sequences is performed and output is verified theoretically
and practically using MATLAB.

24
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO – 4
FAST FOURIER TRANSFORM OF TWO SEQUENCE
AIM :
To obtain the fast fourier transform of given sequence using MATLAB Software.

EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:
DFT:

The discrete Fourier transform (DFT) is the primary transform used for numerical computation
in digital signal processing. It is very widely used for spectrum analysis, fast convolution, and
many other applications. The DFT transforms NN discrete-time samples to the same number of
discrete frequency samples, and is defined as

X(k)=∑n=0N−1x(n)e−(i2πnkN)X k n N 1 0 x n 2 n k N

The DFT is widely used in part because it can be computed very efficiently using fast Fourier
transform (FFT) algorithms.

IDFT

The inverse DFT (IDFT) transforms NN discrete-frequency samples to the same number of


discrete-time samples. The IDFT has a form very similar to the DFT,

x(n)=1N∑k=0N−1X(k)ei2πnkNx n 1 N k N 1 0 X k 2 n k N

and can thus also be computed efficiently using FFTs.

25
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Algorithm :
Step : 1 Get/Read the samples of x[n] to x.

Step : 2 Get/Read the length of sequence to n1.

Step : 3 Read the length of the sequence x[n] to n2.

Step : 4 Define time vector n as 0:n2-1.

Step : 5 Store n2-n1 to N

Step : Plot input sequence x[n].

Step : 7 if n1>n2 then pad zeros to x from 1 to N

Step : 8 Now find DFT using FFT with inbuilt function fft.

Step : 9 Plot the real and imaginary part of fft sequence.

Step : 10 Define time vector n as 0:N-1.

Step : 11 Now find IDFT using IFFT with inbuilt function ifft.

Step : 13 Plot the IFFT sequence.

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.

26
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

THEORITICAL CALCULATIONS:

27
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

PROGRAM :
clc;
clear all;
close all;
x=input('Enter the sequence x[n]:');
n1=input('Enter the legth of sequence s[n]:');
n2=length(x);
N=n2-n1;
n=0:n2-1;
subplot(4,1,1);
stem(n,x);
xlabel('n----------->');
ylabel('Amplitude');
title('Input sequence x[n]');
disp('The input sequence is:');
disp(x);
if(n1>n2)
    x=[x,zeros(1,N)];
end
 y=fft(x,n1);
disp('FFT of input sequence is');
disp(y);
n = 0:n1-1;
subplot(4,1,2);
stem(n,real(y));
xlabel('n------->');
ylabel('Amplitude');
title('(REAL part) FFt of sequence');
 subplot(4,1,3);
stem(n,imag(y));

28
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

xlabel('n------->');
ylabel('Amplitude');
title('(IMAG part) FFt of sequence');
X=ifft(y,n1)
disp('IFFt of sequence is');
disp(i);
n = 0:n1-1;
subplot(4,1,4);
stem(n,X);
xlabel('n------->');
ylabel('Amplitude');
title('IFFt of sequence');

29
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Input :

Output :

30
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
DFT and IDF of given sequences is performed and output is verified theoretically and
practically using MATLAB

31
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

32
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO – 5
FREQUENCY RESPONSE OF SYSTEM IN DIFFERENTIAL
EQUATION FORM
Aim:
To plot & observe the frequency response of a system given in difference equation form.

EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:

Given an LTI difference equation describing a filter, it is easy to analytically find an expression
for the frequency response. Recall that if the input x is a complex exponential, then the
output y will be the same complex exponential scaled by the frequency response evaluated at
the frequency of the complex exponential.

Consider a filter given by

a1 y(n) + a2 y(n-1) + a3 y(n-2) = b1 x(n) + b2 x(n-1) + b3 x(n-2).

Let the input x be given by, for all integers n,

x(n) = e jωn.

Then the output y must be given by, for all integers n,

y(n) = H(ω) e jωn.

where H(ω) is the frequency response evaluated at the frequency ω. Plugging the form of the
input and output into the difference equation we get

a1 H(ω) e jωn + a2 H(ω) e jω(n-1) + a3 H(ω) e jω(n-2)


= b1 e jωn + b2 e jω(n-1) + b3 e jω(n-2).

This can be factored as follows,

H(ω) e jωn (a1 + a2 e -jω + a3 e -2jω)
= e jωn (b1 + b2 e -jω + b3 e -2jω).

This can be solved for the frequency response,

33
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

H(ω) = e jωn (b1 + b2 e -jω + b3 e -2jω)/ e jωn (a1 + a2 e -jω + a3 e -2jω).

This form of the frequency response can be generalized to LTI difference equations with an
arbitrary number of terms.

Algorithm :
Step : 1 Get/Read the numerator coefficients to b.

Step : 2 Get/Read the denominator coefficients to a.

Step : 3 Define time vector w as –pi:0.01:pi.

Step : 4 Find out the frequency response using function freqz and store it into g.

Step : 5 Plot the magnitude frequency response.

Step : 6 Plot the Phase frequency response.

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.

PROGRAM :
clc;

clear all;
close all;
b=input('Enter the numerator coefficients: ');
a=input('Enter the denominator coefficients: ');

34
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

w=-pi:0.01:pi;
g=freqz(b,a,w);
subplot(2,1,1);
plot(w,abs(g));
xlabel('Normalized Frequency');
ylabel('Magnitude');
title('Magnitude-Frequency Response:');
subplot(2,1,2);
plot(w,angle(g));
xlabel('Normalized Frequency');
ylabel('Phase');
title('Phase-Frequency Response');

Input :

35
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Output :

RESULT:

36
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Frequency response of differential equation form is performed and output is verified


theoretically and practically using MATLAB.

37
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO – 6

38
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

DETERMINATION OF POWER SPECTRUM


Aim:
To generate power spectral density for a given input signal using MATLAB
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:
A Power Spectral Density (PSD) is the measure of signal's power content versus
frequency. A PSD is typically used to characterize broadband random signals. The amplitude of
the PSD is normalized by the spectral resolution employed to digitize the signal.

Consider a WSS random process X(t) with autocorrelation function RX(τ). We define the
Power Spectral Density (PSD) of X(t) as the Fourier transform of RX(τ). We show the PSD of X(t),
by SX(f). More specifically, we can write

SX(f)=F{RX(τ)}=∫∞ ∫ ❑ R X (τ)e−2 jπfτ dτ ,


−∞

From this definition, we can conclude that RX(τ) can be obtained by the inverse Fourier
transform of SX(f). That is

RX(τ)=F−1{SX(f)}= ∫ ❑ S X (f )e 2 jπfτ df .
−∞

As we have seen before, if X(t) is a real-valued random process, then RX(τ) is an even, real-
valued function of τ. From the properties of the Fourier transform, we conclude that SX(f) is
also real-valued and an even function of f. Also, from what we will discuss later on, we can
conclude that SX(f) is non-negative for all f.

1.Sx(−f)=SX(f), for all f;

2.Sx(f)≥0, for all f.

Before going any further, let's try to understand the idea behind the PSD. To do so, let's choose
τ=0. We know that expected power in X(t) is given by
∞ ∞

E[ X (t) ]=RX(0)= ∫ ❑ S X (f )e 2 jπf 0 df


2
=∫ ∫ ❑ S X (f )df .
−∞ −∞

39
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

We conclude that the expected power in X(t) can be obtained by integrating the PSD of X(t).
This fact helps us to understand why SX(f) is called the power spectral density. In fact, as we will
see shortly, we can find the expected power of X(t) in a specific frequency range by integrating
the PSD over that specific range.

The expected power in X(t)X(t) can be obtained as



2
E[ X (t) ]=RX(0)= ∫ ❑ S X (f )df .
−∞

Algorithm :
Step : 1 Get/Read the samples of x[n] to N.

Step : 2 Get/Read the frequency to f.

Step : 3 Define a for loop for 1 to N and store sinusoidal signal for different N values to X.

Step : 4 Plot the input signal X(n).

Step : 5 Find the Auto Correlation using sum=sum+(X(k)*X(k+n-1)) and store it to y(n).

Step : 7 Plot Auto Correlation signal y.

Step : 7 Find the fft of the signal y and plot the magnitude and phase Response.

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.

40
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

PROGRAM :
clc;
clear all;
close all;
N=input('Enter the N value: ');
f=input('Enter the Frequency: ');
for n=1:N
    X(n)=sin((2*pi*f*n)/N);
end
subplot(4,1,1);
plot(X);
title('Input Sequence');
xlabel('N');
ylabel('Amplitude');
for n=1:1:N
    sum=0;
   for k=1:1:N-n+1
       sum=sum+(X(k)*X(k+n-1));
   end
   y(n)=sum;
end
display(y(n));
subplot(4,1,2);
plot(y);
title('Auto Correlation');
xlabel('Time');
ylabel('Amplitude');

41
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

n=0:1:N-1;
y1=fft(y);
subplot(4,1,3);
plot(n,abs(y1));
title('PSD Magnitude Response');
xlabel('Frequency');
ylabel('Amplitude');
subplot(4,1,4);
plot(n,angle(y1));
title('PSD Phase Response');
xlabel('Frequency');
ylabel('Amplitude');

42
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Input :

Output :

43
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
Hence the power density spectrum of given input signal is observed.

44
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

45
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO – 7
DESIGN OF IIR LOW PASS FILTER
Aim:
To design an IIR low pass filter using Butterworth & Chebyshev approximation.

EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:
BUTTERWORTH FILTER :-

The Butterworth filter has a maximally flat response that is, no passband ripple and roll-
off of minus 20db per pole. It is “flat maximally magnitude” filters at the frequency of jω= 0, as
the first 2N - 1 derivatives of the transfer function when jω = 0 are equal to zero [5]. The phase
response of the Butterworth filter becomes more nonlinear with increasing N. This filter is
completely defined mathematically by two parameters; they are cut off frequency and number
of poles.

The magnitude squared response of low pass Butterworth filter is given by

Filter Selectivity,

Attenuation,

CHEBYSHEV FILTER :-

46
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

The absolute difference between the ideal and actual frequency response over the entire pass
band is minimized by Chebyshev Type I filter by incorporating equal ripple in the pass band.
Stop band response is maximally flat. The transition from pass band to stop band is more rapid
than for the Butterworth filter. The magnitude squared Chebyshev response is:

Algorithm :
Step : 1 Get/Read the sampling frequency.

Step : 2 Get/Read the pass band frequency and multiply the pass band frequency by 2 and
divide by sampling frequency.

Step : 3 Get/Read the stop band frequency and multiply the stop band frequency by 2 and
divide by sampling frequency.

Step : 4 Get/Read the pass band attenuation an pass band attenuation.

Step : 5 create a Butterworth filter using the inbuilt function buttord and butter.

Step : 7 Plot magnitude and phase response of butterworth filter.

Step : 8 create a chebyshev filter using the inbuilt function cheb1ord and cheby1.

Step : 9 Plot magnitude and phase response of chebyshev filter.

47
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.

PROGRAM :
clc;
clear all;
close all;
fs=input('enter the sampling frequency');
wpa=input('enter the passband frequency');
wp=2*wpa/fs;
wsa=input('enter the stopband frequency');
ws=2*wsa/fs;
rp=input('enter the passband attenuation');
rs=input('enter the stopband attenuation');
[n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,w]=freqz(b,a,w);

48
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

m=20*log10(abs(h));
an=angle(h);
subplot(3,2,1);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('butter magn response');
grid on;
subplot(3,2,2);
plot(w/pi,an);
xlabel('normalized frequency');
ylabel('phase');
title('butter phase response');
grid on;
[n,wp]=cheb1ord(wp,ws,rp,rs);
[b,a]= cheby1(n,5,wp);
w=0:0.01:pi;
[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,3);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('cheby1 magn response');
grid on;
subplot(3,2,4);
plot(w/pi,an);

49
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

xlabel('normalized frequency');
ylabel('phase');
title('cheby1 phase response');
grid on;
[n,ws]=cheb2ord(wp,ws,rp,rs);
[b,a]= cheby2(n,5,ws);
w=0:0.01:pi;
[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,5);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('cheby2 magn response');
grid on;
subplot(3,2,6);
plot(w/pi,an);
xlabel('normalized frequency');
ylabel('phase');
title('cheb2 phase response');
grid on;

50
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Input :

Output :

51
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
Hence an IIR low pass filter is designed and its response is observed.

52
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

53
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO – 8
DESIGN OF IIR HIGH PASS FILTER
Aim:
To design an IIR high pass filter using Butterworth & Chebyshev approximation.

EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:
The infinite impulse response (IIR) filter is a recursive filter in that the output from the filter is
computed by using the current and previous inputs and previous outputs.
Because the filter uses previous values of the output, there is feedback of the output in the
filter structure. The design of the IIR filter is based on identifying the pulse transfer function
G(z) that satisfies the requirements of the filter specification. This can be undertaken either by
developing an analogue prototype and then transforming it to the pulse transfer function, or by
designing directly in digital.

BUTTERWORTH FILTER :-

The Butterworth filter has a maximally flat response that is, no passband ripple and roll-
off of minus 20db per pole. It is “flat maximally magnitude” filters at the frequency of jω= 0, as
the first 2N - 1 derivatives of the transfer function when jω = 0 are equal to zero [5]. The phase
response of the Butterworth filter becomes more nonlinear with increasing N. This filter is
completely defined mathematically by two parameters; they are cut off frequency and number
of poles.

The magnitude squared response of low pass Butterworth filter is given by

Filter Selectivity,

54
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Attenuation,

CHEBYSHEV FILTER :-

The absolute difference between the ideal and actual frequency response over the entire pass
band is minimized by Chebyshev Type I filter by incorporating equal ripple in the pass band.
Stop band response is maximally flat. The transition from pass band to stop band is more rapid
than for the Butterworth filter. The magnitude squared Chebyshev response is:

Algorithm :
Step : 1 Get/Read the sampling frequency.

Step : 2 Get/Read the pass band frequency and multiply the pass band frequency by 2 and
divide by sampling frequency.

Step : 3 Get/Read the stop band frequency and multiply the stop band frequency by 2 and
divide by sampling frequency.

Step : 4 Get/Read the pass band attenuation an pass band attenuation.

55
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Step : 5 create a Butterworth filter using the inbuilt function buttord and butter.

Step : 7 Plot magnitude and phase response of butterworth filter.

Step : 8 create a chebyshev filter using the inbuilt function cheb1ord and cheby1.

Step : 9 Plot magnitude and phase response of chebyshev filter.

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.

PROGRAM :
clc;
clear all;
close all;
fs=input('enter the sampling frequency');
wpa=input('enter the passband frequency');
wp=2*wpa/fs;
wsa=input('enter the stopband frequency');
ws=2*wsa/fs;
rp=input('enter the passband attenuation');
rs=input('enter the stopband attenuation');
[n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn,'high');
w=0:0.01:pi;

56
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,1);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('butter magn response');
grid on;
subplot(3,2,2);
plot(w/pi,an);
xlabel('normalized frequency');
ylabel('phase');
title('butter phase response');
grid on;
[n,wp]=cheb1ord(wp,ws,rp,rs);
[b,a]= cheby1(n,5,wp,'high');
w=0:0.01:pi;
[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,3);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('cheby1 magn response');
grid on;
subplot(3,2,4);
plot(w/pi,an);
xlabel('normalized frequency');
57
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

ylabel('phase');
title('cheby1 phase response');
grid on;
[n,ws]=cheb2ord(wp,ws,rp,rs);
[b,a]= cheby2(n,5,ws,'high');
w=0:0.01:pi;
[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,5);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('cheby2 magn response');
grid on;
subplot(3,2,6);
plot(w/pi,an);
xlabel('normalized frequency');
ylabel('phase');
title('cheb2 phase response');
grid on;

58
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Input :

Output :

59
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
Hence an IIR high pass filter is designed and its response is observed.

60
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

61
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO – 9
DESIGN OF FIR LOW PASS FILTER
Aim:
To design an FIR low pass filter using windowing technique.

EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:
In digital signal processing, an FIR is a filter whose impulse response is of finite period, as
a result of it settles to zero in finite time. This is often in distinction to IIR filters, which can have
internal feedback and will still respond indefinitely. The impulse response of an Nth order
discrete time FIR filter takes precisely N+1 samples before it then settles to zero. FIR filters
are most popular kind of filters executed in software and these filters can be continuous time,
analog or digital and discrete time. Special types of FIR filters are namely, Boxcar, Hilbert
Transformer, Differentiator, Lth-Band and Raised-Cosine.

FIR filter design based on windows is simple and robust, however, it is not optimal. The
resulting pass-band and stop-band parameters are equal even though often the specification is
more strict in the stop band than in the pass band unnecessary high accuracy in the pass band.
The ripple of the window is not uniform (decays as we move away from discontinuity points
according to side-lobe pattern of the window) by allowing more freedom in the ripple
behaviour we may be able to reduce filter’s order and hence its complexity.

Algorithm :
Step : 1 Get/Read the sampling frequency.

62
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Step : 2 Get/Read the pass band frequency and multiply the pass band frequency by 2 and
divide by sampling frequency.

Step : 3 Get/Read the stop band frequency and multiply the stop band frequency by 2 and
divide by sampling frequency.

Step : 4 Get/Read the pass band attenuation an pass band attenuation.

Step : 5 create a rectangular window filter using the inbuilt function rectwin.

Step : 7 Plot magnitude and phase response of rectangular window filter.

Step : 8 create a hamming window filter using the inbuilt function hamming.

Step : 9 Plot magnitude and phase response of hamming window filter.

Step : 10 create a hanning window filter using the inbuilt function hann.

Step : 11 Plot magnitude and phase response of hanning window filter.

Step : 12 create a barlett window filter using the inbuilt function barlett.

Step : 13 Plot magnitude and phase response of barlett window filter.

Step : 14 create a blackman window filter using the inbuilt function blackman.

Step : 15 Plot magnitude and phase response of blackman window filter.

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.

PROGRAM :

63
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

clc;
clear all;
close all;
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
f=input('enter the sampling frequency');
wp=2*(fp/f);
ws=2*(fs/f);
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*((fs-fp)/f);
n=ceil(num/den);
%n=abs(n);
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
else
    n1=n+1;
end
%rectangle
y1=rectwin(n1);
wn=(wp+ws)/2;
b=fir1(n,wn,'low',y1);
w=0:0.01:pi;
[h1,w]=freqz(b,1,w);
magnitude1=(abs(h1));
phase1=angle(h1);
%hamming
y2=hamming(n1);
64
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

b=fir1(n,wp,'low',y2);
w=0:0.01:pi;
[h2,w]=freqz(b,1,w);
magnitude2=(abs(h2));
phase2=angle(h2);
%hanning
y3=hann(n1);
b=fir1(n,wp,'low',y3);
w=0:0.01:pi;
[h3,w]=freqz(b,1,w);
magnitude3=(abs(h3));
phase3=angle(h3);
%barlett
y4=bartlett(n1);
b=fir1(n,wp,'low',y4);
w=0:0.01:pi;
[h4,w]=freqz(b,1,w);
magnitude4=(abs(h4));
phase4=angle(h4);
%blackman
y5=blackman(n1);
b=fir1(n,wp,'low',y5);
w=0:0.01:pi;
[h5,w]=freqz(b,1,w);
magnitude5=(abs(h5));
phase5=angle(h5);
%kaiser
y6=kaiser(n1);
b=fir1(n,wp,'low',y6);
w=0:0.01:pi;
65
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

[h6,w]=freqz(b,1,w);
magnitude6=(abs(h6));
phase6=angle(h6);
subplot(3,2,1);
plot(w/pi,magnitude1);
xlabel('normalized frequency');
ylabel('magnitude');
title('rectangular window');
subplot(3,2,2);
plot(w/pi,magnitude2);
xlabel('normalized frequency');
ylabel('magnitude');
title('hamming window');
subplot(3,2,3);
plot(w/pi,magnitude3);
xlabel('normalized frequency');
ylabel('magnitude');
title('hanning window');
subplot(3,2,4);
plot(w/pi,magnitude4);
xlabel('normalized frequency');
ylabel('magnitude');
title('barlett window');
subplot(3,2,5);
plot(w/pi,magnitude5);
xlabel('normalized frequency');
ylabel('magnitude');
title('blackman window');
subplot(3,2,6);
plot(w/pi,magnitude6);
66
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

xlabel('normalized frequency');
ylabel('magnitude');
title('kaiser window');
figure;
subplot(3,2,1);
plot(w/pi,phase1);
xlabel('normalized frequency');
ylabel('phase');
title('rectangular window');
subplot(3,2,2);
plot(w/pi,phase2);
xlabel('normalized frequency');
ylabel('phase');
title('hamming window');
subplot(3,2,3);
plot(w/pi,phase3);
xlabel('normalized frequency');
ylabel('phase');
title('hanning window');
subplot(3,2,4);
plot(w/pi,phase4);
xlabel('normalized frequency');
ylabel('phase');
title('barlett window');
subplot(3,2,5);
plot(w/pi,phase5);
xlabel('normalized frequency');
ylabel('phase');
title('blackman window');
subplot(3,2,6);
67
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

plot(w/pi,phase6);
xlabel('normalized frequency');
ylabel('phase');
title('kaiser window');

Input :

Output :

68
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
Hence an FIR Low pass filter is designed and its response is observed.

69
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

70
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO – 10
DESIGN OF HIGH LOW PASS FILTER
Aim:
To design an FIR High pass filter using windowing technique.

EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.

THEORY:
In digital signal processing, an FIR is a filter whose impulse response is of finite period, as
a result of it settles to zero in finite time. This is often in distinction to IIR filters, which can have
internal feedback and will still respond indefinitely. The impulse response of an Nth order
discrete time FIR filter takes precisely N+1 samples before it then settles to zero. FIR filters
are most popular kind of filters executed in software and these filters can be continuous time,
analog or digital and discrete time. Special types of FIR filters are namely, Boxcar, Hilbert
Transformer, Differentiator, Lth-Band and Raised-Cosine.

FIR filter design based on windows is simple and robust, however, it is not optimal. The
resulting pass-band and stop-band parameters are equal even though often the specification is
more strict in the stop band than in the pass band unnecessary high accuracy in the pass band.
The ripple of the window is not uniform (decays as we move away from discontinuity points
according to side-lobe pattern of the window) by allowing more freedom in the ripple
behaviour we may be able to reduce filter’s order and hence its complexity.

Algorithm :
Step : 1 Get/Read the sampling frequency.

Step : 2 Get/Read the pass band frequency and multiply the pass band frequency by 2 and
divide by sampling frequency.

71
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Step : 3 Get/Read the stop band frequency and multiply the stop band frequency by 2 and
divide by sampling frequency.

Step : 4 Get/Read the pass band attenuation an pass band attenuation.

Step : 5 create a rectangular window filter using the inbuilt function rectwin.

Step : 7 Plot magnitude and phase response of rectangular window filter.

Step : 8 create a hamming window filter using the inbuilt function hamming.

Step : 9 Plot magnitude and phase response of hamming window filter.

Step : 10 create a hanning window filter using the inbuilt function hann.

Step : 11 Plot magnitude and phase response of hanning window filter.

Step : 12 create a barlett window filter using the inbuilt function barlett.

Step : 13 Plot magnitude and phase response of barlett window filter.

Step : 14 create a blackman window filter using the inbuilt function blackman.

Step : 15 Plot magnitude and phase response of blackman window filter.

PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window

2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.

3) Write the program in the ‘Edit’ window and save it in ‘M-file’.

4) Run the program.

5) Enter the input in the command window.

6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.

72
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

PROGRAM :
clc;
clear all;
close all;
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
f=input('enter the sampling frequency');
wp=2*(fp/f);
ws=2*(fs/f);
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*((fp-fs)/f);
n=ceil(num/den);
%n=abs(n);
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
else
    n1=n+1;
end
%rectangle
y1=rectwin(n1);
wn=(wp+ws)/2;
b=fir1(n,wn,'high',y1);
w=0:0.01:pi;

73
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

[h1,w]=freqz(b,1,w);
magnitude1=(abs(h1));
phase1=angle(h1);
%hamming
y2=hamming(n1);
b=fir1(n,wp,'high',y2);
w=0:0.01:pi;
[h2,w]=freqz(b,1,w);
magnitude2=(abs(h2));
phase2=angle(h2);
%hanning
y3=hann(n1);
b=fir1(n,wp,'high',y3);
w=0:0.01:pi;
[h3,w]=freqz(b,1,w);
magnitude3=(abs(h3));
phase3=angle(h3);
%barlett
y4=bartlett(n1);
b=fir1(n,wp,'high',y4);
w=0:0.01:pi;
[h4,w]=freqz(b,1,w);
magnitude4=(abs(h4));
phase4=angle(h4);
%blackman
y5=blackman(n1);
b=fir1(n,wp,'high',y5);
w=0:0.01:pi;
[h5,w]=freqz(b,1,w);
magnitude5=(abs(h5));
74
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

phase5=angle(h5);
%kaiser
y6=kaiser(n1);
b=fir1(n,wp,'high',y6);
w=0:0.01:pi;
[h6,w]=freqz(b,1,w);
magnitude6=(abs(h6));
phase6=angle(h6);
subplot(3,2,1);
plot(w/pi,magnitude1);
xlabel('normalized frequency');
ylabel('magnitude');
title('rectangular window');
subplot(3,2,2);
plot(w/pi,magnitude2);
xlabel('normalized frequency');
ylabel('magnitude');
title('hamming window');
subplot(3,2,3);
plot(w/pi,magnitude3);
xlabel('normalized frequency');
ylabel('magnitude');
title('hanning window');
subplot(3,2,4);
plot(w/pi,magnitude4);
xlabel('normalized frequency');
ylabel('magnitude');
title('barlett window');
subplot(3,2,5);
plot(w/pi,magnitude5);
75
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

xlabel('normalized frequency');
ylabel('magnitude');
title('blackman window');
subplot(3,2,6);
plot(w/pi,magnitude6);
xlabel('normalized frequency');
ylabel('magnitude');
title('kaiser window');
figure;
subplot(3,2,1);
plot(w/pi,phase1);
xlabel('normalized frequency');
ylabel('phase');
title('rectangular window');
subplot(3,2,2);
plot(w/pi,phase2);
xlabel('normalized frequency');
ylabel('phase');
title('hamming window');
subplot(3,2,3);
plot(w/pi,phase3);
xlabel('normalized frequency');
ylabel('phase');
title('hanning window');
subplot(3,2,4);
plot(w/pi,phase4);
xlabel('normalized frequency');
ylabel('phase');
title('barlett window');
subplot(3,2,5);
76
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

plot(w/pi,phase5);
xlabel('normalized frequency');
ylabel('phase');
title('blackman window');
subplot(3,2,6);
plot(w/pi,phase6);
xlabel('normalized frequency');
ylabel('phase');
title('kaiser window');

77
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Input :

Output :

78
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
Hence an FIR High pass filter is designed and its response is observed.

79
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

80
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

EXPERIMENT NO: 11
LINEAR CONVOLUTION USING CODE COMPOSER STUDIO
AIM: 
To perform Linear Convolution of two sequences using code composer studio.
EXPERIMENTAL REQUIREMENTS:
1. A PC loaded with Code composer studio.
2. TMS320C6713 kit.

THEORY: 

Convolution
Convolution is a mathematical operation used to express the relation between input and
output of an LTI system. It relates input, output and impulse response of an LTI system as
y (t) = x(t) * h(t)
Where y (t )= output of LTI
x (t) = input of LTI
h (t) = impulse response of LTI
There are two types of convolutions:
● Continuous convolution
● Discrete convolution

Continuous Convolution

y(t) = x(t) * h(t)

81
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

Output signal is obtained by convolving input signal and impulse response.

Discrete Convolution

y[n] = x[n] * h[n]

Output signal is obtained by convolving input signal and impulse response.


By using convolution we can find zero state response of the system.
Limits of Convoluted Signal
If two signals are convoluted then the resulting convoluted signal has following range:
Sum of lower limits < t < sum of upper limits
The linear convolution (or correlation) of two sequences of lengths P and Q, respectively, will
produce a third sequence of length P + Q − 1. 
PROPERTIES OF LINEAR CONVOLUTION
x(n) = Excitation Input signal

y(n) = Output Response

h(n) = Unit sample response

1. Commutative Law: (Commutative Property of Convolution)

x(n) * h(n) = h(n) * x(n)

2. Associate Law: (Associative Property of Convolution) 

[ x(n) * h1(n) ] * h2(n) = x(n) * [ h1(n) * h2(n) ]

3. Distribute Law: (Distributive property of convolution) 

x(n) * [ h1(n) + h2(n) ] = x(n) * h1(n) + x(n) * h2(n)

Causality and stability are also properties of Linear Convolution.

82
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

ALGORITHM :
Step : 1 Get/Read the samples of x[n] to x.
Step : 2 Get/Read the samples of h[n] to h.
Step : 3 Get/Read the length of x to m.
Step : 4 Get/Read the length of h to n.
Step : 5 Use 2 for loops and repeat it upto m+n-1.
Step : 6 Determine the convolution of x and h using
y[n] = ∑ X(k) H(n-k).
Step : 7 Plot the graph of y[n].
PROCEDURE:
1. Open CC Studio by clicking on the icon.
2. Go to file, click on new cc project for creating new file.
3. Select target as C671X floating point DSP.
4. In connections, select spectrum digital DSK-EVM-ezdsp onboard USB emulator.
5. Name the project and click on finish.
6. Write the program, and save the file.
7. To check whether some space has been created in stack memory or not, go to
properties in select project and select C600 linker and click on basic options and then
click ok.
8. Then build the program by clicking on the hammer symbol.
9. Click on the user defined on right side. Select new target configuration and then
select launch select configuration.
10. Go to Run and Connect target. 
11. If the kit is not connected, it will display as disconnected otherwise no issues.
12. Again go to Run, click on load and select load program.
13. Select our project and click on debug and select output file and then press ok.
14. Then go to run and click on resume or press F8 to start execution.
15. Give the required inputs and observe the output.
16. For graphs, go to view and click on expressions.
17. Right click on output and select graph.
18. To convert continous signal into digital, go to graph properties.
19. Then click on style and select Bar.
20. Then note down the output waveforms and values.
PROGRAM:

83
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

#include<stdio.h>
int x[15],h[15],y[15];
main()
{
int i,j,m,n;
printf(“\n enter value for m :”);
scanf(“%d”,&m);
printf(“\n enter value for n :”);
scanf(“%d”,&n);
printf(“\n enter value for input x[n] ”);
for(i=0;i<m;i++)
scanf(“%d”,&x[i]); 
printf(“\n enter value for input h[n] ”);
for(i=0;i<n;i++)
scanf(“%d”,&h[i]);
//padding zeroes
for(i=m;i<m+n-1;i++)
{
x[i]=0;
}
for(i=n;i<m+n-1;i++)
{
h[i]=0;
}
//Convolution operation
for(i=0;i<m+m-1;i++)
{

84
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

y[i]=0; 
for(j=0;j<=i;j++)
{
y[i]= y[i] + (x[j] * h[i-j]);
}
}
//Displaying output
for(i=0;i<m+n-1;i++)
{
printf(“\n The value of output y[%d] = %d”,i,y[i]);
}
}
OBSERVATIONS:

RESULT:
Linear Convolution of two sequences is performed and output is verified using code
composer studio.

85
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

86
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

                                                  EXPERIMENT NO: 12

CIRCULAR CONVOLUTION USING CODE COMPOSER STUDIO


AIM: 
To perform Circular Convolution of two sequences using code composer studio.
EXPERIMENTAL REQUIREMENTS:
1. A PC loaded with Code composer studio.
2. TMS320C6713 kit.

THEORY : 
x[n] and h[n] are two finite sequences of length N with DFTs denoted by X[k] and H[k],
respectively. Let us form the product

W[k] = X[k]H[k],

and determine the sequence w[n] of length N for which the DFT is W[k].

First, extend x[n] and h[n] to periodic sequences with period N, x h ˜[n] and [n], respectively. ˜
Then, the periodic convolution of x h ˜[n] and [n] corresponds to multiplication of the
corresponding periodic sequences of Fourier series coefficients.

w[n] = w˜[n]RN [n]


N −1
¿ ∑ ❑ x [m]h[n−m]
m =0

N −1
¿ ∑ ❑ x [m] h[((n−m))N ]
m =0

This operation is called circular convolution and is denoted as

87
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

ALGORITHM:
Step : 1 Get/Read the samples of x[n] to x.
Step : 2 Get/Read the samples of h[n] to h.
Step : 3 Get/Read the length of x to m.
Step : 4 Get/Read the length of h to n.
Step : 5 If m  is greater than n, then padding of zeros is done on h(n) and zeros are  ranging from
1 to (m – n).
Step : 6 If n is greater than m, then padding of zeros is done on x(n) and zeros are ranging from 1
to (n – m).
Step : 7 Use 2 for loops to determine convolution.
Step : 8 Determine the convolution of x and h using
y[n] = x[n]           h[n].
Step : 9 Plot the graph of y[n].
PROCEDURE:
1. Open CC Studio by clicking on the icon.
2. Go to file, click on new cc project for creating new file.
3. Select target as C671X floating point DSP.
4. In connections, select spectrum digital DSK-EVM-ezdsp onboard USB emulator.
5. Name the project and click on finish.
6. Write the program, and save the file.
7. To check whether some space has been created in stack memory or not, go to
properties in select project and select C600 linker and click on basic options and then
click ok.
8. Then build the program by clicking on the hammer symbol.
9. Click on the user defined on right side. Select new target configuration and then
select launch select configuration.
10. Go to Run and Connect target. 
11. If the kit is not connected, it will display as disconnected otherwise no issues.
12. Again go to Run, click on load and select load program.
13. Select our project and click on debug and select output file and then press ok.
14. Then go to run and click on resume or press F8 to start execution.
15. Give the required inputs and observe the output.
16. For graphs, go to view and click on expressions.
17. Right click on output and select graph.
18. To convert continous signal into digital, go to graph properties.
19. Then click on style and select Bar.
20. Then note down the output waveforms and values.

88
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

PROGRAM:
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) /*If length of both sequences are not equal*/
{
if(m>n) /* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++)
{
h[i]=0;
n=m;
}
}
for(i=m;i<n;i++)
{

89
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

x[i]=0;
m=n;
}
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}

OBSERVATIONS:
90
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
             Circular Convolution of given sequences is performed and output is verified using code
composer studio.

91
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

92
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

                                         EXPERIMENT NO: 13
   GENERATION OF SINE AND SQUARE WAVEFORMS USING    
                                  CODE COMPOSER STUDIO
AIM: 
To generate Sine and square waveforms using Code Composer Studio.
EXPERIMENTAL REQUIREMENTS:
1. A PC loaded with Code composer studio.
2. TMS320C6713 kit.
THEORY: 

Sinusoidal signal:
A signal, which is continuous in nature is known as continuous signal. General format of a
sinusoidal signal is
x(t)=Asin(ωt+ϕ)

Here,
A = amplitude of the signal
ω = Angular frequency of the signal Measured in radians
φ = Phase angle of the signal Measured in radians
The tendency of this signal is to repeat itself after certain period of time, thus is called periodic
signal. The time period of signal is given as;
T=2πω

The diagrammatic view of sinusoidal signal is shown below.

93
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

A continuous-time signal x(t) is said to be periodic with period T if it satisfy the condition

x (t+T) = x(t) for all t -∞<t

A signal is periodic if the above condition is not satisfied for at least one value of T.

The smallest value of T that satisfies the above condition is known as fundamental period.

Complex exponential and sinusoidal signals are examples for continuous time periodic signals.
Consider a sinusoidal signal.

x(t)=Asin(wt+θ)

Where A is the amplitude, w is the frequency in radians per second (rad/sec), and θ the phase
in radians. The frequency f0 in hertz is given by f0 = w /2π or periodic signal we have

X(t+T)=x(t)

For x(t)=Asin(wt+θ)

X (t+T) = Asin [w(t+T)+ θ)]

= Asin[wt+wT+θ]

From the Above equations ,

wT = 2π , T =2π/ w

Thus the sinusoidal is periodic with period 2π/ w.

Sum of Sinusoidal Signals:


The sum of two periodic signals x1(t) and x2(t) with periods T1 and T2 respectively may or may
not be periodic, then the ratio T1/T2 can be written as the ratio a/b of two integers a and b. If
T1/T2 = a/b, then bT1 = aT2, and since a and b are integers, x1(t) and x2(t) are periodic with
period bT1. If a and b are co prime (i. e. a and b have no common integer factors other than 1)
then T = bT1 is the fundamental period of the sum of two signals.

94
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

ALGORITHM:
For Sine wave:
Step : 1 Get/Read the frequency f.
Step : 2 Get/Read number of samples n.
Step : 3 Use a for loop to generate a sinusoidal signal.
For Square wave:
Step : 1 Get/Read the frequency f.
Step : 2 Use a for loop to generate a Square waveform
Step : 3 If ((i*2)/f)%2==0, set value of y as 1 else set as -1.
 
PROCEDURE:
1. Open CC Studio by clicking on the icon.
2. Go to file, click on new cc project for creating new file.
3. Select target as C671X floating point DSP.
4. In connections, select spectrum digital DSK-EVM-ezdsp onboard USB emulator.
5. Name the project and click on finish.
6. Write the program, and save the file.
7. To check whether some space has been created in stack memory or not, go to
properties in select project and select C600 linker and click on basic options and
then click ok.
8. Then build the program by clicking on the hammer symbol.
9. Click on the user defined on right side. Select new target configuration and then
select launch select configuration.
10. Go to Run and Connect target. 
11. If the kit is not connected, it will display as disconnected otherwise no issues.
12. Again go to Run, click on load and select load program.
13. Select our project and click on debug and select output file and then press ok.
14. Then go to run and click on resume or press F8 to start execution.
15. Give the required inputs and observe the output.
16. For graphs, go to view and click on expressions.
17. Right click on output and select graph.
18. To convert continous signal into digital, go to graph properties.
19. Then click on style and select Bar.
20. Then note down the output waveforms and values.

PROGRAMS:
/*Sine wave generation*/
#include<stdio.h>
#include<math.h>
#define pi 3.14
float y[500];

95
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

void main()
{
int t,f,n;
printf("enter the frequency");
scanf("%d",&f);
printf("enter the n value");
scanf("%d",&N);

for(t=0;t<=500;t++)
y[t]=sin(2*pi*f*t/N);
}

/* Square wave generation*/


#include<stdio.h>
#include<math.h>
float y[100];
void main()
{
int t,i,f;
printf("enter the frequency");
scanf("%d",&t);
for(i=0;i<128;i++)
if(((i*2)/t)%2==0)
y[i]=1;
else
y[i]=-1;
}
OBSERVATIONS:

96
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology

RESULT:
         Sinusoidal and square waveforms are generated using Code Composer Studio.

97
Digital signal processing lab

You might also like