clear all; clc; n = -50:50; x = zeros(1,101); %偏移量k k = input('请输入δ(n-k)的偏移量k:\n'); x(51) = 1; subplot(2,1,1); stem(n,x); title('δ(n)'); xlabel('n'); n1 = n+k; subplot(2,1,2); stem(n1,x); title(['δ(n-',num2str(k),')']); xlabel('n');
输入偏移量30输出结果:
2. 单位阶跃序列
1 2 3 4 5 6 7
clear all; clc; n = 0:100; x = ones(1,101); stem(n,x); title("u(n)"); xlabel('n');
输出结果:
3. 正弦序列
1 2 3 4 5 6 7 8 9 10 11 12
clear all; clc; n = 0:100; A = input('请输入振幅:\n'); f = input('请输入模拟频率:\n'); Fs = input('请输入抽样频率:\n'); fai = input('请输入初相:\n'); x = A*sin(2*pi*f*n/Fs+fai); m = 2*pi*f/Fs; stem(n,x); title(['x=',num2str(A),'sin(',num2str(m),'n','+',num2str(fai),')']); xlabel('n');
输入参数:
请输入振幅: 3 请输入模拟频率: 100 请输入抽样频率: 300 请输入初相: 0
输出波形:
4. 复正弦序列
1 2 3 4 5 6 7 8 9
clear all; clc; N = input('请输入要显示的长度:\n'); omega = input('请输入指数系数\n'); n = 0:N-1; x = exp(1i*omega*n); stem(n,x); title(['x=exp(j',num2str(omega),'n)']); xlabel('n');
输入参数:
请输入要显示的长度: 100 请输入指数系数 2
输出波形:
5. 指数序列
1 2 3 4 5 6 7 8 9
clear all; clc; N = input("请输入序列长度:"); n = 0:N-1; a = input("请输入指数的底数:"); x = a.^n; stem(n,x); title(['x = ',num2str(a),'^n']); xlabel("n");