You are on page 1of 20

Experiment 1

Objective: Generate and plot these sequences:


(a)Impulse function δ (n)
(b)Unit step function u (n)
(c)Ramp function r (n)

Coding: (a) Impulse function δ (n)


n= input('enter value of n=');
x=-n:n;
y=-n:n;
for i=1:((2.*n)+1);
if(i==n+1)
y(1,i)=1;
else
y(1,i)=0;
end
end
stem(x,y)

Result: enter value of n=5

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
Coding: (b) Unit step function u (n)
n= input('enter value of n=');
x=-n:n;
y=-n:n;
for i=1:((2.*n)+1);
if(i>=n+1)
y(1,i)=1;
else
y(1,i)=0;
end
end
stem(x,y)

Result: enter value of n=5

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-5 -4 -3 -2 -1 0 1 2 3 4 5

Coding: (c) Ramp function r (n)


n= input('enter value of n=');
x=-n:n;
y=-n:n;
for i=1:((2.*n)+1);
if(i>n+1)
y(1,i)=i-(n+1);
else
y(1,i)=0;
end
end
stem(x,y)
Result: enter value of n=5

4.5

3.5

2.5

1.5

0.5

0
-5 -4 -3 -2 -1 0 1 2 3 4 5

Conclusion: The following sequences are plotted.


Experiment 2
Objective: Generate and plot these sequences using other functions:
(a)Impulse function δ (n) = u (n) – u (n)
(b)Unit step function u (n) =∑∞
δ n  k
(c)Ramp function r (n) =nu (n)

Coding: (a) Impulse function δ (n)


n=input('enter value of n=');
x=-n:n;
y=ones(1,((2.*n)+1));
u=ones(1,((2.*n)+1));
for i=1:((2.*n)+1);
if(i<=n)
y(1,i)=0
end
end
for i=1:((2.*n)+1)
if(i<=n+1);
u(1,i)=0
end
end
k=y-u
stem(x,k)

Result: enter value of n=5

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
Coding: (b) Unit step function u (n)
n=input('enter value of n=');
u=zeros(1,((2.*n)+1));
for j=1:((2.*n)+1);
y=zeros(1,((2.*n)+1));
x=-n:n;
for i=1:((2.*n)+1);
if(i==n+j)
y(1,i)=1;
else
y(1,i)=0;
end
end
u=u+y
end
stem(x,u)

Result: enter value of n=10

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10

Coding: (c) Ramp function r (n)


clc;
clear all;
n=input('enter the value of n=');
x=-n:n;
for i=1:((2.*n)+1)
if(i<=n)
y(1,i)=0;
else
y(1,i)=(i-(n+1));
end
end
stem(x,y)
Result: enter value of n=10

10

0
-10 -8 -6 -4 -2 0 2 4 6 8 10

Conclusion: The following sequences are plotted.


Experiment 3
Objective: Generate and plot these sequences using other functions:
(a)Shifted Impulse function δ (n-p)
(b) Shifted Unit step function u (n-p)
(c) Shifted Ramp function r (n-p)

Coding: (a) Impulse function δ (n)


n= input('enter value of n=');
p= input('enter shift p=');
x=-n:n;
y=-n:n;
for i=1:((2.*n)+1);
if(i==n+p+1)
y(1,i)=1;
else
y(1,i)=0;
end
end
stem(x,y)

Result: enter value of n=5


enter shift p=1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
Coding: (b) Unit step function u (n)
n= input('enter value of n=');
p= input('enter shift p=');
x=-n:n;
y=-n:n;
for i=1:((2.*n)+1);
if(i>=n+p+1)
y(1,i)=1;
else
y(1,i)=0;
end
end
stem(x,y)

Result: enter value of n=5


enter shift p=1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-5 -4 -3 -2 -1 0 1 2 3 4 5

Coding: (c) Ramp function r (n)


n= input('enter value of n=');
p= input('enter shift p=');
x=-n:n;
y=-n:n;
for i=1:((2.*n)+1);
if(i>n+p+1)
y(1,i)=i-(n+1);
else
y(1,i)=0;
end
end
stem(x,y)
Result: enter value of n=5
enter shift p=2

4.5

3.5

2.5

1.5

0.5

0
-5 -4 -3 -2 -1 0 1 2 3 4 5

Conclusion: The following sequences are plotted.


Experiment 4
Objective: Find and plot linear convolution of two sequences x1(n) and x2(n) of length N1 and
N2.

Coding: Linear convolution:

x1=input('enter the sequence=');


x2=input('enter the sequence=');
n1=length(x1);
n2=length(x2);
p=n1+n2-1;
y=zeros(1,p);
for j=1:p
if(j>n1)
x1(1,j)=0;
end
end
for j=1:p
if(j>n2)
x2(1,j)=0;
end
end
for j=1:p
for k=1:p
if((k+1-j)>0)
y(1,k)=y(1,k)+(x1(1,j))*x2(1,(k+1-j))
else
y(1,k)=y(1,k)
end
end
end
subplot(3,1,1)
stem(x1)
subplot(3,1,2)
stem(x2)
subplot(3,1,3)
stem(y)

Result: enter the sequence= [1 2 3 4]


enter the sequence= [1 2 3 4]
4

0
1 2 3 4 5 6 7
4

0
1 2 3 4 5 6 7
30

20

10

0
1 2 3 4 5 6 7

The linear convolution is [1 2 3 4 5 6 7]

Conclusion: The following sequences are plotted.


Experiment 5
Objective: Find and plot circular convolution of two sequences x1(n) and x2(n) of length N1
and N2.

Coding: Circular convolution:


clc;
clear all;
x1=input('enter the sequence=');
x2=input('enter the sequence=');
n1=length(x1)
n2=length(x2)
N=n1
if(n2>n1)
N=n2;
end
p=0;
y=zeros(1,(4.*N));
for j=1:N
if(j>n1)
x1(1,j)=0
end
end
for j=1:N
if(j>n2)
x2(1,j)=0
end
end
x1=[x1 x1 x1 x1]
x2=[x2 x2 x2 x2]
for j=1:N
for k=1:N
if((k-j)>=0)
p=k-j+1
else
p=k-j+1+N
end
y(1,k)=y(1,k)+(x1(1,j).*x2(1,p))
end
end
y=[y y y y]
subplot(3,1,1)
stem(x1)
subplot(3,1,2)
stem(x2)
subplot(3,1,3)
stem(y)

Result: enter the sequence= [1 2 3 4]


enter the sequence= [1 2 3 4]
4

0
0 2 4 6 8 10 12 14 16
4

0
0 2 4 6 8 10 12 14 16
30

20

10

0
0 10 20 30 40 50 60 70

The circular convolution is [26 28 26 20]

Conclusion: The following sequences are plotted.


Experiment 6
Objective: (a) Find Discrete Fourier Transform (DFT) and inverse DFT of two sequences x1(n)
and x2(t).
(b) Find Magnitude and Phase of the above DFT computed.

Coding: (a) DFT of x1(t) and x2(t):


x=input('enter the sequence=');
y=input('enter the sequence=');
x1=fft(x)
y1=fft(y)
z=x1.*y1;
m=ifft(z);
subplot(4,1,1)
stem(x)
subplot(4,1,2)
stem(y)
subplot(4,1,3)
stem(z)
subplot(4,1,4)
stem(m)

Result: enter the sequence= [2 1 2 1]


enter the sequence= [1 2 3 4]

0
1 1.5 2 2.5 3 3.5 4
4

0
1 1.5 2 2.5 3 3.5 4
100

-100
1 1.5 2 2.5 3 3.5 4
20

10

0
1 1.5 2 2.5 3 3.5 4
The DFT of two sequences x1(k) = [6 0 2 0]
x2 (k) = [10 -2+j2 -2 -2-j2]
m = [14 16 14 16]

Coding: (b) Magnitude and phase:


x=input('enter the sequence=');
d=fft(x)
m=abs(d)
p=angle(d)
subplot(4,1,1)
stem(x)
subplot(4,1,2)
stem(d)
subplot(4,1,3)
stem(m)
subplot(4,1,4)
stem(p)

Result: enter the sequence= [1 2 3 4]

0
1 1.5 2 2.5 3 3.5 4
2

-2
1 1.5 2 2.5 3 3.5 4
10

0
1 1.5 2 2.5 3 3.5 4
5

-5
1 1.5 2 2.5 3 3.5 4

The magnitude = [10 2.8284 2 2.8284]


The phase = [0 2.3562 3.1416 -2.3562]

Conclusion: The following sequences are plotted.


Experiment 7

Objective: (a) To design low pass FIR Equiripple filter for the following specifications and plot
magnitude and phase plot.
Fs = 48000Hz
Fpass = 9600Hz
Fstop = 12000Hz
Apass = 1db
Astop = 80db
Filter order = minimum
Result: (a)
Magnitude Response (dB)
20

-20

-40
Magnitude (dB)

-60

-80

-100

-120

-140
0 5 10 15 20
Frequency (kHz)

Phase Response
0

-500
Phase (degrees)

-1000

-1500

-2000

-2500
0 5 10 15 20
Frequency (kHz)
Objective: (b) To design low pass IIR Butterworth filter for the following specifications and plot
magnitude and phase plot.
Fs = 48000Hz
Fpass = 9600Hz
Fstop = 12000Hz
Apass = 1db
Astop = 80db
Filter order = minimum
Result: (b)
Magnitude Response (dB)
500

-500
Magnitude (dB)

-1000

-1500

-2000

-2500
0 5 10 15 20
Frequency (kHz)

Phase Response
0

-500

-1000
Phase (degrees)

-1500

-2000

-2500

-3000
0 5 10 15 20
Frequency (kHz)
Filter Design and Analysis Tool

The filter design and analysis tool (FDA Tool) is a user interface for designing and analyzing filters
quickly. FDA Tool enables one to design digital FIR or IIR filters by setting filter specifications, by
importing filters from MATLAB workspace, or by adding, moving or deleting poles and zeros. FDA Tool
also provides tools for analyzing Filter, such as magnitude and phase response and pole-zero plots.

Different Steps of FDA Tool

1. Opening FDA Tool.


2. Choosing a response type.
3. Choosing a filter design method.
4. Setting the filter design specifications.
5. Computing filter coefficients.
6. Analyzing the filter.
7. Editing the filter using the pole/zero editors.
8. Converting the filter structure.
9. Importing a filter design.
10. Exporting a filter design.
11. Generating a C header file.
12. Generating MATLAB code.
13. Managing filter in the current sessions.
14. Saving and Opening filter design sessions.

Opening FDA tool:


In order to open FDA Tool, Type “fdatool” on the command prompt. The filter design and analysis tool
opens the design filter panel displayed.

Choosing a Response type:


One can choose types listed below.
• Low pass
• Raised cosine
• High pass
• Band pass
• Differentiator
• Multiband
• Hilbert transformer
• Arbitrary magnitude

Choosing a filter design method


One can use the default filter design method for the response type you have selected or one can select a
filter method from the available FIR and IIR methods listed in the GUI.

Setting the filter design specifications


The filter design specifications that one can set vary according to response type and design method. The
display region illustrates filter specifications when one can select Analysis => Filter specifications when
one clicks the filter specifications toolbar button. It includes Filter, options, band pass filter
specifications and band pass filter magnitude specifications.
Computing the filter coefficients
Now that you have specified the filter design, click the design filter to compute the filter coefficients.

Analyzing the filter


One can view the following filter response characteristics in the display region or in a separate window
• Magnitude response
• Phase response
• Magnitude response and Phase response
• Group delay response
• Phase delay response
• Impulse response
• Step response
• Pole-zero plot
• Zero- phase plot

Editing the filter using pole- zero editor


It displays the pole zero plot.

Converting the filter structure


One can edit> convert structure to convert the current filter to a new structure. All filters can be
converted to the following representations
• Direct form 1
• Direct form 2
• Direct form 1 transposed
• Direct form 2 transposed
• Lattice ARMA

Importing a filter design


It includes Import filter panel and structures. The import filter panel allows you to import a filter. One
can access this region by clicking the import filter button in the side bar.
The available filter structures are:
• Direct form
• Lattice
• Discrete time filter

Exporting a filter design


One can export the filter to workspace, an ASCII filter objects to a MAT file, SP Tool, to a Simulink Model
etc.

Generating C header File


One can generate MATLAB code that constructs the filter one designs in the FDA tool from the
command line.

Managing filters in the current session


One can store filters designed in the current FDA tool session for cascading together, exporting to FV too
or for recalling later in the same or future FDA tool sessions.
Saving and opening filter design sessions
One can save your filter design sessions as a MAT file and return to the same session another time.

You might also like