0% found this document useful (0 votes)
22 views59 pages

Matlab

Uploaded by

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

Matlab

Uploaded by

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

sine 1hz

t = [0: 0.01 : 2];


f = 1;
a = sin(2*pi*f*t);
plot(t,a)

sine 2hz

t = [0: 0.02 : 1];


f = 2;
a = sin(2*pi*f*t);
plot(t,a)

1
sine 10hz

t = [0: 0.001 : 0.2];


f = 10;
a = sin(2*pi*f*t);
plot(t,a)

2
sin t

t = [0 : 0.01 : 4*pi];
y = sin(t);
plot(t,y)

3
sin 2 pi t

t = [0 : 0.01 : 2];
y = sin(2*pi*t);
plot(t,y)

4
sin pi t

t = [0 : 0.001 : 2];
y = sin(pi*t);
plot(t,y)

5
cos 2 pi t

t = [0 : 0.001 : 2];
y = cos(2*pi*t);
plot(t,y)

6
impulse

t = (-1:0.001:1)';
im = t==0;
plot(t,im)

7
step

t = (-1:0.01:1);
unt = t>=0;
plot(t,unt)

8
ramp

t = (-1:0.01:1);
ramp_fn = t.*unt;
plot(t,ramp_fn)

9
rectang

t = (-10:0.01:10);
rect = t>=-1 & t<=1;
plot(t,rect)

10
triangl

t = (0:0.01:2);
unt = t>=0 & t<=1;
trian = t.*unt;
plot(t,trian)
hold on
unt = t>1 & t<=2;
tr = -t.*unt;
tr =2+tr;
plot(t,tr)
hold off

11
expo in

t = [0:0.01:5];
plot(exp(t))

12
expo dec

t = [0:0.01:5];
plot(exp(-t))

13
sinc

t = [-4 : 0.01 : 4];


y = sin(pi*t)./(pi*t);
plot(t,y)

14
sa

t = [-10 : 0.01 : 10];


y = sin(t)./(t);
plot(t,y)

15
sin t

sample_rate = 40;
t = [0:2*pi/sample_rate:2*pi];
f=1;
y = sin(2*pi*f*t);
stem(t,y)

16
sini 2 pi t

sample_rate = 40;
t = [0:2*pi/sample_rate:2*pi];
f=2;
y = sin(2*pi*f*t);
stem(t,y)

17
**

sample_rate = 40;
t = [0:2*pi/sample_rate:2*pi];
f=10;
y = sin(2*pi*f*t);
stem(t,y)

18
sin

n = [0:0.1:2*pi];
y=sin(n);
stem(n,y)

19
cos

n = [0:0.1:2*pi];
y=cos(n);
stem(n,y)

20
comb

stem(ones(1,10))
ylim([0, 2]);

21
impulse

n = (-10:1:10)';
im = n==0;
stem(n,im)

22
step

n = (-1:0.1:1)';
unt = n>=0;
stem(n,unt)

23
ramp

n = (-1:0.1:1)';
ramp_fn = n.*un_st;
stem(n,ramp_fn)

24
rec

n = (-5:0.1:5);
rect = n>=-1 & n<=1;
stem(n,rect)

25
tri

n = (0:0.01:2);
unt = n>=0 & n<=1;
trian = n.*unt;
plot(n,trian)
hold on
unt = n>1 & n<=2;
tr = -n.*unt;
tr =2+tr;
stem(n,tr)
hold off

26
expo in

n = [0:0.1:5];
stem(exp(n))

27
expo dec

n = [0:0.1:5];
stem(exp(-n))

28
sinc

n = [-4 : 0.1 : 4];


y = sin(pi*n)./(pi*n);
stem(n,y)

29
sa

n = [-10 : 0.2 : 10];


y = sin(n)./(n);
stem(n,y)

30
experiment 2

sin t

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=sin(t)

x = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700

plot(t,x)

31
cos t

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=cos(t)

x = 1×1000
1.0000 0.9999 0.9998 0.9995 0.9992 0.9987 0.9982 0.9975

plot(t,x)

32
cos (t+pi/4)

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=cos(t+(pi/4))

x = 1×1000
0.7071 0.7000 0.6928 0.6856 0.6782 0.6708 0.6634 0.6559

plot(t,x)

33
cos (t-pi/4)

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=cos(t-(pi/4))

x = 1×1000
0.7071 0.7141 0.7211 0.7280 0.7348 0.7416 0.7483 0.7549

plot(t,x)

34
sin(-t)

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=sin(-t)

x = 1×1000
0 -0.0100 -0.0200 -0.0300 -0.0400 -0.0500 -0.0600 -0.0700

plot(t,x)

35
siin(t/2)

t=linspace(0,100,1000)

t = 1×1000
0 0.1001 0.2002 0.3003 0.4004 0.5005 0.6006 0.7007

x=sin(t/2)

x = 1×1000
0 0.0500 0.0999 0.1496 0.1989 0.2476 0.2958 0.3432

plot(t,x)

36
sin(2t)

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=sin(2*t)

x = 1×1000
0 0.0200 0.0400 0.0600 0.0800 0.0999 0.1198 0.1397

plot(t,x)

37
sin(2t+1)

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=sin((2*t)+1)

x = 1×1000
0.8415 0.8521 0.8624 0.8724 0.8820 0.8913 0.9002 0.9087

plot(t,x)

38
sin t + cos t

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=sin(t)

x = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700

y=cos(t)

y = 1×1000
1.0000 0.9999 0.9998 0.9995 0.9992 0.9987 0.9982 0.9975

z=x+y

z = 1×1000
1.0000 1.0100 1.0198 1.0296 1.0392 1.0488 1.0582 1.0676

plot(t,z)

39
sint + cos(t+pi/4)

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=sin(t)

x = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700

y=cos(t+(pi/4))

y = 1×1000
0.7071 0.7000 0.6928 0.6856 0.6782 0.6708 0.6634 0.6559

z=x+y

z = 1×1000
0.7071 0.7100 0.7128 0.7156 0.7183 0.7209 0.7234 0.7259

plot(t,z)

40
3sin(-t)-2sin(2t+1)

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=3*sin(-t)

x = 1×1000
0 -0.0300 -0.0601 -0.0901 -0.1201 -0.1501 -0.1801 -0.2100

y=2*sin((2*t)+1)

y = 1×1000
1.6829 1.7042 1.7248 1.7448 1.7640 1.7825 1.8003 1.8174

z=x-y

z = 1×1000
-1.6829 -1.7343 -1.7849 -1.8348 -1.8841 -1.9326 -1.9804 -2.0274

plot(t,z)

41
multiply and plot

t=linspace(0,10,1000)

t = 1×1000
0 0.0100 0.0200 0.0300 0.0400 0.0501 0.0601 0.0701

x=sin(t/2)

x = 1×1000
0 0.0050 0.0100 0.0150 0.0200 0.0250 0.0300 0.0350

y=-3*cos(t-(pi/4))

y = 1×1000
-2.1213 -2.1424 -2.1634 -2.1841 -2.2045 -2.2248 -2.2448 -2.2646

z=x.*y

z = 1×1000
0 -0.0107 -0.0217 -0.0328 -0.0441 -0.0557 -0.0674 -0.0793

plot(t,z)

42
con inbulit

x=[1,2,3,4]

x = 1×4
1 2 3 4

stem(x)

43
h=[1,1,1]

h = 1×3
1 1 1

stem(h)

44
y=conv(x,h)

y = 1×6
1 3 6 9 7 4

stem(y)

45
cir con inbuilt

x=[1,2,3,4]

x = 1×4
1 2 3 4

stem(x)

46
h=[1,1,1]

h = 1×3
1 1 1

stem(h)

47
y=cconv(x,h)

y = 1×6
1 3 6 9 7 4

stem(y)

48
con without

x=[1,2,3,4]

x = 1×4
1 2 3 4

stem(x)

49
h=[1,1,1]

h = 1×3
1 1 1

stem(h)

50
xpad = [x zeros(1,6-length(x))];
hpad = [h zeros(1,6-length(h))];
ccirc = ifft(fft(xpad).*fft(hpad));
stem(ccirc)

51
circ without

x=[1,2,3,4]

x = 1×4
1 2 3 4

stem(x)

52
h=[1,1,1]

h = 1×3
1 1 1

stem(h)

53
N = length(x)+length(h)-1;
xpad = [x zeros(1,12-length(x))];
hpad = [h zeros(1,12-length(h))];
ccirc = ifft(fft(xpad).*fft(hpad));
ccirc = ccirc(1:N);
stem(ccirc)

54
linear using circular

x=[1,2,3,4]

x = 1×4
1 2 3 4

stem(x)

55
h=[1,1,1]

h = 1×3
1 1 1

stem(h)

56
n=max(length(x),length(h))

n = 4

xpad = [x zeros(1,n-length(x))];
hpad = [h zeros(1,n-length(h))];
f=cconv(xpad,hpad)

f = 1×7
1.0000 3.0000 6.0000 9.0000 7.0000 4.0000 0.0000

stem(f)

57
cross correlation

a = [1 2 2 1]+1i;
b = [1 3 4 1]-2*1i;
c = cconv(a,conj(fliplr(b)),7);
y=corrcoef(c)

y = 1

stem(c)

Warning: Using only the real component of complex data.

58
59

You might also like