Skip to content

Commit

Permalink
acycle1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mingsongli committed May 21, 2019
1 parent f52d579 commit 6ff4458
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 10 deletions.
Binary file modified code/guicode/evofftGUI.fig
Binary file not shown.
46 changes: 43 additions & 3 deletions code/guicode/evofftGUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

% Edit the above text to modify the response to help evofftGUI

% Last Modified by GUIDE v2.5 19-May-2019 16:13:23
% Last Modified by GUIDE v2.5 21-May-2019 11:37:51

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
Expand Down Expand Up @@ -75,11 +75,12 @@ function evofftGUI_OpeningFcn(hObject, eventdata, handles, varargin)
set(handles.checkbox3,'position',[0.293,0.35,0.36,0.1])
set(handles.checkbox5,'position',[0.293,0.25,0.36,0.1])
set(handles.checkbox4,'position',[0.293,0.15,0.36,0.1])
set(handles.checkbox6,'position',[0.293,0.05,0.36,0.1])
set(handles.checkbox6,'position',[0.293,0.05,0.2,0.1])
set(handles.checkbox7,'position',[0.029,0.35,0.25,0.08])
set(handles.checkbox7,'Value',0)
set(handles.checkbox8,'position',[0.029,0.45,0.25,0.08])
set(handles.checkbox8,'Value',1)
set(handles.popupmenu4,'position',[0.46,0.03,0.18,0.11])

set(handles.uipanel6,'position',[0.029,0.05,0.251,0.28])
set(handles.uipanel10,'position',[0.637,0.1,0.251,0.42])
Expand Down Expand Up @@ -135,6 +136,7 @@ function evofftGUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.method = 'Fast Fourier transform (LAH)';
handles.lenthx = xmax-xmin;
handles.time_0pad = 1;
handles.padtype = 1;
% if number of calculations is larger than 500;
% then, a large step is recommended. This way, the ncal is ~500.
ncal = (xmax-xmin - handles.window)/mean1;
Expand Down Expand Up @@ -649,7 +651,7 @@ function evofft_ok_pushbutton_Callback(hObject, eventdata, handles)

if handles.time_0pad == 1
% restore time/depth
data = zeropad2(data,window);
data = zeropad2(data,window,handles.padtype);
else
data(:,2) = data(:,2) - mean(data(:,2));
end
Expand Down Expand Up @@ -1240,3 +1242,41 @@ function checkbox8_Callback(hObject, eventdata, handles)
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox8


% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu4
contents = cellstr(get(hObject,'String'));
val = contents{get(hObject,'Value')};
if strcmp(val,'zero')
%disp('zero')
handles.padtype = 1;
elseif strcmp(val,'mirror')
%disp('mirror')
handles.padtype = 2;
elseif strcmp(val,'mean')
%disp('mean')
handles.padtype = 3;
elseif strcmp(val,'random')
%disp('random')
handles.padtype = 4;
end
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
51 changes: 44 additions & 7 deletions code/seriesanalysis/zeropad2.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
function [dataX] = zeropad2(data,win)
function [dataX] = zeropad2(data,win,padding)
% zero-padding data, to the beginning and the end of the data
% data: 2 column, equal spaced sampling data
% win: window size, must be larger than sampling rate of the data
% padding: padding type. (1=zero padding,
% 2=mirror padding, 3=mean padding, 4=random padding)
%
%
% partly based on evofft19.m
% 2019: update by Nicolas Thibault & Giovanni Rizzi on padding options
%
% Mingsong Li, April 2019
% Penn State

if nargin < 3; padding = 1; end
if nargin < 2; win = 0.35 * abs(data(end,1) - data(1,1)); end
% ensure data is sorted in the ascending order
data = sortrows(data);

Expand All @@ -18,14 +25,44 @@
dt = mean(diff(x));
% number of zero-padding data
n = round(win/2/dt);

% zero-padding first half window
X1x = linspace( (min(x)-win/2), min(x)-dt, n);
X1y = zeros(n,1);
X1 = [X1x',X1y];
%X1x = linspace( (min(x)-win/2), min(x)-dt, n);
X1x = (min(x)-dt) : -dt : (min(x)-win/2);
X1x = sort(X1x);

% zero-padding last half window
X2x = linspace( max(x)+dt, (max(x)+win/2), n);
X2 = [X2x',X1y];
%X2x = linspace( max(x)+dt, (max(x)+win/2), n);
X2x = (max(x)+dt) : dt : (max(x)+win/2);

if padding == 1
% zero padding
X1y = zeros(length(X1x),1);
X2y = zeros(length(X2x),1);
elseif padding == 2
% mirror padding
X1y = y(length(X1x):-1:1);
X2y = y(end: -1 : (end-length(X2x)+1));
%disp(size(X2x'))
%disp(size(X2y))
elseif padding == 3
% mean padding
y_start_mean = mean(y(1:n));
y_end_mean = mean(y(end-n:end));
X1y = zeros(length(X1x),1) + y_start_mean;
X2y = zeros(length(X2x),1) + y_end_mean;
elseif padding == 4
% random padding
y_start_mean = mean(y(1:n));
y_end_mean = mean(y(end-n:end));
X1y = randn(length(X1x),1) * std(y(1:n)) + y_start_mean;
X2y = randn(length(X2x),1) * std(y(end-n:end)) + y_end_mean;
else
error('Error: padding must be either 1, 2, 3, or 4')
end

X1 = [X1x',X1y];
X2 = [X2x',X2y];

% final result
dataX = [X1; data; X2];

0 comments on commit 6ff4458

Please sign in to comment.