You are on page 1of 13

Câu 1:Hàm dtft

Code:
function [X] = dtft(x,n,w);

X = x*exp(-j*n'*w);
end

1.1 cửa sổ hình chữ nhật:


code:
Hf_1 = figure;
set(Hf_1,'NumberTitle','off','Name','Rectangular');
w = linspace(-pi,pi,501);
wtick = (-1:0.5:1);
magtick = (0:0.5:1.1);
% M = 10
M = 10; n = 0:M; x = ones(1,length(n));
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,1);
plot(w/pi,magX,'b','LineWidth',1.5);
axis([-1 1 0 1.1]);
title('M = 10');
xlabel('\omega/\pi'); ylabel('|X|');
% M = 25
M = 25; n = 0:M; x = ones(1,length(n));
X = dtft(x,n,w);
magX = abs(X); magX = magX/max(magX);
subplot(2,2,2);
plot(w/pi,magX,'g','LineWidth',1.5);
axis([-1 1 0 1.1]);
title('M = 25');
xlabel('\omega/\pi'); ylabel('|X|');
% M = 50
M = 50; n = 0:M; x = ones(1,length(n));
X = dtft(x,n,w);
magX = abs(X); magX = magX/max(magX);
subplot(2,2,3);
plot(w/pi,magX,'r','LineWidth',1.5);
axis([-1 1 0 1.1]);
title('M = 50');
xlabel('\omega/\pi'); ylabel('|X|');

% M = 101
M = 101; n = 0:M; x = ones(1,length(n));
X = dtft(x,n,w);
magX = abs(X); magX = magX/max(magX);
subplot(2,2,4);
plot(w/pi,magX,'y','LineWidth',1.5);
axis([-1 1 0 1.1]);
title('M = 101');
xlabel('\omega/\pi'); ylabel('|X|');

hình ảnh trên matlab

1.2 cửa sổ hamming


code:
clc; close all;
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','hamming');
w = linspace(-pi,pi,501);
wtick = [-1:0.5:1];
magtick = [0:0.5:1.1];
% M = 10
M = 10; n = 0:M;
x = (0.54-0.46*cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X); magX = magX/max(magX);
subplot(2,2,1);
plot(w/pi,magX,'b','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|'); title(['M = 10']);
xlabel('\omega/\pi')
% M = 25
M = 25; n = 0:M;
x = (0.54-0.46*cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X); magX = magX/max(magX);
subplot(2,2,2);
plot(w/pi,magX,'g','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|'); title(['M = 25']);
xlabel('\omega/\pi')
% M = 50
M = 50; n = 0:M;
x = (0.54-0.46*cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X); magX = magX/max(magX);
subplot(2,2,3);
plot(w/pi,magX,'r','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|'); title(['M = 50']);
xlabel('\omega/\pi')
% M = 100
M = 100; n = 0:M;
x = (0.54-0.46*cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X); magX = magX/max(magX);
subplot(2,2,4);
plot(w/pi,magX,'y','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|'); title(['M = 100']);
xlabel('\omega/\pi')

hình ảnh trên matlab:

1.3 cửa sổ hanning


code :
clc; close all;
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','hanning');
w = linspace(-pi,pi,501); wtick = [-1:0.5:1]; magtick = [0:0.5:1.1];
% M = 10
M = 10; n = 0:M; x = 0.5*(1-cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,1);
plot(w/pi,magX,'b','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['M = 10']);
xlabel('\omega/\pi')
% M = 25
M = 25; n = 0:M; x = 0.5*(1-cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,2);
plot(w/pi,magX,'g','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['M = 25']);
xlabel('\omega/\pi')
% M = 50
M = 50; n = 0:M; x = 0.5*(1-cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,3);
plot(w/pi,magX,'r','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['M = 50']);
xlabel('\omega/\pi')
% M = 101
M = 101; n = 0:M; x = 0.5*(1-cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,4);
plot(w/pi,magX,'y','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['M = 101']);
xlabel('\omega/\pi')

hình ảnh trên matlab:


1.4 cửa sổ tam giác
code :
clc; close all;
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','tamgiac');
w = linspace(-pi,pi,501); wtick = [-1:0.5:1]; magtick = [0:0.5:1.1];
% M = 10
M = 10; n = 0:M;
x = (1-(abs( M-1-(2*n) )/(M+1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,1);
plot(w/pi,magX,'b','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|'); title(['M = 10']);
xlabel('\omega/\pi')
% M = 25
M = 25; n = 0:M;
x = (1-(abs( M-1-(2*n) )/(M+1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,2);
plot(w/pi,magX,'g','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['M = 25']);
xlabel('\omega/\pi')
% M = 50
M = 50; n = 0:M;
x = (1-(abs( M-1-(2*n) )/(M+1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,3);
plot(w/pi,magX,'r','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['M = 50']);
xlabel('\omega/\pi')
% M = 101
M = 101; n = 0:M;
x = (1-(abs( M-1-(2*n) )/(M+1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,4);
plot(w/pi,magX,'y','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['M = 101']);
xlabel('\omega/\pi')

hình ảnh trên matlab:

1.5 cả 4 cửa sổ với M=10


code:

clc; close all;


Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','4 cua so voi M=10');
w = linspace(-pi,pi,501); wtick = [-1:0.5:1]; magtick = [0:0.5:1.1];
%cua so chu nhat voi M = 10
M = 10; n = 0:M; x = ones(1,length(n));
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,1);
plot(w/pi,magX,'b','LineWidth',1.5);
axis([-1 1 0 1.1]);
title(' cua so chu nhat voi M = 10');
xlabel('\omega/\pi'); ylabel('|X|');

% cua so hamming voiM = 10


M = 10; n = 0:M;
x = (0.54-0.46*cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,2);
plot(w/pi,magX,'g','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['cua so hamming voi M = 10']);
xlabel('\omega/\pi')

%cua so hanning voi M = 10


M = 10; n = 0:M; x = 0.5*(1-cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,3);
plot(w/pi,magX,'r','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title([' cua so hanning voi M = 10']);
xlabel('\omega/\pi')

%cua so tam giac voi M = 10


M = 10; n = 0:M;
x = (1-(abs( M-1-(2*n) )/(M+1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,4);
plot(w/pi,magX,'y','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|'); title(['cua so tam giac voi M = 10']);
xlabel('\omega/\pi')

hình ảnh trên matlab:


1.6 cả 4 cửa sổ với M=25
code:
clc; close all;
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','4 cua so voi M=25');
w = linspace(-pi,pi,501); wtick = [-1:0.5:1]; magtick = [0:0.5:1.1];
%cua so chu nhat voi M = 25
M = 25; n = 0:M; x = ones(1,length(n));
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,1);
plot(w/pi,magX,'b','LineWidth',1.5);
axis([-1 1 0 1.1]);
title(' cua so chu nhat voi M = 25');
xlabel('\omega/\pi'); ylabel('|X|');

% cua so hamming voi M = 25


M = 25; n = 0:M;
x = (0.54-0.46*cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,2);
plot(w/pi,magX,'g','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['cua so hamming voi M = 25']);
xlabel('\omega/\pi')

%cua so hanning voi M = 25


M = 25; n = 0:M; x = 0.5*(1-cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,3);
plot(w/pi,magX,'r','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title([' cua so hanning voi M = 25']);
xlabel('\omega/\pi')

%cua so tam giac voi M = 25


M = 25; n = 0:M;
x = (1-(abs( M-1-(2*n) )/(M+1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,4);
plot(w/pi,magX,'y','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|'); title(['cua so tam giac voi M = 25']);
xlabel('\omega/\pi')

hình ảnh trên matlab:

1.7 cả 4 cửa sổ với M=50


code:
clc; close all;
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','4 cua so voi M=50');
w = linspace(-pi,pi,501); wtick = [-1:0.5:1]; magtick = [0:0.5:1.1];
%cua so chu nhat voi M = 50
M = 50; n = 0:M; x = ones(1,length(n));
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,1);
plot(w/pi,magX,'b','LineWidth',1.5);
axis([-1 1 0 1.1]);
title(' cua so chu nhat voi M = 50');
xlabel('\omega/\pi'); ylabel('|X|');

% cua so hamming voiM = 50


M = 50; n = 0:M;
x = (0.54-0.46*cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,2);
plot(w/pi,magX,'g','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['cua so hamming voi M = 50']);
xlabel('\omega/\pi')

%cua so hanning voi M = 50


M = 50; n = 0:M; x = 0.5*(1-cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,3);
plot(w/pi,magX,'r','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title([' cua so hanning voi M = 50']);
xlabel('\omega/\pi')

%cua so tam giac voi M = 50


M = 50; n = 0:M;
x = (1-(abs( M-1-(2*n) )/(M+1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,4);
plot(w/pi,magX,'y','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|'); title(['cua so tam giac voi M = 50']);
xlabel('\omega/\pi')

hình ảnh trên matlab:


1.8 cả 4 cửa sổ với M=101
code:
clc; close all;
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','4 cua so voi M=101');
w = linspace(-pi,pi,501); wtick = [-1:0.5:1]; magtick = [0:0.5:1.1];
%cua so chu nhat voi M = 101
M = 101; n = 0:M; x = ones(1,length(n));
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,1);
plot(w/pi,magX,'b','LineWidth',1.5);
axis([-1 1 0 1.1]);
title(' cua so chu nhat voi M = 101');
xlabel('\omega/\pi'); ylabel('|X|');

% cua so hamming voi M = 101


M = 101; n = 0:M;
x = (0.54-0.46*cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,2);
plot(w/pi,magX,'r','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title(['cua so hamming voi M = 101']);
xlabel('\omega/\pi')

%cua so hanning voi M = 101


M = 101; n = 0:M; x = 0.5*(1-cos((2*pi*n)/(M-1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,3);
plot(w/pi,magX,'g','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|');
title([' cua so hanning voi M = 101']);
xlabel('\omega/\pi')

%cua so tam giac voi M = 101


M = 101; n = 0:M;
x = (1-(abs( M-1-(2*n) )/(M+1)) );
X = dtft(x,n,w);
magX = abs(X);
magX = magX/max(magX);
subplot(2,2,4);
plot(w/pi,magX,'y','LineWidth',1.5);
axis([-1 1 0 1.1]);
ylabel('|X|'); title(['cua so tam giac voi M = 101']);
xlabel('\omega/\pi')
hình ảnh trên matlab:

You might also like