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

📄 cp5_2.m

📁 离散控制系统设计的MATLAB 代码
💻 M
字号:
%%%%%%%%%%% Comprehensive Problem 5.2 %%%%%%%%%%%
%   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                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   ---- frequency response of first-order hold ----
%
clear
disp('Comprehensive Problem 5.2')
disp('Frequency response computation of a first-order hold.')
disp('Also shows the Gibb Phenomenon.')

fs = 10;                        % sampling at 10 Hz
Ts = 1/fs;                      % sampling period
f = [1:1:29]';                  % frequency points from 0 to 30 Hz
Gh1 = (1 + j*2*pi*f*Ts)/Ts .* ...
    ((1-exp(-j*Ts*2*pi*f))./(j*2*pi*f)).^2;  % './' is entry-wise divide
Gh1 = [Ts; Gh1];                % define DC gain separately
f = [0; f];

disp(' ')
disp('Plot frequency response of first-order hold')
figure
subplot(2,1,1) 
plot(f,abs(Gh1))                % magnitude plot
ylabel('Magnitude')
grid
title('Frequency response of the First-Order Hold')
subplot(2,1,2), 
plot(f,angle(Gh1)*180/pi)       % phase plot
ylabel('Phase (deg)')
xlabel('Frequency (Hz)')
grid
%%%%%%%%%%%%%%
disp('*******>'), pause
disp('Plot frequency response of a 1-Hz sine signal')

t = [0:Ts:0.9]';                % time points from 0 to 0.9 sec
e = sin(2*pi*t);                % 1 Hz signal
N = 10;
fr = fft(e)/N/Ts;               % frequency spectrum
for i = 1:10
  if abs(fr(i)) < 1e-10
    fr(i) = 0;
  end
end
fr_paste = [fr; fr; fr];        % continue the spectrum
fr_e = fr_paste.*Gh1;           % '.*' is entry-wise multiply

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

disp('Plot the output of a first-order hold using the lowest 5')
disp('nonzero frequency components, and compare to the actual output.')

tt = [0:0.001:1]';
ff = [1 9 11 19 21];            % first 5 nonzero frequency components
e5 = 0*tt;
for i = 1:5
  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)
xlabel('Time (s)')
ylabel('Amplitude')
title('FOH output and signal made up of lowest 5 non-zero freq components')
hold on 
disp('Press space bar 10 times to complete plotting of FOH output')
foh(e,1,Ts) 
title('FOH output and signal made up of lowest 5 non-zero freq components')
hold off
axis([0 1 -1.5 1.5])
disp('End of Comprehensive Problem CP5.2')
%%%%%%%%%%

⌨️ 快捷键说明

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