Bai 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Bai 1

n=0:255;

f1=1/288;

f2=5/128;

xn=cos(2*pi*f1*n)+cos(2*pi*f2*n)

subplot(3,1,1)

plot(n,xn)

fc=50/108;

xcn=cos(2*pi*fc*n)

subplot(3,1,2)

plot(n,xcn)

xam=xn.*xcn

subplot(3,1,3)

plot(n,xam)

grid

bai 2

clc
clear all
x1=1:6;
X=fft(x1)
pho_bien_do=abs(X)
pho_pha=angle(X)
subplot(2,1,1)
stem(pho_bien_do)
subplot(2,1,2)
stem(pho_pha)
grid
X=

Columns 1 through 4
21.0000 + 0.0000i -3.0000 + 5.1962i -3.0000 + 1.7321i -3.0000 + 0.0000i

Columns 5 through 6

-3.0000 - 1.7321i -3.0000 - 5.1962i

pho_bien_do =

21.0000 6.0000 3.4641 3.0000 3.4641 6.0000

pho_pha =

0 2.0944 2.6180 3.1416 -2.6180 -2.0944

Bai 3

clc
clear all
A=input('Nhap bien do ban thich ')
w=2*pi;
u=input('Nhap goc pha ')
T=input('Nhap 1 so bat ky ')
t=0:0.05:T

Nhap bien do ban thich 1

A=

Nhap goc pha 1

u=

Nhap 1 so bat ky 1

T=

t=

Columns 1 through 9

0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500 0.4000

Columns 10 through 18
0.4500 0.5000 0.5500 0.6000 0.6500 0.7000 0.7500 0.8000 0.8500

Columns 19 through 21

0.9000 0.9500 1.0000

y=

Columns 1 through 9

0.8415 0.9672 0.9983 0.9317 0.7739 0.5403 0.2538 -0.0575 -0.3632

Columns 10 through 18

-0.6333 -0.8415 -0.9672 -0.9983 -0.9317 -0.7739 -0.5403 -0.2538 0.0575

Columns 19 through 21

0.3632 0.6333 0.8415

ans =

Columns 1 through 9

0.8415 0.9672 0.9983 0.9317 0.7739 0.5403 0.2538 -0.0575 -0.3632

Columns 10 through 18

-0.6333 -0.8415 -0.9672 -0.9983 -0.9317 -0.7739 -0.5403 -0.2538 0.0575

Columns 19 through 21

0.3632 0.6333 0.8415

Bai 4

x=-10:1:10
y=[zeros(1,5) 2*(ones(1,11)) zeros(1,5)]
subplot(2,2,1)
stem(x,y)
axis([-10 10 0 6])
grid on
y2=[5*(ones(1,7)) zeros(1,7) 5*(ones(1,7))]
subplot(2,2,2)
stem(x,y2)
axis([-10 10 0 6])
grid on
X=fft(x)
pho_bien_do=abs(X)
pho_pha=angle(X)
subplot(2,2,3)
stem(pho_bien_do)
subplot(2,2,4)
stem(pho_pha)
grid on

x=-10:1:10
y=[zeros(1,5) 2*(ones(1,11)) zeros(1,5)]
subplot(2,2,1)
stem(x,y)
axis([-10 10 0 6])
grid on
y2=[5*(ones(1,7)) zeros(1,7)
5*(ones(1,7))]
subplot(2,2,2)
stem(x,y2)
axis([-10 10 0 6])
grid on
subplot(2,2,3)
plot(x,y)
axis([-10 10 0 6])
grid on
subplot(2,2,4)
plot(x,y2)
axis([-10 10 0 6])

x=-10:1:10
for i=1:length(x)
if abs(x(i))>=3
y(i)=5
else
y(i)=0
end
end
subplot(2,2,1)
plot(x,y)
xlabel('111')
subplot(2,2,2)
X=fft(y)
stem(X)
xlabel('112')

x=-10:1:10
for i=1:length(x)
if abs(x(i))<=5
y(i)=2
else
y(i)=0
end
end
subplot(2,2,1)
plot(x,y)
xlabel('111')
subplot(2,2,2)
X=fft(y)
stem(X)
xlabel('121')

x=-10:1:10
for i=1:length(x)
if abs(x(i))<=5
2 2

y(i)=2 1.8 1.8

else 1.6 1.6

y(i)=0 1.4 1.4

end 1.2 1.2

end 1 1

0.8 0.8

for i=1:length(x) 0.6 0.6

if x(i)<=7 && x(i)>=-3 0.4 0.4

y2(i)=2 0.2 0.2

else 0 0

y2(i)=0 -10 -8 -6 -4 -2 0
111
2 4 6 8 10 -10 -8 -6 -4 -2 0
121
2 4 6 8 10

end
end
subplot(1,2,1)
stem(x,y)
xlabel('111')
grid on
subplot(1,2,2)
stem(x,y2)
xlabel('121')
grid on

x=-10:1:10
for i=1:length(x)
if abs(x(i))<=5
2 2

1.5 1.5

1 1

0.5 0.5

0 0
-10 -8 -6 -4 -2 0 2 4 6 8 10 -10 -8 -6 -4 -2 0 2 4 6 8 10
111 121

1.5

0.5

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

y(i)=2
else
y(i)=0
end
end

for i=1:length(x)
if x(i)<=7 && x(i)>=-3
y2(i)=2
else
y2(i)=0
end
end
for i=1:length(x)
if x(i)>=-7 && x(i)<=3
y3(i)=2
else
y3(i)=0
end
end
subplot(2,2,1)
stem(x,y)
xlabel('111')
grid on
subplot(2,2,2)
stem(x,y2)
xlabel('121')
grid on
subplot(2,2,3)
stem(x,y3)
xlabel('123')
grid on

You might also like