comp_exam2_1.m

来自「the source code of Ziemer s book Digital」· M 代码 · 共 20 行

M
20
字号
%  Plot of line spectra for half-rectified sinewave
%
clf
A = 1;
n_max = 11;                                 % Maximum harmonic plotted; odd
n = -n_max:1:n_max;
X = A./(pi*(1+eps - n.^2));                 % Offset 1 slightly to avoid divide by 0
for m = 1:2:2*n_max+1
   X(m) = 0;                                % Set odd harmonic lines to 0
end
X(n_max+2) = -j*A/4;                        % Compute lines for n = 1 & n = -1
X(n_max) = j*A/4;
[arg_X, mag_X] = cart2pol(real(X),imag(X)); % Convert to magnitude and phase
for m = n_max+3:2:2*n_max+1
   arg_X(m) = arg_X(m) - 2*pi;              % Force phase to be odd
end
subplot(2,1,1),stem(n, mag_X),ylabel('|X_n|')
title('Plot of amplitude and phase spectra for half-rectified sinewave')
subplot(2,1,2),stem(n, arg_X),xlabel('nf_0'),ylabel('angle(X_n)')

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?