Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

classdef analysis < matlab.apps.

AppBase

% Properties that correspond to app components


properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
AnalysisTab matlab.ui.container.Tab
dothi matlab.ui.control.UIAxes
giatriTable matlab.ui.control.Table
giatriTable2 matlab.ui.control.Table
ThemButton matlab.ui.control.Button
FileEditFieldLabel matlab.ui.control.Label
FileEditField matlab.ui.control.EditField
PhanTichButton matlab.ui.control.Button
OptionTab matlab.ui.container.Tab
UIAxes matlab.ui.control.UIAxes
UIAxes2 matlab.ui.control.UIAxes
OptionDropDownLabel matlab.ui.control.Label
OptionDropDown matlab.ui.control.DropDown
HelpTab matlab.ui.container.Tab
end

properties (Access = public)


dat
fs
N
fk
t
x
df
X
A
phase
Power
y
env

end

methods (Access = private)


function phantich = func(app)

% fs = app.TanSoLayMauEditField.Value;

app.dat= load(app.FileEditField.Value);
app.fs= 1/app.dat(2,2);
app.N= app.dat(end,1);
app.t= app.dat(1:app.N,2);
app.x= app.dat(1:app.N,3)';
L=app.N+1;

%Frequency Domain
app.df=app.fs /(app.N-1);
app.fk=0:app.df:app.fs;

app.X=fft(app.x);
app.A=2*abs(app.X)/app.N;

app.phase= angle(app.X);
app.Power = app.A.^2/2;

app.y = hilbert(app.x);
app.env = abs(app.y);

k=readtable(app.FileEditField.Value);
app.giatriTable2.Data = k;
xx=table2array(k(1:app.N,2));
yy=table2array(k(1:app.N,3));
plot(app.dothi,xx,yy);

% %Speciality Values
%
% % Means Value
% means= (1/N)*sum(x);
%
% % RMS Value
% RMS = sqrt((1/N)*sum(x.^2));
%
% % Max Value
% xmax= max(x,[],1:N);
%
% %Min Value
% xmin = min(x,[],1:N);
%
% % Peak to Peak Value
% xpeak = xmax - xmin;
%
% %Crest Factor
% Cr=(xpeak)/RMS;
%
% name={'Means'; 'RMS'; 'Max' ; 'Min'; 'Peak'; 'Crest'};
% value={means; RMS; xmax; xmin; xpeak;Cr};
% bb= table(name,value);
% BB= readtable(bb);
% app.UITable2_2.Data= BB;
%

plot(app.t,app.x)
xlim([0 0.74])
plot_param = {'Color', [0.6 0.1 0.2],'Linewidth',0.5};
hold on
plot(app.t,[-1;1]*app.env,plot_param{:})
hold off
xlim([0 0.74])
title('Hilbert Envelope')
xlabel ('Time (s)');
ylabel ('acceleration (m/s^2)');

% figure(),clf
% subplot(3,1,1);
% plot(fk,A);
% xlabel ('Frequency (Hz)');
% xlim ([0 fs/2]);
% title('Amplitude Spectrum');
% subplot(3,1,2);
% plot(fk,phase);
% xlabel ('Frequency (Hz)');
% xlim ([0 fs/2]);
% title('Phase Spectrum ');
% subplot(3,1,3);
% plot(fk,Power);
% xlabel ('Frequency (Hz)');
% xlim ([0 fs/2]);
% title('Power Spectrum');
% if app.OptionDropDown.Value == ('Bien Do12');
%
% plot(app.UIAxes,fk,A);
% xlim(app.UIAxes,[0 fs/2]);
% end
%
% if app.OptionDropDown.Value == ('Pha123456');
% plot(app.UIAxes,fk,phase);
% end
%
% if app.OptionDropDown.Value == ('Cong Suat');
%
% plot(app.UIAxes,fk,Power);
%
% xlim (app.UIAxes,[0 fs/2]);
%
% end
% if app.OptionDropDown.Value == ('Phổ pha');
%
% plot(app.UIAxes,fk,phase);
%
% xlim (app.UIAxes,[0 fs/2]);
%
% end
% if app.OptionDropDown.Value == ('Phổ công suất');
%
% plot(app.UIAxes,fk,Power);
%
% xlim (app.UIAxes,[0 fs/2]);
%
% end

% %Low-High-Band Pass Filter


% %LowPassFilter
% xlow = lowpass(x,flow,fs);
% %HighPassFilter
% xhigh = highpass(x,fhigh,fs);
% %BandPassFiler
% xband = bandpass(x,fband,fs);
%
% figure()
%
% subplot(3,1,1);
% plot(fk, xlow);
%
% title('Low Pass Filter');
% xlabel('Time (s)');
% ylabel ('Frequence (Hz)');
%
% subplot(3,1,2);
% plot(t, xhigh);
%
% title('High Pass Filter');
% xlabel('Time (s)');
% ylabel ('Frequence (Hz)');
%
% subplot(3,1,3);
% plot(fk, xband);
%
% title('Band Pass Filter');
% xlabel('Time (s)');
% ylabel ('Frequence (Hz)');

% if app.LThapCheckBox.Value ==1
% figure(),clf;
% xlow = lowpass(x,flow,fs);
% plot(t,xlow)
% title('Low Pass Filter');
% xlabel('Time (s)');
% ylabel ('Frequence (Hz)');
%
% end
% if app.LCaoCheckBox.Value ==1
% figure(),clf;
% xhigh = highpass(x,fhigh,fs);
% plot(t,xhigh)
% title('High Pass Filter');
% xlabel('Time (s)');
% ylabel ('Frequence (Hz)');
% end
% if app.LDaiCheckBox.Value ==1
% figure(),clf;
% xband = bandpass(x,fband,fs);
% plot(t,xband)
% title('Band Pass Filter');
% xlabel('Time (s)');
% ylabel ('Frequence (Hz)');
% end
%
% %Window Function In Fourier Analysis
% %Hamming
% if app.HammingCheckBox.Value ==1
% figure(),clf;
% ham = wvtool(hamming(L));
% end
% %Gaussian
% if app.GaussianCheckBox.Value ==1
% figure(),clf;
% gau = wvtool(gausswin(L));
% end
% %Hanning
% if app.HanningCheckBox.Value ==1
% figure(),clf;
% han = wvtool(hann(L));
% end
% %Blackman
% if app.BlackmanCheckBox.Value ==1
% figure(),clf;
% bla = wvtool(blackman(L));
% end
%
%

end
end

% Callbacks that handle component events


methods (Access = private)

% Value changed function: FileEditField


function FileEditFieldValueChanged(app, event)
value = app.FileEditField.Value;

end

% Button pushed function: ThemButton


function ThemButtonPushed(app, event)
[filename, path] = uigetfile('*.txt') ;
app.FileEditField.Value = filename;
figure(app.UIFigure);
end

% Button pushed function: PhanTichButton


function PhanTichButtonPushed(app, event)
app.func();
end
% Value changed function: OptionDropDown
function OptionDropDownValueChanged(app, event)

value = app.OptionDropDown.Value;

if app.OptionDropDown.Value == ('Bien Do12');

plot(app.UIAxes,app.fk,app.A)
xlim(app.UIAxes,[0 app.fs/2]);
end

if app.OptionDropDown.Value == ('Pha123456');

plot(app.UIAxes,app.fk,app.phase);
end

if app.OptionDropDown.Value == ('Cong Suat');

plot(app.UIAxes,app.fk,app.Power);

xlim (app.UIAxes,[0 app.fs/2]);

end
end
end

% Component initialization
methods (Access = private)

% Create UIFigure and components


function createComponents(app)

% Create UIFigure and hide until all components are created


app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 873 511];
app.UIFigure.Name = 'UI Figure';

% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [1 0 873 512];

% Create AnalysisTab
app.AnalysisTab = uitab(app.TabGroup);
app.AnalysisTab.Title = 'Analysis';

% Create dothi
app.dothi = uiaxes(app.AnalysisTab);
title(app.dothi, '')
xlabel(app.dothi, 'Time(s)')
ylabel(app.dothi, 'Acceleration(m/s^2)')
app.dothi.PlotBoxAspectRatio = [2.05940594059406 1 1];
app.dothi.XGrid = 'on';
app.dothi.YGrid = 'on';
app.dothi.Position = [286 212 549 273];

% Create giatriTable
app.giatriTable = uitable(app.AnalysisTab);
app.giatriTable.ColumnName = {'STT'; 'Name'; 'Value'};
app.giatriTable.ColumnWidth = {40, 'auto', 'auto'};
app.giatriTable.RowName = {};
app.giatriTable.Position = [286 23 264 158];

% Create giatriTable2
app.giatriTable2 = uitable(app.AnalysisTab);
app.giatriTable2.ColumnName = {'STT'; 'Time'; 'Value'};
app.giatriTable2.ColumnWidth = {40, 'auto', 'auto'};
app.giatriTable2.RowName = {};
app.giatriTable2.Position = [559 23 278 158];

% Create ThemButton
app.ThemButton = uibutton(app.AnalysisTab, 'push');
app.ThemButton.ButtonPushedFcn = createCallbackFcn(app,
@ThemButtonPushed, true);
app.ThemButton.Position = [171 444 100 22];
app.ThemButton.Text = 'Thêm';

% Create FileEditFieldLabel
app.FileEditFieldLabel = uilabel(app.AnalysisTab);
app.FileEditFieldLabel.HorizontalAlignment = 'right';
app.FileEditFieldLabel.Position = [18 444 25 22];
app.FileEditFieldLabel.Text = 'File';

% Create FileEditField
app.FileEditField = uieditfield(app.AnalysisTab, 'text');
app.FileEditField.ValueChangedFcn = createCallbackFcn(app,
@FileEditFieldValueChanged, true);
app.FileEditField.Position = [58 444 100 22];

% Create PhanTichButton
app.PhanTichButton = uibutton(app.AnalysisTab, 'push');
app.PhanTichButton.ButtonPushedFcn = createCallbackFcn(app,
@PhanTichButtonPushed, true);
app.PhanTichButton.Position = [86 200 100 22];
app.PhanTichButton.Text = 'Phân Tích';

% Create OptionTab
app.OptionTab = uitab(app.TabGroup);
app.OptionTab.Title = 'Option';

% Create UIAxes
app.UIAxes = uiaxes(app.OptionTab);
title(app.UIAxes, 'Spectrum')
xlabel(app.UIAxes, 'Frequency(Hz)')
ylabel(app.UIAxes, '')
app.UIAxes.XGrid = 'on';
app.UIAxes.YGrid = 'on';
app.UIAxes.Position = [444 128 428 313];

% Create UIAxes2
app.UIAxes2 = uiaxes(app.OptionTab);
title(app.UIAxes2, 'Filter')
xlabel(app.UIAxes2, 'Time(s)')
ylabel(app.UIAxes2, 'Acceleration(m/s^2)')
app.UIAxes2.XGrid = 'on';
app.UIAxes2.YGrid = 'on';
app.UIAxes2.Position = [1 128 411 313];

% Create OptionDropDownLabel
app.OptionDropDownLabel = uilabel(app.OptionTab);
app.OptionDropDownLabel.HorizontalAlignment = 'right';
app.OptionDropDownLabel.FontWeight = 'bold';
app.OptionDropDownLabel.Position = [444 456 44 22];
app.OptionDropDownLabel.Text = 'Option';

% Create OptionDropDown
app.OptionDropDown = uidropdown(app.OptionTab);
app.OptionDropDown.Items = {'Bien Do12', 'Pha123456', 'Cong Suat'};
app.OptionDropDown.ValueChangedFcn = createCallbackFcn(app,
@OptionDropDownValueChanged, true);
app.OptionDropDown.FontWeight = 'bold';
app.OptionDropDown.Position = [503 456 100 22];
app.OptionDropDown.Value = 'Bien Do12';

% Create HelpTab
app.HelpTab = uitab(app.TabGroup);
app.HelpTab.Title = 'Help';

% Show the figure after all components are created


app.UIFigure.Visible = 'on';
end
end

% App creation and deletion


methods (Access = public)

% Construct app
function app = analysis

% Create UIFigure and components


createComponents(app)

% Register the app with App Designer


registerApp(app, app.UIFigure)

if nargout == 0
clear app
end
end

% Code that executes before app deletion


function delete(app)

% Delete UIFigure when app is deleted


delete(app.UIFigure)
end
end
end

You might also like