1、 掌握利用MATLAB计算系统幅频、相频响应的方法;
2、 掌握使用MATLAB进行傅里叶变换的方法;
3、 掌握使用MATLAB验证傅里叶变换的性质的方法。
>> clear all;
>> a = [1 3 2];
>> b = [1];
>> w = -2 * pi : 0.01 : 2 * pi;
>> [H, w] = freqs(b, a, w);
>> mag = abs(H);
>> pha = angle(H);
>> rea = real(H);
>> ima = imag(H);
>> figure
>> subplot(2, 1, 1);
>> plot(w, mag);
>> grid on;
>> xlabel('\omega/\omega_0');
>> ylabel('|H(jw)|');
>> title('幅频响应曲线');
>> axis([-2 * pi, 2 * pi, 0, 0.6]);
>> subplot(2, 1, 2);
>> plot(w, pha);
>> grid on;
>> xlabel('\omega/\omega_0');
>> ylabel('∠H(jw) (rad)');
>> title('相频响应曲线');
>> axis([-2 * pi, 2 * pi, 0, 0.6]);
>> axis([-2 * pi, 2 * pi, -3, 3]);
>> figure
>> subplot(2, 1, 1);
>> plot(w, rea);
>> axis([-2 * pi 2 * pi -0.1 0.6]);
>> grid on;
>> xlabel('\omega/\omega_0');
>> ylabel('Re{H(jw)}');
>> title('频率响应的实部');
>> subplot(2, 1, 2);
>> plot(w, ima);
>> xlabel('\omega/\omega_0');
>> ylabel('Im{H(jw)}');
>> axis([-2 * pi 2 * pi -0.4 0.4]);
>> grid on;
>> title('频率响应的虚部');
幅频响应、相频响应曲线:
频率响应的实部和虚部:
2、
MATLAB代码:
(1)X1(t) 信号
>> clear all;
>> syms x;
>> f = exp(-x) .* heaviside(x);
>> F = fourier(f);
>> Fs = abs(F);
>> Fe = angle(F);
>> figure
>> subplot(2, 1, 1);
>> ezplot(Fs, [-2 * pi, 2 * pi]);
>> title('符号计算X1(jw)的幅度谱', 'FontSize', 14);
>> grid on;
>> xlabel('\omega/\omega_0');
>> ylabel('|X1(jw)|');
>> subplot(2, 1, 2);
>> ezplot(Fe, [-2 * pi, 2 * pi]);
>> title('符号计算X1(jw)的相位谱', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('∠X1(jw) (rad)');
>> grid on;
>> clear all;
>> T = 0.01;
>> dw = 0.01;
>> t = -5 : T : 5;
>> w = -2 * pi : dw : 2 * pi;
>> f = exp(-t) .* (t >= 0);
>> F = f * exp(-j * t' * w) * T;
>> Fe = angle(F);
>> Fs = abs(F);
>> figure
>> subplot(2, 1, 1);
>> plot(w, Fs);
>> axis([-2 * pi 2 * pi 0.1 1.1]);
>> grid on;
>> title('数值计算X1(jw)的幅度谱', 'FontSize', 14);
>> ylabel('|X1(jw)|');
>> xlabel('\omega/\omega_0');
>> subplot(2, 1, 2);
>> plot(w, Fe);
>> axis([-2 * pi 2 * pi -1.5 1.5]);
>> title('数值计算X1(jw)的相位谱', 'FontSize', 14);
>> grid on;
>> ylabel('∠X1(jw) (rad)');
>> xlabel('\omega/\omega_0');
(2)X2(t) 信号
>> clear all;
>> syms x;
>> f = exp(-3 * abs(x)) .* sin(2 * x);
>> F = fourier(f);
>> figure
>> Fs = abs(F);
>> Fe = angle(F);
>> subplot(2, 1, 1);
>> ezplot(Fs);
>> grid on;
>> title('符号计算X2(jw)的幅度谱', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('|X2(jw)|');
>> subplot(2, 1, 2);
>> ezplot(Fe);
>> fplot(Fe);
>> axis([-2 * pi 2 * pi -1.6 1.6]);
>> axis([-2 * pi 2 * pi -2 2]);
>> grid on;
>> title('符号计算X2(jw)的相位谱', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('∠X2(jw) (rad)');
>> clear all;
>> T = 0.01;
>> dw = 0.01;
>> t = -10 : T : 10;
>> w = -2 * pi : dw : 2 * pi;
>> f = exp(-3 * abs(t)) .* sin(2 * t);
>> F = f * exp(-j * t' * w) * T;
>> figure
>> Fs = abs(F);
>> Fe = angle(F);
>> subplot(2, 1, 1);
>> plot(w, Fs);
>> grid on;
>> axis([-2 * pi 2 * pi -0.01 0.23]);
>> title('数值计算X2(jw)的幅度谱', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('|X2(jw)|');
>> subplot(2, 1, 2);
>> plot(w, Fe);
>> grid on;
>> axis([-2 * pi 2 * pi -2 2]);
>> title('数值计算X2(jw)的相位谱', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('∠X2(jw) (rad)');
(3)X3(t) 信号
>> clear all;
>> syms x;
>> f = heaviside(x + 0.5) - heaviside(x - 0.5);
>> F = fourier(f);
>> Fs = abs(F);
>> Fe = angle(F);
>> figure
>> subplot(2, 1, 1);
>> ezplot(Fs, [-5 * pi, 5 * pi]);
>> grid on;
>> title('符号计算X3(jw)的幅度谱', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('|X3(jw)|');
>> subplot(2, 1, 2);
>> ezplot(Fe, [-5 * pi, 5 * pi]);
>> grid on;
>> title('符号计算X3(jw)的相位谱', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('∠X3(jw) (rad)');
>> clear all;
>> T = 0.01;
>> dw = 0.01;
>> t = -5 : T : 5;
>> w = -5 * pi : dw : 5 * pi;
>> f = Heaviside(t + 0.5) - Heaviside(t - 0.5);
>> F = f * exp(-j * t' * w) * T;
>> Fs = abs(F);
>> Fe = angle(F);
>> figure;
>> subplot(2, 1, 1);
>> plot(w, Fs);
>> axis([-5 * pi 5 * pi -0.1 1.1]);
>> grid on;
>> title('数值计算X3(jw)幅度谱', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('|X3(jw)|');
>> subplot(2, 1, 2);
>> plot(w, Fe);
>> plot(w, abs(Fe));
>> axis([-5 * pi 5 * pi -0.2 3.3]);
>> grid on;
>> xlabel('\omega/omega_0');
>> xlabel('\omega/\omega_0');
>> ylabel('∠X3(jw) (rad)');
>> title('数值计算X3(jw)相位谱', 'FontSize', 14);
生成的谱图:
(1)X1(t) 信号
符号计算方法:
数值计算方法:
符号计算方法:
数值计算方法:
符号计算方法:
3、
(1)、验证线性性质
MATLAB代码:
>> clear all;
>> syms t;
>> x1 = exp(-t) .* heaviside(t);
>> x2 = exp(-3 * abs(t)) .* sin(2 * t);
>> x = 2 * x1 + 5 * x2;
>> X = fourier(x);
>> figure
>> subplot(2, 1, 1);
>> aX = abs(X);
>> pX = angle(X);
>> ezplot(aX);
>> grid on;
>> title('直接计算傅里叶变换的实部', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('|X(jw)|');
>> subplot(2, 1, 2);
>> ezplot(pX);
>> grid on;
>> title('直接计算傅里叶变换的虚部', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('∠X(jw) (rad)');
>> X1 = fourier(x1);
>> X2 = fourier(x2);
>> Y = 2 * X1 + 5 * X2;
>> aY = abs(Y);
>> pY = angle(Y);
>> figure
>> subplot(2, 1, 1);
>> ezplot(aY);
>> grid on;
>> title('使用性质计算傅里叶变换的实部', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('|X(jw)|');
>> subplot(2, 1, 2);
>> ezplot(pY);
>> grid on;
>> title('使用性质计算傅里叶变换的虚部', 'FontSize', 14);
>> xlabel('\omega/\omega_0');
>> ylabel('∠X(jw) (rad)');
直接计算:
使用性质计算:
(2)验证卷积性质:
// 待更新。
4、
MATLAB代码:
signal_DTFT函数:
function X = signal_DTFT(xn, n, w)
X = xn * (exp(-1i) .^ (n' * w));
其余代码:
>> clear all;
>> w = -4 * pi : 0.01 : 4 * pi;
>> n = -30 : 30;
>> xn = 0.5 .^ (n - 1) .* (n >= 1);
>> X = signal_DTFT(xn, n, w);
>> magX = abs(X);
>> figure
>> subplot(2, 1, 1);
>> plot(w, magX);
>> grid on;
>> xlabel('\omega/\omega_0');
>> ylabel('|X(e^{jw})|');
>> title('傅里叶变换的模值', 'FontSize', 14);
>> axis([-4 * pi, 4 * pi, 0.5, 2]);
>> subplot(2, 1, 2);
>> plot(w, phaX);
>> axis([-4 * pi, 4 * pi, -4, 4]);
>> grid on;
>> xlabel('\omega/\omega_0');
>> ylabel('∠X(e^{jw}) (rad)');
>> title('傅里叶变换的相位', 'FontSize', 14);
傅里叶变换结果:
答: 数值计算和符号计算的精度不同。符号计算的精度取决于MATLAB中 ezplot 函数的精度,而数值计算的精度取决于自己定义的 w 变量的精度。
1、 单位阶跃函数 u(t) 可以用 heaviside(t) 函数近似表示。在 t = 0 时刻的函数值为 0.5. 举例:
>> clear all;
>> syms x;
>> u = heaviside(x);
>> ezplot(u, [-5, 5]);
>> xlabel('t');
>> ylabel('u(t)');
>> title('单位阶跃函数', 'FontSize', 14);
>> heaviside(0)
ans =
0.5000
函数图像: