32 lines
921 B
Matlab
32 lines
921 B
Matlab
|
|
function [fig]=bodeSamples(simData)
|
|
%f=figure(); h=plot(simData.Time,simData.Data,'g');
|
|
%set(h(1),'color','b'); set(h(2),'color',[0 0.5 0]);
|
|
Ts=1/5000; % sampling period
|
|
t=0:Ts:simData.Time(end);
|
|
posI=interp1(simData.Time,simData.Data(:,1),t);
|
|
posO=interp1(simData.Time,simData.Data(:,2),t);
|
|
ftI=fft(posI);
|
|
ftO=fft(posO);
|
|
tf=ftO./ftI;
|
|
|
|
L=length(t);
|
|
k=(L-1)*Ts; % fmax =1/Ts at sample (L-1)/2 (index0-base)
|
|
N=[10 220]*k; % number of relevant indexes (index0-base)
|
|
frq=(N(1):N(2))/k;
|
|
N=N+1;%index0-base -> index1-base
|
|
tfn=tf(N(1):N(2));
|
|
|
|
%fig=figure(); h=plot(abs(ftI));
|
|
%fig=figure(); h=plot(abs(ftO));
|
|
%fig=figure(); h=plot(abs(ftI(N(1):N(2))));
|
|
fig=figure();
|
|
ax1=subplot(2,1,1);
|
|
ax2=subplot(2,1,2);
|
|
h=plot(ax1,frq,abs(tfn));
|
|
p=unwrap(phase(tfn))/(2*pi)*360;
|
|
h=plot(ax2,frq,p);
|
|
grid(ax1,'on');grid(ax2,'on');
|
|
set(ax1, 'XScale', 'log');
|
|
set(ax2, 'XScale', 'log');
|
|
end |