You are on page 1of 14

Applied Signal

Processing Lab
Introduction to Matlab

Submitted to: Isra Nazir


Submitted by: Muhammad Abdullah
Group Member:
Roll Number: 2015-BT-BMED-19
Roll Number: 2015-BT-BMED-
Roll Number: 2015-BT-BMED-
Department: Bio-medical engineering
technology

Muhammad Abdullah
UNIVERSITY OF ENGINEERING AND TECHNOLOGY KSK
LAHORE
>> %Lab Task
>> 3+7.5

ans =

10.5000

>> 18/4

ans =

4.5000

>> 3*7

ans =

21

>> 3^2

ans =

9
%Example 1:
>> a=5;x=2;y=8
>> y=exp(-a)*sin(x)+10*sqrt(y)

y=

28.2904

>>
>> %Example 2:
>> sin(pi/4)

ans =

0.7071

>> exp(10)

ans =

2.2026e+04
>> A=[1 2 3; 4 5 6; 7 8 9]
A=

1 2 3
4 5 6
7 8 9

>> A=[1,2,3;4,5,6;7,8,9];
>> A=[1,2,3;4,5,6;7,8,9]

A=

1 2 3
4 5 6
7 8 9

>>
>> a=[
123
456
7 8 9]

a=

1 2 3
4 5 6
7 8 9

>>
>> b=a'

b=

1 4 7
2 5 8
3 6 9

>>
>> a=[1 2 3 4 ; 5 6 7 8]

a=

1 2 3 4
5 6 7 8

>> a(:,:)

ans =
1 2 3 4
5 6 7 8

>> a(1,2)

ans =

>> a(1,:)

ans =

1 2 3 4

>> a(:,[1,3])

ans =

1 3
5 7

>> a(:,end) % in lab manual Ans is 3


% 7
ans =

4
8
>> b=a(:,3:end)

b=

3 4
7 8

>> diag(b)

ans =

3
8

>> >> %changing and deleting matrix elements:


>> a=1:5

a=
1 2 3 4 5

>> a(2)=6

a=

1 6 3 4 5

>> a([1 3])=0

a=

0 6 0 4 5

>> %Manipulating Matrix:


>> a=[1 3 4; 5 7 8]

a=

1 3 4
5 7 8

>> A'

ans =

1 4 7
2 5 8
3 6 9

>> Flipr(a)
Undefined function 'Flipr' for input arguments of type 'double'.

Did you mean:


>> fliplr(a)

ans =

4 3 1
8 7 5

>> >> flipud(a)

ans =

5 7 8
1 3 4

>> >> a=[2 3 4;5 6 7;2 1 0];


>> b=[1 2 3;5 6 2;0 0 5];
>> a*b

ans = % in lab manual ans


is
17 22 32
17 22 32 40 52 59
35 46 62 7 10 8
7 10 8

>> >> a.*b

ans = % in lab manual ans


is
26 12
2 6 12 25 42 12
25 36 14 0 0 0
0 0 0

>>%basic plotting
>> x=[1 2 3 4 5 6];
>> y=[3 -1 2 4 5 1];
>> plot(x,y)
>>

>> X=0:pi/100: 2*pi;


>> y=sin(x);
>> plot(x,y)
>> >> %adding title and
axis labels:
>> xlabel('x= 0:2\pi');
>> ylabel('sine of x');
>> title('plot of the Sine
Function')
>>

>> %Multiple data set in one plot:


>> x=0:pi/100:2*pi;
>> y1=2*cos(x);
>> y2=cos(x);
>> y3=0.5*cos(x);
>> plot(x,y1, '--',x,y2,'--
',x,y3,':')
>> xlabel('0\leq x \leq 2\pi')
>> ylabel(cosine functions)

>>legend('2*cos(x)','cos(x)','0.5*cos(x)')
>> axis([0 2*pi -3 3])
>> %This is a sample m-file
>> a=[1,2,3;0,1,1;1,2,3]

a=

1 2 3
0 1 1
1 2 3

>> b=a';
>> c=a+b

c=

2 2 4
2 2 3
4 3 6

>> d=inv(c)

d=

-1.500000000000000 0 1.000000000000000
0 2.000000000000000 -1.000000000000000
1.000000000000000 -1.000000000000000 0

>>
run the matlab as administrator
%This is a sample m-file
run the matlab as administrator
Home>new>function then past the code
function y = prod(a,b)
y=a*b;
save with the name as prod.m
>> prod enter
ans =

>>
run the matlab as administrator
Home>new>function then past the code
%This is a sample m-file
a=[1,2,3;0,1,1;1,2,3]
b=a';
c=a+b
d=inv(c)
save with the name as rkg.m
>> rkg enter

a=

1 2 3
0 1 1
1 2 3

c=

2 2 4
2 2 3
4 3 6

d=

-1.5000 0 1.0000
0 2.0000 -1.0000
1.0000 -1.0000 0

>>% the load function:


Create a text file containing these four lines
16.0 3.0 2.0 13.0
5.0 10.0 11.0 8.0
9.0 6.0 7.0 12.0
4.0 15.0 14.0 1.0
Save the file as magik.dat
Click at import dataSelect magik.dat file from the location open
%Exercise:
%Q #1
>> x = -5 + 9*i

x=

-5.0000 + 9.0000i

>> y = 6 -2*i

y=

6.0000 - 2.0000i

>> x-y

ans =

-11.0000 +11.0000i

>>
>> x*y

ans =

-12.0000 +64.0000i

>> x/y

ans =
-1.2000 + 1.1000i

>>%Q #2

>> 6*(35^1.4)+14^0.35

ans =

873.1743

>>%Q #3
>>
x=[1:1.5/1000:1.4999];
>> y = 4*(sqrt((6*x) +
1));
>> z = 5*(exp(0.3*x))-
(2*x);
>> plot(x,y,'--',x,z,'-- ')
>> xlabel('0< x< 1.5')
>> ylabel('Algebric
functions')
>>
legend('4*(sqrt((6*x) +
1))','5*(exp(0.3*x))-
(2*x)')
>> axis([1 1.5 4 15])

>>%Q #4
>> t=[1:5/1000:4.9999];
>> s=2*sin(3*t+2)+sqrt(5*t+1);
>> plot(t,s,'--')
>> xlabel('0< t< 5')
>> ylabel('Trignometric functions')
>> legend('2*sin(3*t+2)+sqrt(5*t+1)')
>> axis([1 5 0 8])
>>%Q #5
>> x=[0:pi/1000:2*pi];
>> y=[exp(-x)].*sin(8*x);
>> plot(x,y,'--')
>> xlabel('0\leq x \leq 2\pi')
>> ylabel('Exponential and
Trigonometric function')
>> legend('[exp(-
x)].*sin(8*x)')
>> axis([0 2*pi -0.6 1])
>>

>>%Q #6
>> x=[-pi:pi/1000:pi];
>> y=(4/pi)*[(sin(x))+(sin(3*x)/3)+(sin(5*x)/5)+(sin(7*x)/7)];
>> plot(x,y,'--')
>> xlabel('-pi< x<pi')
>> ylabel('Forier Series')
>> legend('(4/pi)*[(sin(x))+(sin(3*x)/3)+(sin(5*x)/5)+(sin(7*x)/7)]')
>>axis([-4 4 -1.5 1.5]
>>%Q #7
>> a= [1 1 1;0 0 0;0 0 0;0 0 0]

a=

1 1 1
0 0 0
0 0 0
0 0 0

>>%Q#8
%Solve set of equations
>> syms x
>> syms y
>> syms y
>> eqn1= 6*x-4*y+8*z==112;
>> eqn2= -5*x-3*y+7*z==75;
>> eqn3= 14*x+9*y-5*z==-67;
>> [a,b]=equationsToMatrix([eqn1,eqn2,eqn3],[x,y,z]);
>> x=linsolve(a,b)

x=

2
-5
10

>>

You might also like