⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex5_6.m

📁 离散控制系统设计的MATLAB 代码
💻 M
字号:
%%%%%%%%%%%%%%%%%% Example 5.6 %%%%%%%%%%%%%%%%%%
%   Discrete-Time Control Problems using        %
%       MATLAB and the Control System Toolbox   %
%   by J.H. Chow, D.K. Frederick, & N.W. Chbat  %
%         Brooks/Cole Publishing Company        %
%                September 2002                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 	----     spectrum of ZOH output    ----
%
clear
disp('Example 5.6')

fs = 10; Ts = 1/fs;             % sampling frequency and period
f = [0:1:29]';                  % frequency points from 0 to 29 Hz
Gh0 = (1-exp(-j*Ts*2*pi*f))./(j*2*pi*f);  % './' is entry-wise divide
disp('The warning is due to divide by zero at zero frequency, define DC gain separately')
disp('')
Gh0(1) = Ts;                    % define DC gain separately
% spectrum of ZOH output
dt = [0:Ts:0.9]';              % time points from 0 to 0.9 sec
e = sin(2*pi*dt);               % 1 Hz signal
N = 10;                         % number of data points   
fr = fft(e)/N/Ts;               % frequency spectrum
fr = small20(fr,1e-10);          % set small coeff to exact zeros
fr_paste = [fr; fr; fr];        % continue the spectrum to form 30 freq points
fr_e = fr_paste.*Gh0;           % '.*' is entry-wise multiply

figure
subplot(2,1,1), dplot(f,abs(fr_e)), grid              % magnitude plot
ylabel('Magnitude')
title('Spectrum of the Output of Zero-Order Hold for Example 5.6')
subplot(2,1,2), stem(f,angle(fr_e)*180/pi,':'), grid  % phase plot
ylabel('Phase (deg)')
xlabel('Frequency (Hz)')
disp('******>'), pause

% sinusoidal series approximation of ZOH output
tt = [0:0.001:1]';
ff = [1 9 11 19 21];           % first 5 nonzero frequency components
e5 = 0*tt;
for i = 1:5                    % sum over all 5 frequency components
  % 1 is added to ff(i) because the 1st entry of fr_e is DC
    e5=e5+2*abs(fr_e(ff(i)+1))*cos(2*pi*ff(i)*tt+angle(fr_e(ff(i)+1)));
end
figure
plot(tt,e5), hold on, stairs(dt,e,'--'), hold off, grid
xlabel('Time (s)')
ylabel('Amplitude')
title('ZOH output (dashed) and signal made up of lowest 5 non-zero freq components (solid)')
%%%%%%%%%%

⌨️ 快捷键说明

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