Vous êtes sur la page 1sur 61

c  


|

 
 c  

c

|

c  
The name c  stands for MATrixLABoratory. MATLAB is a
software package for high-performance numerical computation and
visualization . It provides an interactive environment with hundreds of
built-in functions for technical computation, graphics, and animation .
Best of all, it provides easy extensibility with its own high-level
programming language. Using the MATLAB product, you can solve
technical computing problems faster than with traditional programming
languages. The MATLAB development environment lets you develope
interactively analyze data, view the data files, and manage projects.

c   

1) MATLAB¶s ease of use is its best feature. Also, it has a shallow
learning curve i.e. more learning with less effort .whereas the computer
algebra systems have a steep learning curve.
2) It is an high level language for technical computing.
3) MATLAB is often much faster at the calculations ±often as fast as C
or Fortran .
4) MATLAB beats everyone hands down in terms of ease of use,
availability of built-in functions, ease of programming, and speed. The
proof is the phenomenal growth of its users around the world in just a
few years.
5) MATLAB¶s built-in functions provide excellent tools for:

ë| linear algebra computations


ë| data analysis
ë| Signal processing
ë| ptimization
ë| Îumerical solution of ordinary differential equations( ¶s)
ë| Many other types of scientific calculations.
Most of these functions use state-of-the-art algorithms. There are
numerous functions for 2- and 3- graphics, as well as for animation.
6) The user is not limited to use the built-in functions, he can write his
own functions in this language. nce written, these functions behave
just like the built-in functions.
7) There are several optional ³toolboxes´ available from the developers
of MATLAB. These are collections of functions written for special
applications such as symbolic computation, image processing, statistics,
control system design, neural networks, etc.
8) The basic building block of MATLAB is the matrix. The fundamental
data-type is the array. Vectors, scalars, real matrices, and complex
matrices are all automatically handled as special cases of the basic data-
type.
9) It provides a no. of features for documenting and sharing your work.
You can integrate your matlab code with other languages and
application, and distribute your algorithms and applications.

  c  

*It is an interpreted language for numerical computation. It allows one
to perform numerical calculations, and visualize the results without the
need for complicated and time consuming programming. MATLAB
allows its users to accurately solve problems, produce graphics easily
and produce code efficiently.

   c  
* There are limitations and restrictions on the use of the MATLAB
compiler. They vary from version to version. Regardless of the version,
script m-files cannot be converted into C codes or standalone
executables. You must first convert them into function m-files.
* Because MATLAB is an interpreted language, it can be slow, and poor
programming practices can make it unacceptably slow.

c    c 

The general structure of the MATLAB environment is discussed below.
MATLAB desktop:
>>this is where MATLAB puts you when you launch it. The MATLAB
desktop by default consists of the following subwindows .

ë| á  
This is the main window. It is
characterized by the MATLAB command prompt (>>). When you
launch the application program, MATLAB puts you in this
window. All commands, including those for running user-written
programs, are typed in this window at the MATLAB prompt. This
window further contains other smaller windows which are:
1)|á  

this is where all your files rom the current
directory are listed. You can do file navigation here. You can
have several options of what you do with a file once you select
it (with a mouse click).
2)|  

this sub-window lists all variables that you have
generated so far and shows their type and size. You can do
various things with these variables such as plotting, by clicking
on a variable and then using right button on the mouse to select
your option.
3)|á  
all commands typed on the MATLAB
prompt in the command window get recorded, even across
multiple sessions, in this window. You can select a command
from this window with the mouse and execute it in the
command window by double clicking on it. You can also select
a set of commands from this window and create an m-file with
right click of the mouse.

ë|  
The output of all graphics commands typed in
the command window are flushed to the graphics or figure
window, a separate gray window with (default) white background
color. The user can create as many figure windows as the system
memory will allow.

ë|   
This is where you write, edit, create, and save
your own programs in files called M-files. You can use any text
editor to carry out these tasks. n most of systems, MATLAB
provides its own built-in editor. However you can use your own
editor by typing the standard file-editing command that you
normally use on your system.


    á



There is online help for all built in functions. With so many built in
functions, it is important to know how to look for functions and how to
learn to use them.
There are several ways to get help:
1.|£  
the keyword search function. If you are looking for a
function, use £    to get a list of functions with the
string keyword in their description.
For example: typing £  

  
lists functions that
create identity matrix.
2.|£
the most direct on-line help. if you know the exact name of a
function you can get help on it by typing ˣ 
  on
the command line.
For example: typing ˣˣprovides help on the function help
itself.








  

c

To develop elementary signal function modules (m-files) for unit impulse, unit
step, exponential and unit ramp sequences.

 c


x=input('left limit ')
y=input('right limit ')
t=-x:y

£    
a=[zeros(1,x),ones(1,1),zeros(1,y)]
stem(t,a)
xlabel('t')
ylabel('a')
subplot(2,2,1)

     
b=[zeros(1,x),ones(1,y+1)]
stem(t,b)
xlabel('t')
ylabel('b')
subplot(2,2,2)

    
c=[zeros(1,x+1),1:y]
stem(t,c)
xlabel('t')
ylabel('c')
subplot(2,2,3)

  £ £   


n=input('value of n ')
d=[n.^t]
stem(t,d)
xlabel('t')
ylabel('d')
subplot(2,2,4)
á  

left limit 5

x=

right limit 5

y=

t=

Columns 1 through 10

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

Column 11

a=

Columns 1 through 10

0 0 0 0 0 1 0 0 0 0

Column 11

b=

Columns 1 through 10

0 0 0 0 0 1 1 1 1 1

Column 11

c=

Columns 1 through 10
0 0 0 0 0 0 1 2 3 4

Column 11

value of n 2

n=

d=

Columns 1 through 6

0.0313 0.0625 0.1250 0.2500 0.5000 1.0000

Columns 7 through 11

2.0000 4.0000 8.0000 16.0000 32.0000









R R R R R     



R R R R R     
 



R R R R R     





R R R R R     

á   

left limit 5
x=
5
right limit 5
y=
5
t=
Columns 1 through 10
-5 -4 -3 -2 -1 0 1 2 3 4
Column 11
5
value of n 0
n=
0
a=
Columns 1 through 10
InfInfInfInfInf 1 0 0 0 0
Column 11
0
























R R R R R     
á   

left limit 5
x=
5
right limit 5
y=
5
t=
Columns 1 through 10
-5 -4 -3 -2 -1 0 1 2 3 4
Column 11
5
value of n -3
n=
-3
a=
Columns 1 through 6
-0.0041 0.0123 -0.0370 0.1111 -0.3333 1.0000
Columns 7 through 11
-3.0000 9.0000 -27.0000 81.0000 -243.0000





R 

R

R 

R

R 
R R R R R     
  
c

To develop program modules based on operation on sequences like signal shifting,
signal folding, signal addition and signal multiplication of
ë| unit step
ë| unit impulse and
ë| random signal

 c

ë|    

t=input('range ')
x1=[t>=0]
stem(t,x1)
xlabel('t')
ylabel('x1')
subplot(5,1,1)
k=input('delay ')
  
x2=[(t-k)>=0]
stem(t,x2)
xlabel('t')
ylabel('x2')
subplot(5,1,2)
 £
t1=-fliplr(t)
x3=fliplr(x2)
stem(t1,x3)
xlabel('t1')
ylabel('x3')
subplot(5,1,3)
  
x4=x2+x3
stem(t,x4)
xlabel('t')
ylabel('x4')
subplot(5,1,4)
£ £
  
x5=x2.*x3
stem(t,x5)
xlabel('t')
ylabel('x5')
subplot(5,1,5)

á  

range -4:5
t=
-4 -3 -2 -1 0 1 2 3 4 5
x1 =
0 0 0 0 1 1 1 1 1 1
delay 3
k=
3
x2 =
0 0 0 0 0 0 0 1 1 1
t1 =
-5 -4 -3 -2 -1 0 1 2 3 4
x3 =
1 1 1 0 0 0 0 0 0 0
x4 =
1 1 1 0 0 0 0 1 1 1
x5 =
0 0 0 0 0 0 0 0 0 0







 

R R R R     




 

R R R R R    


 



R R R R     





R
R R R R     




 

R R R R     

ë|   £ 


t=input('range ')
x1=[t==0]
stem(t,x1)
xlabel('t')
ylabel('x1')
subplot(5,1,1)
k=input('delay ')

  
x2=[(t-k)==0]
stem(t,x2)
xlabel('t')
ylabel('x2')
subplot(5,1,2)

 £
t1=-fliplr(t)
x3=fliplr(x2)
stem(t1,x3)
xlabel('t1')
ylabel('x3')
subplot(5,1,3)

  
x4=x2+x3
stem(t,x4)
xlabel('t')
ylabel('x4')
subplot(5,1,4)

£ £
  
x5=x2.*x3
stem(t,x5)
xlabel('t')
ylabel('x5')
subplot(5,1,5)



á  

range -4:5
t=
-4 -3 -2 -1 0 1 2 3 4 5
x1 =
0 0 0 0 1 0 0 0 0 0
delay 3
k=
3
x2 =
0 0 0 0 0 0 0 1 0 0
t1 =
-5 -4 -3 -2 -1 0 1 2 3 4
x3 =
0 0 1 0 0 0 0 0 0 0
x4 =
0 0 1 0 0 0 0 1 0 0
x5 =
0 0 0 0 0 0 0 0 0 0








R R R R     






R R R R R    






R R R R     





R
R R R R     






R R R R     

   £


t=input('range')
x1=input('enter sequence')
stem(t,x1)
xlabel('t')
ylabel('x1')
subplot(5,1,1)
k=input('delay')

  
t1=t-k
stem(t1,x1)
xlabel('t1')
ylabel('x1')
subplot(5,1,2)

 £
t2=-fliplr(t)
x2=fliplr(x1)
stem(t2,x2)
xlabel('t2')
ylabel('x2')
subplot(5,1,3)

  
x3=x1+x2
stem(t,x3)
xlabel('t')
ylabel('x3')
subplot(5,1,4)

£ £
  
x4=x1.*x2
stem(t,x4)
xlabel('t')
ylabel('x4')
subplot(5,1,5)



á  

range-4:5
t=
-4 -3 -2 -1 0 1 2 3 4 5
enter sequence[1,3,2,4,5,4,3,2,3,2]
x1 =
1 3 2 4 5 4 3 2 3 2
delay3
k=
3
t1 =
-7 -6 -5 -4 -3 -2 -1 0 1 2
t2 =
-5 -4 -3 -2 -1 0 1 2 3 4
x2 =
2 3 2 3 4 5 4 2 3 1
x3 =
3 6 4 7 9 9 7 4 6 3
x4 =
2 9 4 12 20 20 12 4 9 2







R R R R R R R   





R R R R R     






R R R R      






R R R R      





R R R R      



  
c

To calculate and plot convolution of two causal, anti-causal and two-sided
sequences.

 c

|
m1=input('left limit of 1st ')
n1=input('right limit of 1st ')
t1=-m1:n1
x1=input('enter 1st sequence ')
stem(t1,x1)
xlabel('t1')
ylabel('x1')
subplot(3,1,1)
m2=input('left limit of 2nd ')
n2=input('right limit of 2nd ')
t2=-m2:n2
x2=input('enter 2nd sequence ')
stem(t2,x2)
xlabel('t2')
ylabel('x2')
subplot(3,1,2)
l=m1+m2
r=n1+n2
t=-l:r
y=conv(x1,x2)
stem(t,y)
xlabel('t')
ylabel('y')
subplot(3,1,3)

ácc  


 
 £ 


left limit of 1st 0
m1 =
0
right limit of 1st 4
n1 =
4
t1 =
0 1 2 3 4
enter 1st sequence [2,3,1,2,1]
x1 =
2 3 1 2 1
left limit of 2nd 0
m2 =
0
right limit of 2nd 6
n2 =
6
t2 =
0 1 2 3 4 5 6
enter 2nd sequence [2,1,3,2,3,2,1]
x2 =
2 1 3 2 3 2 1
l=
0
r=
10
t=
0 1 2 3 4 5 6 7 8 9 10
y=
4 8 11 18 19 22 18 13 8 4 1






u
u     

u

u

u
u      
u






u
u u         

   
 £ 



left limit of 1st 4


m1 =
4

right limit of 1st -1


n1 =
-1
t1 =
-4 -3 -2 -1

enter 1st sequence [2,3,1,2]


x1 =
2 3 1 2

left limit of 2nd 5


m2 =
5

right limit of 2nd -2


n2 =
-2
t2 =
-5 -4 -3 -2

enter 2nd sequence [1,3,2,1]


x2 =
1 3 2 1

l=
9

r=
-3

t=
-9 -8 -7 -6 -5 -4 -3

y=
2 9 14 13 11 5 2







R R R R R R R




R R R
R R R R





R R R R R R  R


    




left limit of 1st 1
m1 =
1
right limit of 1st 3
n1 =
3
t1 =
-1 0 1 2 3
enter 1st sequence [2,3,1,2,1]
x1 =
2 3 1 2 1
left limit of 2nd 2
m2 =
2
right limit of 2nd 3
n2 =
3
t2 =
-2 -1 0 1 2 3
enter 2nd sequence [2,3,1,3,2,3]
x2 =
2 3 1 3 2 3
l=
3
r=
6
t=
-3 -2 -1 0 1 2 3 4 5 6
y=
4 12 13 16 22 20 18 10 8 3








R R R R      




R R R     





R R      










  
c

WAP to determine:
1. Cross Correlation
2. Auto Correlation
of any sequence.

 c

t=input('nter range')
x=input('nter 1st sequence')
y=input('nter 2nd sequence')
%cross-correlation
m=xcorr(x,y)
subplot(2,1,1)
stem(m)
xlabel('t')
ylabel('m')
%auto-correlation
n=xcorr(x,x)
subplot(2,1,2)
stem(n)
xlabel('t')
ylabel('n')|
|
á  

nter range-2:3

t=
-2 -1 0 1 2 3

nter 1st sequence[2,1,3,1,2,3]


x=
2 1 3 1 2 3

nter 2nd sequence[4,3,1,3,2,1]


y=
4 3 1 3 2 1

m=
2.0000 5.0000 11.0000 12.0000 20.0000 24.0000 26.0000 26.0000
13.0000 17.0000 12.0000
n=
6 7 13 16 16 28 16 16 13 7 6






@


@        @ @@



@


@        @ @@











  
c

WAP to plot poles and zeros of Transfer function and also check the stability of
the system.

 c

num=input('enter coefficients of numerator')
den=input('enter coefficients of denominator')
tf(num,den)
[z,p,k]=tf2zp(num,den)
zplane(num,den)
if abs(p)<=1
disp('stable')
else
disp('unstable')
end

á  

enter coefficients of numerator[2,1,3,2]
num =

2 1 3 2

enter coefficients of denominator[2,3,1,3]


den =

2 3 1 3

Transfer function:
2 s^3 + s^2 + 3 s + 2
---------------------
2 s^3 + 3 s^2 + s + 3

z=
0.0658 + 1.2565i
0.0658 - 1.2565i
-0.6316
p=
-1.7174
0.1087 + 0.9282i
0.1087 - 0.9282i
k=
1

unstable





 


R

R

R R R R   
















  
c

WAP to calculate the residues of any transfer function

 c

n=input('nter Îumerator')
d=input('nter enominator')
[r,p,k]=residue(n,m)

á  

nter Îumerator[2,3,1,3,2]
n=
2 3 1 3 2
nter enominator[1,3,2,4,1]
d=
1 3 2 4 1
r=
0.0180 + 0.0281i
0.0180 - 0.0281i
0.0089 - 0.0801i
0.0089 + 0.0801i
0.0307 + 0.1442i
0.0307 - 0.1442i
-0.0629 - 0.1529i
-0.0629 + 0.1529i
0.0714
-0.0607
p=
-1.0724 + 1.4349i
-1.0724 - 1.4349i
-0.4155 + 1.2075i
-0.4155 - 1.2075i
0.5724 + 0.9586i
0.5724 - 0.9586i
0.5806 + 0.8782i
0.5806 - 0.8782i
-1.0000
-0.8300
k=

[]
  
c

WAP to calculate the twiddle factor for 2, 4, 8.

 c

n=input('length')
dftmtx(n)

á  


    

length2

n=
2

ans =
1 1
1| -1

    

length4

n=
4

ans =
1.0000 1.0000 1.0000 1.0000
1.0000 0 - 1.0000i -1.0000 0 + 1.0000i
1.0000 -1.0000 1.0000 -1.0000
1.0000 0 + 1.0000i -1.0000 0 - 1.0000i

    

length8

n=
8

ans =
1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000
1.0000 0.7071 - 0.7071i 0 - 1.0000i -0.7071 - 0.7071i -1.0000
-0.7071 + 0.7071i 0 + 1.0000i 0.7071 + 0.7071i
1.0000 0 - 1.0000i -1.0000 0 + 1.0000i 1.0000
0 - 1.0000i -1.0000 0 + 1.0000i

1.0000 -0.7071 - 0.7071i 0 + 1.0000i 0.7071 - 0.7071i -1.0000


0.7071 + 0.7071i 0 - 1.0000i -0.7071 + 0.7071i

1.0000 -1.0000 1.0000 -1.0000 1.0000 -


1.0000 1.0000 -1.0000

1.0000 -0.7071 + 0.7071i 0 - 1.0000i 0.7071 + 0.7071i -1.0000


0.7071 - 0.7071i 0 + 1.0000i -0.7071 - 0.7071i

1.0000 0 + 1.0000i -1.0000 0 - 1.0000i 1.0000


0 + 1.0000i -1.0000 0 - 1.0000i

1.0000 0.7071 + 0.7071i 0 + 1.0000i -0.7071 + 0.7071i -1.0000


-0.7071 - 0.7071i 0 - 1.0000i 0.7071 - 0.7071i















  
c

WAP to calculate iscrete Fourier Transform ( FT) for 2, 4, 8. Also calculate
its Inverse iscrete Fourier Transform (I FT) to verify the result.

 c

x=input('nter any sequence')
n=input('nter Length')
y=fft(x,n)
z=ifft(y)

á  


    

nter any sequence[2,1,3,2,4,1]
x=
2 1 3 2 4 1

nter Length2
n=
2

y=
3 1

z=
2| 1

    

nter any sequence[2,1,3,2,4,1]
x=
2 1 3 2 4 1

nter Length4
n=
4

y=
8.0000 -1.0000 + 1.0000i 2.0000 -1.0000 - 1.0000i
z=
2 1 3 2

    

nter any sequence[2,1,3,2,4,1]
x=
2 1 3 2 4 1

nter Length8
n=
8

y=
13.0000 -3.4142 - 4.4142i 3.0000 -0.5858 + 1.5858i 5.0000
-0.5858 - 1.5858i 3.0000 -3.4142 + 4.4142i

z=
2 1 3 2 4 1 0 0





















  
c

WAP to calculate zero padding between two sequences.

 c

x1=input('nter 1st sequence')
x2=input('nter 2nd sequence')
a=length(x1)
b=length(x2)
if(a==b)
x1=[x1]
x2=[x2]
elseif(a>b)
n=a-b
x1=[x1]
x2=[x2,zeros(1,n)]
else
n=b-a
x1=[x1,zeros(1,n)]
x2=[x2]
end
|
á  

nter 1st sequence[1,2,3,1,2]
x1 =
1 2 3 1 2
nter 2nd sequence[3,2,1,3]
x2 =
3 2 1 3
a=
5
b=
4
n=
1

x1 =
1 2 3 1 2

x2 =
3 2 1 3 0
  
c

WAP to calculate circular convolution using FT and I FT method.

 c

x1=input('nter 1st sequence')
x2=input('nter 2nd sequence')
a=length(x1)
b=length(x2)
if(a==b)
x1=[x1]
x2=[x2]
p=fft(x1)
q=fft(x2)
r=p.*q
s=ifft(r)
elseif(a>b)
n=a-b
x1=[x1]
x2=[x2,zeros(1,n)]
p=fft(x1)
q=fft(x2)
r=p.*q
s=ifft(r)
else
n=b-a
x1=[x1,zeros(1,n)]
x2=[x2]
p=fft(x1)
q=fft(x2)
r=p.*q
s=ifft(r)
end

á  

nter 1st sequence[1,3,2,3]

x1 =
1 3 2 3
nter 2nd sequence[1,2,3,1,2]

x2 =
1 2 3 1 2

a=
4

b=
5

n=
1

x1 =
1 3 2 3 0

x2 =
1 2 3 1 2

p=
9.0000 -2.1180 - 2.2654i 0.1180 - 2.7144i 0.1180 + 2.7144i -2.1180
+ 2.2654i

q=
9.0000 -1.0000 - 1.1756i -1.0000 + 1.9021i -1.0000 - 1.9021i -
1.0000 + 1.1756i

r=
81.0000 -0.5451 + 4.7553i 5.0451 + 2.9389i 5.0451 - 2.9389i -
0.5451 - 4.7553i

s=
18 12 17 17 17





  
c

WAP to calculate circular convolution using function available in toolbox.

 c

x1=input('nter 1st sequence')
x2=input('nter 2nd sequence')
a=length(x1)
b=length(x2)
if(a==b)
c=cconv(x1,x2,a)
elseif(a>b)
c=cconv(x1,x2,a)
else
c=cconv(x1,x1,b)
end

á  

nter 1st sequence[2,1,3,2,1]

x1 =
2 1 3 2 1

nter 2nd sequence[2,1,3,2]

x2 =
2 1 3 2

a=
5

b=
4

c=
17 11 15 14 15
  
c

WAP to:-
1)| Plot poles and zeros for any transfer function.
2)| Calculate the roots of numerator and denominator of any transfer function.
3)| From the roots calculate polynomial coefficients of numerator and denominator.
4)| Calculate the frequency response of this transfer function:
ë| Magnitude response.
ë| Phase response.

 c

n=input('nter Coefficient of numerator ')


d=input('nter Coefficient of denominator ')
tf(n,d)
[z,p,k]=tf2zp(n,d)
zplane(n,d)
subplot(2,1,1)
r1=roots(n)
r2=roots(d)
p1=poly(r1)
p2=poly(r2)
freqz(n,d,250,500)
subplot(2,1,2)

á  

nter Coefficient of numerator [1,2,3,1,2]
n=
1 2 3 1 2

nter Coefficient of denominator [1,2,1,2,3]


d=
1 2 1 2 3

Transfer function:
s^4 + 2 s^3 + 3 s^2 + s + 2
---------------------------
s^4 + 2 s^3 + s^2 + 2 s + 3

z=
-1.1097 + 1.2377i
-1.1097 - 1.2377i
0.1097 + 0.8436i
0.1097 - 0.8436i

p=
0.4436 + 1.0818i
0.4436 - 1.0818i
-1.4436 + 0.3324i
-1.4436 - 0.3324i

k=
1

r1 =
-1.1097 + 1.2377i
-1.1097 - 1.2377i
0.1097 + 0.8436i
0.1097 - 0.8436i

r2 =
0.4436 + 1.0818i
0.4436 - 1.0818i
-1.4436 + 0.3324i
-1.4436 - 0.3324i

p1 =
1.0000 2.0000 3.0000 1.0000 2.0000

p2 =
1.0000 2.0000 1.0000 2.0000 3.0000
















 

R

R  R R   
 




 !

R

R 
     

 












     

 
  
c

WAP to calculate inverse z-transform for any transfer function by power series
expansion method.

ë|    
  £ £  £    

 c

n=input('nter Coefficient of numerator ')
d=input('nter Coefficient of denominator ')
a=length(n)
b=length(d)
if(a>b)
[q,r]=deconv(n,d)
else
x=4
n=[n,zeros(1,x-1)]
[q,r]=deconv(n,d)
end

á  

nter Coefficient of numerator [1 2 3 1 2]
n=
1 2 3 1 2
nter Coefficient of denominator [1 2 1 2 3]
d=
1 2 1 2 3
a=
5
b=
5
x=
4
n=
1 2 3 1 2 0 0 0
q=
1 0 2 -5
r=
0 0 0 0 7 1 4 15


ë|   
    £  £ 

 c

n1=input('nter Coefficient of 1st sequece of numerator ')
n2=input('nter Coefficient of 2nd sequece of numerator ')
n3=input('nter Coefficient of 3rd sequece of numerator ')

d1=input('nter Coefficient of 1st sequece of denominator ')


d2=input('nter Coefficient of 2nd sequece of denominator ')
d3=input('nter Coefficient of 3rd sequece of denominator ')

n=[n1;n2;n3]
d=[d1;d2;d3]
[num,den]=sos2tf([n,d])
a=length(num)
b=length(den)
if(a>b)
[q,r]=deconv(num,den)
else
x=4
num=[num,zeros(1,x-1)]
[q,r]=deconv(num,den)
end

á  

nter Coefficient of 1st sequece of numerator [1,2,3]
n1 =
1 2 3
nter Coefficient of 2nd sequece of numerator [1,1,1]
n2 =
1 1 1
nter Coefficient of 3rd sequece of numerator [2,1,2]
n3 =
2 1 2

nter Coefficient of 1st sequece of denominator [1,2,3]


d1 =
1 2 3
nter Coefficient of 2nd sequece of denominator [3,2,1]
d2 =
3 2 1
nter Coefficient of 3rd sequece of denominator [1,1,1]
d3 =
1 1 1

n=
1 2 3
1 1 1
2 1 2

d=
1 2 3
3 2 1
1 1 1

num =
2 7 17 22 23 13 6
den =
3 11 25 30 25 11 3

a=
7

b=
7

x=
4

num =
2 7 17 22 23 13 6 0 0 0

q=
0.6667 -0.1111 0.5185 -0.3086

r=
Columns 1 through 9

0 0 0 0 0.0988 0.6049 1.5185 2.3457 1.8395

Column 10

0.9259
  
c

WAP to design magnitude response for rectangular, hamming, hanning,
triangular, blackman and Kaiser window.

 c

n=input('order of filter ')
b=input('value of beta ')
w1=window(@rectwin,n)
w2=window(@hamming,n)
w3=window(@hann,n)
w4=window(@triang,n)
w5=window(@blackman,n)
w6=window(@kaiser,n)
plot(1:n,[w1,w2,w3,w4,w5,w6]);axis([1 n 0 1])
legend('rectwin','hamming','hann','triang','blackman','kaiser')

á  

order of filter 5
n=
5
value of beta 4
b=
4
w1 =
1
1
1
1
1
w2 =
0.0800
0.5400
1.0000
0.5400
0.0800
w3 =
0
0.5000
1.0000
0.5000
0
w4 =
0.3333
0.6667
1.0000
0.6667
0.3333
w5 =
-0.0000
0.3400
1.0000
0.3400
-0.0000
w6 =
0.9403
0.9849
1.0000
0.9849
0.9403




   


 
  












@

@ @       
  
c

WAP to designa FIR filter by using rectangular, hamming, hanning, triangular,
blackman and Kaiser windows for:
ë| LPF
ë| HPF
ë| BPF
ë| BSF

 c

ë|  


| 
£ 

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,rectwin(n+1))
freqz(b,1)
|


u

u
! "#$


u


uu
u u u u u u u u u u 
  º  


|  

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,hamming(n+1))
freqz(b,1)




u

! "#$
u


u


uu


u
u u  u  u  u  u  u  u  u  u 
    º   

|  

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,hann(n+1))
freqz(b,1)
|



u
!  "# $


 u


 u u


  u
u u  u  u  u  u  u  u  u  u 
          º      


| £ 

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,triang(n+1))
freqz(b,1)




u
!  "  #     $


 u


 u


 u
u u  u  u  u  u  u  u  u  u 
                 º         

| £
 

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,blackman(n+1))
freqz(b,1)



u
 



R u

R uu

R u
u u u  u  u  u  u  u  u  u 
 
    º 
  


| ÷  

n=input('order of filter ')
w=input('cut off frequency')
d=input('value of beta ')
b=fir1(n,w,kaiser(n+1,d))
freqz(b,1)



u
 



R u

R uu
u u u
u u u u u  u  u 
 
    º 
  


ë|  


| 
£ 

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,'high',rectwin(n+1))
freqz(b,1)



!  "#  $
u


 u


 u u
u u  u  u  u  u  u  u  u  u 
             º       


|  

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,'high',hamming(n+1))
freqz(b,1)




!  "# $

 
  
                    
         
  ! " #
          º      


|  

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,'high',hann(n+1))
freqz(b,1)




!  "# $

 
  
                    
         
       !  " #  º      


| £ 

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,'high',triang(n+1))
freqz(b,1)


u

! "#$
u


u


u


u
u u  u  u  u  u  u  u  u  u 
    º   


| £
 

n=input('order of filter ')
w=input('cut off frequency')
b=fir1(n,w,'high',blackman(n+1))
freqz(b,1)



u
!"#$


u


uu


u
u u u u u u u u u u 
 º  


| ÷  

n=input('order of filter ')
w=input('cut off frequency')
d=input('value of beta ')
b=fir1(n,w,'high',kaiser(n+1,d))
freqz(b,1)



u
!  "  #     $


 u


 u u
u u  u  u  u  u  u  u  u  u 
                 º         

ë|  


| 
£ 

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'bandpass',rectwin(n+1))
freqz(b,1)



!  "#  $

u


 u


 u u
u u  u  u  u  u  u  u  u  u 
             º       


|  

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'bandpass',hamming(n+1))
freqz(b,1)



!  "#  $

u


 u


 u u


  u
u u  u  u  u  u  u  u  u  u 
             º       


|  

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'bandpass',hann(n+1))
freqz(b,1)


u

!  "# $
u


 u


 u u


  u
u u  u  u  u  u  u  u  u  u 
          º       

| £ 

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'bandpass',triang(n+1))
freqz(b,1)
|


u
!"#$


u


u


u


u
u u u u u u u u u u 
 º  

| £
 

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'bandpass',blackman(n+1))
freqz(b,1)



u
!"#$


u


uu


u
u u u u u u u u u u 
 º   
| ÷  

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
d=input('value of beta ')
w=[w1 w2]
b=fir1(n,w,'bandpass',kaiser(n+1,d))
freqz(b,1)



u
!  "# $


 u


 u u


  u
u u  u  u  u  u  u  u  u  u 
          º      


ë|   


| 
£ 

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'stop',rectwin(n+1))
freqz(b,1)



$
*
! "#$

/ *$

/ &$ $ $ $ $ ' $ ( $ ) $ $ + $ , $ - $ .
%& % % % %* % % % % &
01  2  3  45 6  º   


|  

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'stop ',hamming(n+1))
freqz(b,1)



u
! "#$


u


uu
u u  u  u  u  u  u  u  u  u 
    º   


|  

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'stop ',hann(n+1))
freqz(b,1)



u
!  "# $


 u


 u u


  u
u u  u  u  u  u  u  u  u  u 
          º      


| £ 

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'stop ',triang(n+1))
freqz(b,1)
|



!  "# $
u


 u


 u u


  u
u u  u  u  u  u  u  u  u  u 
          º      


| £
 

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
w=[w1 w2]
b=fir1(n,w,'stop ',blackman(n+1))
freqz(b,1)



!  "# $

u


 u


 u u


  u
u u  u  u  u  u  u  u  u  u 
          º      


| ÷  

n=input('order of filter ')
w1=input('1st cut off frequency')
w2=input('2nd cut off frequency')
d=input('value of beta ')
w=[w1 w2]
b=fir1(n,w,' stop ',kaiser(n+1,d))
freqz(b,1)



u
!"#$


u


uu
u u  u  u  u  u  u  u  u  u 
  º  

  

c

WAP to convert analog filter to digital filter by using:
ë| IIM method
ë| BLT method.

 c


|cc  


n=input('nter Îumerator ')
d=input('nter enominator ')
fs=input('Sampling Frequency ')
[b,a]=impinvar(d,n,fs)

á  

nter Îumerator [1,2,1,2]
n=
1 2 1 2

nter enominator [2,1,3,2]


d=
2 1 3 2

Sampling Frequency .6
fs =
0.6000

b=
-1.6667 0.5136 -2.0594 -0.1189

a=
1.0000 0.1558 0.9932 -0.0357
|c  


n=input('nter Îumerator ')
d=input('nter enominator ')
fs=input('Sampling Frequency ')
[b,a]=bilinear(d,n,fs)

á  

nter Îumerator [1,2,1,2]
n=
1 2 1 2

nter enominator [2,1,3,2]


d=
2 1 3 2

Sampling Frequency .6
fs =
0.6000

b=
1.3443 -0.2828 1.4508 -0.4631

a=
1.0000 -0.1107 0.9098 0.2500
  

c

WAP to design a Butterworth LPF, HPF, BPF, BSF when passband is 4db and
stopband attenuation is 30db.
ë| For LPF and HPF:
Passband frequency=0.2rad/sec.
Stopband frequency=0.4rad/sec.
ë| For BPF and BSF:
Passband frequency=0.2rad/sec to 0.7rad/sec.
Stopband frequency=0.1rad/sec to 0.8rad/sec.

 c


|

Wp=0.2
Ws=0.4
Rp=4
Rs=30
[Î,Wn]=buttord(Wp,Ws,Rp,Rs)
[b,a]=butter(Î,Wn,'low')
freqz(b,a)

á  

Wp =
0.2000

Ws =
0.4000

Rp =
4

Rs =
30

Î=
5

Wn =
0.2223

b=
0.0020 0.0100 0.0201 0.0201 0.0100 0.0020
a=
1.0000 -2.7513 3.3365 -2.1353 0.7128 -0.0983



uu
$ #%&


uu


uu


uu
u u  u  u  u  u  u  u  u  u 
    º   

u
! "# 


uu


uu


uu
u u  u  u  u  u  u  u  u  u 
    º   


|

Wp=0.2
Ws=0.4
Rp=4
Rs=30
[Î,Wn]=buttord(Wp,Ws,Rp,Rs)
[b,a]=butter(Î,Wn,'high')
freqz(b,a)

á  

Wp =
0.2000

Ws =
0.4000

Rp =
4
Rs =
30

Î=
5

Wn =
0.2223

b=
0.3136 -1.5678 3.1357 -3.1357 1.5678 -0.3136

a=
1.0000 -2.7513 3.3365 -2.1353 0.7128 -0.0983



u
  

uu

uu

uu
u u u u u u u u u u 

 
 8  º 
  

uu
  


uu

uu
u u u u u u u u u u 

 
 7  º 
  
|
|

Wp=[0.2 0.7]
Ws=[0.1 0.8]
Rp=4
Rs=30
[Î,Wn]=buttord(Wp,Ws,Rp,Rs)
[b,a]=butter(Î,Wn,'bandpass')
freqz(b,a)

á  

Wp =
0.2000 0.7000

Ws =
0.1000 0.8000

Rp =
4

Rs =
30

Î=
6

Wn =
0.2019 0.6974

b=
Columns 1 through 12
0.0283 0 -0.1700 0 0.4250 0 -0.5667 0 0.4250 0
-0.1700 0

Column 13
0.0283

a=
Columns 1 through 12
1.0000 -1.3394 0.8398 -0.6611 1.1629 -0.8259 0.3178 -0.1708
0.1677 -0.0584 0.0090 -0.0027
Column 13
0.0018


u
$ #%&


uu


uu


uu


uu
u u  u  u  u  u  u  u  u  u 
    º   

uu
! "# 


uu


uuu
u u  u  u  u  u  u  u  u  u 
    º   

| 

Wp=[0.2 0.7]
Ws=[0.1 0.8]
Rp=4
Rs=30
[Î,Wn]=buttord(Wp,Ws,Rp,Rs)
[b,a]=butter(Î,Wn,'stop')
freqz(b,a)
|
á  

Wp =
0.2000 0.7000

Ws =
0.1000 0.8000

Rp =
4

Rs =
30
Î=
6

Wn =
0.2019 0.6974

b=
Columns 1 through 12
0.0309 -0.0820 0.2760 -0.4635 0.8438 -0.9836 1.1976 -0.9836
0.8438 -0.4635 0.2760 -0.0820

Column 13
0.0309

a=
Columns 1 through 12
1.0000 -1.3394 0.8398 -0.6611 1.1629 -0.8259 0.3178 -0.1708
0.1677 -0.0584 0.0090 -0.0027

Column 13
0.0018



u
^Y
W uu
V
U
W


]
\ uu
[
X


S
Z uu

uu
u u  u : u ; u < u  u > u ? u @ u A 
L
  C D  EF G EHIEJK  M º  DF NDC OEP

u
YT
U
U
X uu

U
W
V
U


T
S uuu
R
Q

B9= uu
u u 9 u : u ; u < u = u > u ? u @ u A 9
L
  C D  EF G EHIEJK  M º  DF NDC OEP

Vous aimerez peut-être aussi