Report DMD CurveFit
Report DMD CurveFit
csv File
clc;
clear;
close all;
if ~exist(saveFolder, 'dir')
mkdir(saveFolder);
end
Ns = 8;
An = 1.5;
% signal: sum of sines
x(1,:) = An*sin(2*pi*(fn)*t);
x(2,:) = (An/4)*sin(2*pi*(2*fn)*t);
x(3,:) = (An/8)*sin(2*pi*(3*fn)*t);
x(4,:) = (An/16)*sin(2*pi*(4*fn)*t);
x(5,:) = (An/32)*sin(2*pi*(5*fn)*t);
x(6,:) = (An/64)*sin(2*pi*(6*fn)*t);
x(7,:) = (An/128)*sin(2*pi*(7*fn)*t);
x(8,:) = (An/256)*sin(2*pi*(8*fn)*t);
xclean =
x(1,:)+x(2,:)+x(3,:)+x(4,:)+x(5,:)+x(6,:)+x(7,:)+x(8,:);
figure(1)
% Create axes
axes1 = axes('YGrid','on','XGrid','on','FontSize',20,...
'PlotBoxAspectRatio',[0.24 0.23 0.23]);
% % Uncomment the following line to preserve the Y-limits of
the axes
%ylim(axes1,[-1.1 1.1]);
box(axes1,'on');
hold(axes1,'on');
% Create plot
plot(t,xclean,'LineWidth',1.5,'Color','k')
% Create ylabel
ylabel('$x$','Interpreter','latex');
% Create xlabel
xlabel('$t$','Interpreter','latex');
Step2: Open the file, do DMD, match the results generated in the previous
code with the DMD generated results
if ~exist(saveFolder, 'dir')
mkdir(saveFolder);
end
Lt = 500;
X1 = X(:,1:Lt-1);
X2 = X(:,2:Lt);
dt = t(5)-t(4);
r = 16;
[Phi,omega,lambda,b,Xdmd] = DMD(X1,X2,r,dt);
% DMD Reconstruction
time_dynamics = zeros(r,length(t));
for iter = 1:length(t)
time_dynamics(:,iter) = (b.*exp(omega*t(iter)));
end
X_dmd = Phi*time_dynamics;
X_dmdb = zeros(1,size(time_dynamics,2));
X_dmda = zeros(size(Phi,2),size(time_dynamics,2));
for i = 1:size(Phi,2)
X_dmda(i,:) = Phi(1,i)*time_dynamics(i,:);
X_dmdb(1,:) = X_dmdb+X_dmda(i,:);
end
figure(1)
plot(t,x,'k','LineStyle','-','LineWidth',1.5)
hold on
plot(t,real(X_dmd(1,:)),'b','LineStyle','--','LineWidth',1.5)
hold on
plot(t,real(X_dmdb(1,:)),'r','LineStyle','-.','LineWidth',1.5)
pause(0.5);
% i
% i1 = i+n
% i2 = i+n+1
n = n+1;
end
Step3: Curve Fit the Signal Generated in Step 1 (Use cftool)
i. Run the following code:
Table 4 Matlab Code: open_csv
ii. Type ‘cftool’ in Matlab command window. The following Window will
appear:
iii. Give a file name. Choose ‘t’ as ‘X data’ and ‘x’ as ‘Y data’ from the dropdown
menu.
iv. Choose ‘Custom Equation’. Generate a function y = f(x) according to your
signal that you have generated. My function:
a1*sin(w1*x)+a2*sin(2*w1*x)+a3*sin(3*w1*x)+a4*sin(4*w1*x)+a5*sin(5*w1*
x)+a6*sin(6*w1*x)+a7*sin(7*w1*x)+a8*sin(8*w1*x)
I entered this function in the box provided:
v. Click on ‘Fit Options’. You have to give lower and upper bound to some
parameters (Mostly the fundamental frequency). I know my fundamental
frequency is 62.83. So I provide the lower and upper bound of w_1 as 62 and
63, respectively:
General model:
f(x) = a1*sin(w1*x)+a2*sin(2*w1*x)+a3*sin(3*w1*x)+a4*sin(4*w1*x)+a5*sin(5*w1*x)
+a6*sin(6*w1*x)+a7*sin(7*w1*x)+a8*sin(8*w1*x)
Coefficients (with 95% confidence bounds):
a1 = 1.5 (1.5, 1.5)
a2 = 0.375 (0.375, 0.375)
a3 = 0.1875 (0.1875, 0.1875)
a4 = 0.09375 (0.09375, 0.09375)
a5 = 0.04688 (0.04688, 0.04688)
a6 = 0.02344 (0.02344, 0.02344)
a7 = 0.01172 (0.01172, 0.01172)
a8 = 0.005859 (0.005859, 0.005859)
w1 = 62.83 (62.83, 62.83)
Goodness of fit:
SSE: 1.4060e-24
R-square: 1
Adjusted R-square: 1
RMSE: 2.6568e-14
vii. Copy the coefficients in a matlab script file:
for i = 1:8
% Generate curve-fit (CFT) sine waves
x_CFT = a(i) * sin(i * w1 * t);
% Create figure
figure;
hold on;
grid on;
hold off;
viii. Compare the 8-modes obtained from curve fitting with the 8-modes
obtained from DMD.