📄 复件 main.m
字号:
function main()
n=0:1:20;
t=0:0.01:2*pi;
fs=64;
N1=8;
N2=16;
N3=32;
N4=64;
x1=s1(n,4); %产生信号
x2=s2(n);
x3=s3(n);
x4=s4(n);
x5=s5(n);
x6=s6(t);
figure; %绘时域信号图
subplot(3,2,1);
stem(n,x1,'.');
title('x1(n)时域图');
xlabel('n');
ylabel('x1(n)');
subplot(3,2,2);
stem(n,x2,'.');
title('x2(n)时域图');
xlabel('n');
ylabel('x2(n)');
subplot(3,2,3);
stem(n,x3,'.');
title('x3(n)时域图');
xlabel('n');
ylabel('x3(n)');
subplot(3,2,4);
stem(n,x4,'.');
title('x4(n)时域图');
xlabel('n');
ylabel('x4(n)');
subplot(3,2,5);
stem(n,x5,'.');
title('x5(n)时域图');
xlabel('n');
ylabel('x5(n)');
subplot(3,2,6);
plot(t,x6);
title('x6(t)时域图');
xlabel('t');
ylabel('x6(t)');
X1=fft(x1,N1);
X2=fft(x2,N1);
X3=fft(x3,N1);
X4=fft(x4,N1);
X5=fft(x5,N1);
figure; %频域图 N1=8
i=0:N1-1;
subplot(3,2,1);
stem(i,abs(X1),'.');
title('x1幅频特性(N=8)');
xlabel('k');
ylabel('|X1|');
subplot(3,2,2);
stem(i,abs(X2),'.');
title('x2幅频特性(N=8)');
xlabel('k');
ylabel('|X2|');
subplot(3,2,3);
stem(i,abs(X3),'.');
title('x3幅频特性(N=8)');
xlabel('k');
ylabel('|X3|');
subplot(3,2,4);
stem(i,abs(X4),'.');
title('x4幅频特性(N=8)');
xlabel('k');
ylabel('|X4|');
subplot(3,2,5);
stem(i,abs(X5),'.');
title('x5幅频特性(N=8)');
xlabel('k');
ylabel('|X5|');
X1=fft(x1,N2);
X2=fft(x2,N2);
X3=fft(x3,N2);
X4=fft(x4,N2);
X5=fft(x5,N2);
figure; %频域图 N2=16
i=0:N2-1;
subplot(3,2,1);
stem(i,abs(X1),'.');
title('x1幅频特性(N=16)');
xlabel('k');
ylabel('|X1|');
subplot(3,2,2);
stem(i,abs(X2),'.');
title('x2幅频特性(N=16)');
xlabel('k');
ylabel('|X2|');
subplot(3,2,3);
stem(i,abs(X3),'.');
title('x3幅频特性(N=16)');
xlabel('k');
ylabel('|X3|');
subplot(3,2,4);
stem(i,abs(X4),'.');
title('x4幅频特性(N=16)');
xlabel('k');
ylabel('|X4|');
subplot(3,2,5);
stem(i,abs(X5),'.');
title('x5幅频特性(N=16)');
xlabel('k');
ylabel('|X5|');
t=n/fs; %采样
x7=s6(t);;
figure;
i=0:N2-1;
X6=fft(x7,N2);
subplot(2,2,1);
stem(i,abs(X6),'.');
title('x6幅频特性(N=16)');
xlabel('k');
ylabel('|X6|');
i=0:N3-1;
X6=fft(x7,N3);
subplot(2,2,2);
stem(i,abs(X6),'.');
title('x6幅频特性(N=32)');
xlabel('k');
ylabel('|X6|');
i=0:N4-1;
X6=fft(x7,N4);
subplot(2,2,3);
stem(i,abs(X6),'.');
title('x6幅频特性(N=64)');
xlabel('k');
ylabel('|X6|');
function x=s1(n,N)
x=[(n-0)>=0]-[n-0-N>=0];
function x=s2(n)
for i=0:length(n)-1
if i>=0&i<=3
x(i+1)=i+1;
else if i>=4&i<=7
x(i+1)=8-i;
else
x(i+1)=0;
end
end
end;
function x=s3(n)
for i=0:length(n)-1
if i>=0&i<=3
x(i+1)=4-i;
else if i>=4&i<=7
x(i+1)=i-3;
else
x(i+1)=0;
end
end
end;
function x=s4(n)
x=cos(pi/4*n);
function x=s5(n)
x=sin(pi/8*n);
function x=s6(t)
x=cos(8*pi*t)+cos(16*pi*t)+cos(20*pi*t);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -