Bai 1
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
pho_bien_do =
pho_pha =
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
A=
u=
Nhap 1 so bat ky 1
T=
t=
Columns 1 through 9
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
y=
Columns 1 through 9
Columns 10 through 18
Columns 19 through 21
ans =
Columns 1 through 9
Columns 10 through 18
Columns 19 through 21
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
end 1 1
0.8 0.8
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