Tuesday, August 22, 2017

ANALISA PETA WAKTU-FREKUENSI MENGGUNAKAN DEKOMPOSISI WAVELET





















KODE SUMBER GUI MATLAB:

function varargout = analisa_harmonik_final_WAVELET_COLORMAP(varargin)
% ANALISA_HARMONIK_FINAL_WAVELET_COLORMAP M-file for analisa_harmonik_final_WAVELET_COLORMAP.fig
%      ANALISA_HARMONIK_FINAL_WAVELET_COLORMAP, by itself, creates a new ANALISA_HARMONIK_FINAL_WAVELET_COLORMAP or raises the existing
%      singleton*.
%
%      H = ANALISA_HARMONIK_FINAL_WAVELET_COLORMAP returns the handle to a new ANALISA_HARMONIK_FINAL_WAVELET_COLORMAP or the handle to
%      the existing singleton*.
%
%      ANALISA_HARMONIK_FINAL_WAVELET_COLORMAP('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ANALISA_HARMONIK_FINAL_WAVELET_COLORMAP.M with the given input arguments.
%
%      ANALISA_HARMONIK_FINAL_WAVELET_COLORMAP('Property','Value',...) creates a new ANALISA_HARMONIK_FINAL_WAVELET_COLORMAP or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before analisa_harmonik_final_WAVELET_COLORMAP_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to analisa_harmonik_final_WAVELET_COLORMAP_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

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

% Last Modified by GUIDE v2.5 14-Aug-2017 13:58:12

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @analisa_harmonik_final_WAVELET_COLORMAP_OpeningFcn, ...
                   'gui_OutputFcn',  @analisa_harmonik_final_WAVELET_COLORMAP_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before analisa_harmonik_final_WAVELET_COLORMAP is made visible.
function analisa_harmonik_final_WAVELET_COLORMAP_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to analisa_harmonik_final_WAVELET_COLORMAP (see VARARGIN)

% Choose default command line output for analisa_harmonik_final_WAVELET_COLORMAP
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes analisa_harmonik_final_WAVELET_COLORMAP wait for user response (see UIRESUME)
% uiwait(handles.figure1);



% --- Outputs from this function are returned to the command line.
function varargout = analisa_harmonik_final_WAVELET_COLORMAP_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in tombol_dekomposisi.
function tombol_dekomposisi_Callback(hObject, eventdata, handles)
% hObject    handle to tombol_dekomposisi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Membaca parameter global
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));

n = banyakCuplik;
Fs=1000;

s=sin(50.*linspace(0,pi,n))+ 0.1*sin(100.*linspace(0,pi,n))+ 0.1*sin(150.*linspace(0,pi,n))+...
    0.1*sin(200.*linspace(0,pi,n))+ 0.1*sin(250.*linspace(0,pi,n))+ 0.5.*rand(1,n);



%axes(handles.sinyal);
subplot(3,5,1);plot(0:1/n:1-1/n,s);title('sinyal semula');
ylabel('amplitudo');xlabel('cuplik');

%dekomposisi wavelet level 1 dari sinyal semula
[A1,D1]=dwt(s,'db4');
subplot(3,5,2);plot(A1);
axis([1,length(A1), min(A1), max(A1)]);
title('koefisien aproksimasi lvl 1 A1');
ylabel('amplitudo');xlabel('cuplik');

subplot(3,5,3);plot(D1);
axis([1,length(D1), min(D1), max(D1)]);
title('koefisien detail lvl 1 D1');
ylabel('amplitudo');xlabel('cuplik');

%dekomposisi wavelet level 2 dari level 1 yaitu cA1 (koef.aproksimasi)
[AA2,DA2]=dwt(A1,'db4');
subplot(3,5,4);plot(AA2);
axis([1,length(AA2), min(AA2), max(AA2)]);
title('koefisien aproksimasi lvl 2 AA2');
ylabel('amplitudo');xlabel('cuplik');

subplot(3,5,5);plot(DA2);
axis([1,length(DA2), min(DA2), max(DA2)]);
title('koefisien detail lvl 2 DA2');
ylabel('amplitudo');xlabel('cuplik');

%dekomposisi wavelet level 2 dari level 1 yaitu D1 (koef.detil)
[AD2,DD2]=dwt(D1,'db4');
subplot(3,5,6);plot(AD2);
axis([1,length(AD2), min(AD2), max(AD2)]);
title('koefisien aproksimasi lvl 2 AD2');
ylabel('amplitudo');xlabel('cuplik');

subplot(3,5,7);plot(DD2);
axis([1,length(DD2), min(DD2), max(DD2)]);
title('koefisien detail lvl 2 DD2');
ylabel('amplitudo');xlabel('cuplik');

%dekomposisi wavelet level 3 dari level 2 yaitu AA2 (koef.aproksimasi)
[AAA3,DAA3]=dwt(AA2,'db4');
subplot(3,5,8);plot(AAA3);
axis([1,length(AAA3), min(AAA3), max(AAA3)]);
title('koefisien aproksimasi level 3 AAA3');
ylabel('amplitudo');xlabel('cuplik');

subplot(3,5,9);plot(DAA3);
axis([1,length(DAA3), min(DAA3), max(DAA3)]);
title('koefisien detail level 3 DAA3');
ylabel('amplitudo');xlabel('cuplik');

%dekomposisi wavelet level 3 dari level 2 yaitu DA2 (koef.aproksimasi)
[ADA3,DDA3]=dwt(DA2,'db4');
subplot(3,5,10);plot(ADA3);
axis([1,length(ADA3), min(ADA3), max(ADA3)]);
title('koefisien aproksimasi level 3 ADA3');
ylabel('amplitudo');xlabel('cuplik');

subplot(3,5,11);plot(DDA3);
axis([1,length(DDA3), min(DDA3), max(DDA3)]);
title('koefisien detail level 3 DDA3');
ylabel('amplitudo');xlabel('cuplik');

%dekomposisi wavelet level 3 dari level 2 yaitu AD2 (koef.detil)
[AAD3,DAD3]=dwt(AD2,'db4');
subplot(3,5,12);plot(AAD3);
axis([1,length(AAD3), min(AAD3), max(AAD3)]);
title('koefisien aproksimasi level 3 AAD3');
ylabel('amplitudo');xlabel('cuplik');

subplot(3,5,13);plot(DAD3);
axis([1,length(DAD3), min(DAD3), max(DAD3)]);
title('koefisien detail level 3 DAD3');
ylabel('amplitudo');xlabel('cuplik');

%dekomposisi wavelet level 3 dari level 2 yaitu DD2 (koef.detil)
[ADD3,DDD3]=dwt(DD2,'db4');
subplot(3,5,14);plot(ADD3);
axis([1,length(ADD3), min(ADD3), max(ADD3)]);
title('koefisien aproksimasi level 3 ADD3');
ylabel('amplitudo');xlabel('cuplik');

subplot(3,5,15);plot(DDD3);
axis([1,length(DDD3), min(DDD3), max(DDD3)]);
title('koefisien detail level 3 DDD3');
ylabel('amplitudo');xlabel('cuplik');


set(handles.teks_jumlah_data,'String',num2str(n));

%membuka figure baru
s1= sin(2*50.*linspace(0,pi,n));
figure, plot(0:1/n:1-1/n,s1);
title('sinyal semula');
ylabel('amplitudo');xlabel('Detik');
set(gca, 'YLIM',[-2 2]);



% --- Executes on button press in tombol_komposisi.
function tombol_komposisi_Callback(hObject, eventdata, handles)
% hObject    handle to tombol_komposisi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

cla(handles.sumbu2,'reset');
cla(handles.sumbu3,'reset');
% Membaca parameter global
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
levelD = str2num(get(handles.editLevelD,'String'));

frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
subTransien = str2num(get(handles.editTransien,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
posisiSubtransien = str2num(get(handles.editposisiSubtransien,'String'));

level_kontinyu=levelMaks;
thr=ambangBatas;
n=banyakCuplik;

%Posisi subtransien dikonversi menjadi cuplik
posisiSubtransien = round((Fs2) * posisiSubtransien);

%Simpan n dan Fs2 dan levelD
save n.mat n;
save Fs2.mat Fs2;
save levelD.mat levelD;

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
frek100 = str2num(get(handles.edit100,'String'));
frek150 = str2num(get(handles.edit150,'String'));
frek200 = str2num(get(handles.edit200,'String'));
frek250 = str2num(get(handles.edit250,'String'));

amp100 = str2num(get(handles.edit101,'String'));
amp150 = str2num(get(handles.edit151,'String'));
amp200 = str2num(get(handles.edit201,'String'));
amp250 = str2num(get(handles.edit251,'String'));

% Membaca frekuensi-frekuensi inter-harmonisa dan amplitudo
frek25 = str2num(get(handles.edit25,'String'));
frek75 = str2num(get(handles.edit75,'String'));
frek125 = str2num(get(handles.edit125,'String'));
frek175 = str2num(get(handles.edit175,'String'));

amp25 = str2num(get(handles.edit2511,'String'));
amp75 = str2num(get(handles.edit751,'String'));
amp125 = str2num(get(handles.edit1251,'String'));
amp175 = str2num(get(handles.edit1751,'String'));


%Membaca DC-Offset dan posisi DC-Offset
posisiDCoffset = str2num(get(handles.editposisiDCoffset,'String'));
dcOffset = str2num(get(handles.editOffset,'String'));

%Posisi DC-Offset dikonversi menjadi cuplik
posisiDCoffset = round((Fs2) * posisiDCoffset);

% Sinyal komposit Subtransien dan DC-Offset
s0 = [ampFundamental*sin(2*frekFundamental.*linspace(0,pi,n)) 0];
s1 = [zeros(1,posisiSubtransien) subTransien zeros(1,n-posisiSubtransien-1) 0];

s2 = [zeros(1,posisiDCoffset-1) dcOffset+zeros(1,n-posisiDCoffset+1) 0];
y = s0 + s1 + s2;

%Simpan y dan level_kontinyu
save y4.mat y;
save level_kontinyu.mat level_kontinyu;

% Menampis sinyal komposit dengan LPF
axes(handles.sumbu1);
plot((n/Fs2)*(0:1/n:1),y,'c','LineWidth',2);
grid on
set(gca, 'XColor', 'r')
set(gca, 'YColor', 'r')
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal Sub-transien Dengan Gelombang DC-Offset')
set(gca,'Color',[0 0 0]);

% Melakukan transformasi wavelet diskrit pada level 5 dengan sym2.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
level_maks = levelD;
[c,l] = wavedec(y,level_maks,'sym2');
lv = length(y);

% Mengekspansi koefisien-koefisien wavelet diskrit untuk ditampilkan.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
cfd = zeros(level_maks,lv);
for k = 1:level_maks
d = detcoef(c,l,k);
d = d(ones(1,2^k),:);
cfd(k,:) = wkeep(d(:)',lv);
end
cfd = cfd(:);
I = find(abs(cfd)<sqrt(eps));
cfd(I)=zeros(size(I));
cfd4 = reshape(cfd,level_maks,lv);

save cfd4.mat cfd4;

% Menampilkan koefisien-koefisien diskrit
axes(handles.sumbu2), colormap(pink(64));
img = image(flipud(wcodemat(cfd4,64,'row')));
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
set(get(img,'parent'),'YtickLabels',[]);
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
axes(handles.sumbu3),
ccf4 = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');

%Menyimpan koefisien-koefisien wavelet kontinyu
save ccf4.mat ccf4;


set(handles.teks_jumlah_data,'String',num2str(n));
set(handles.teks_jumlah_level,'String',num2str(level_kontinyu));
set(handles.teks_levelD,'String',num2str(levelD));
set(handles.FrekCuplik,'String',num2str(Fs2));

%figure baru
% Menampilkan koefisien-koefisien diskrit
figure, colormap(pink(64));
img = image(flipud(wcodemat(cfd4,64,'row')));
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
set(get(img,'parent'),'YtickLabels',[]);
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
figure,
ccf = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');

% --- Executes on button press in tombol_waktu_frekuensi_DC_Offset_Harmonisa.
function tombol_waktu_frekuensi_DC_Offset_Harmonisa_Callback(hObject, eventdata, handles)
% hObject    handle to tombol_waktu_frekuensi_DC_Offset_Harmonisa (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla(handles.sumbu2,'reset');
cla(handles.sumbu3,'reset');

% Membaca parameter global
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
levelD = str2num(get(handles.editLevelD,'String'));

frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
subTransien = str2num(get(handles.editTransien,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
posisiSubtransien = str2num(get(handles.editposisiSubtransien,'String'));

level_kontinyu=levelMaks;
thr=ambangBatas;
n=banyakCuplik;

%Simpan n dan Fs2 dan levelD
save n.mat n;
save Fs2.mat Fs2;
save levelD.mat levelD;

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
frek100 = str2num(get(handles.edit100,'String'));
frek150 = str2num(get(handles.edit150,'String'));
frek200 = str2num(get(handles.edit200,'String'));
frek250 = str2num(get(handles.edit250,'String'));

amp100 = str2num(get(handles.edit101,'String'));
amp150 = str2num(get(handles.edit151,'String'));
amp200 = str2num(get(handles.edit201,'String'));
amp250 = str2num(get(handles.edit251,'String'));

% Membaca frekuensi-frekuensi inter-harmonisa dan amplitudo
frek25 = str2num(get(handles.edit25,'String'));
frek75 = str2num(get(handles.edit75,'String'));
frek125 = str2num(get(handles.edit125,'String'));
frek175 = str2num(get(handles.edit175,'String'));

amp25 = str2num(get(handles.edit2511,'String'));
amp75 = str2num(get(handles.edit751,'String'));
amp125 = str2num(get(handles.edit1251,'String'));
amp175 = str2num(get(handles.edit1751,'String'));


% Sinyal komposit
% Frekuensi harmonisa 100, 150, 200, dan 250 Hz
s = ampFundamental*sin(2*frekFundamental.*linspace(0,pi,n))+ amp100* sin(2*frek100.*linspace(0,pi,n))+...
    amp150*sin(2*frek150.*linspace(0,pi,n))+ amp200*sin(2*frek200.*linspace(0,pi,n))+...
    amp250*sin(2*frek250.*linspace(0,pi,n));% + 0.25.*rand(1,n);

y = [s(1:100) s(100) s(101:n)];

%Simpan y dan level_kontinyu
save y5.mat y;
save level_kontinyu.mat level_kontinyu;

% Menampis sinyal komposit
axes(handles.sumbu1);
plot((n/Fs2)*(0:1/n:1),y,'w','LineWidth',2);
grid on
set(gca, 'XColor', 'r')
set(gca, 'YColor', 'r')
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal Harmonisa')
set(gca,'Color',[0 0 0]);

% Melakukan transformasi wavelet diskrit pada level 5 dengan sym2.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
level_maks = levelD;
[c,l] = wavedec(y,level_maks,'sym2');
lv = length(y);

% Mengekspansi koefisien-koefisien wavelet diskrit untuk ditampilkan.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
cfd = zeros(level_maks,lv);
for k = 1:level_maks
d = detcoef(c,l,k);
d = d(ones(1,2^k),:);
cfd(k,:) = wkeep(d(:)',lv);
end
cfd = cfd(:);
I = find(abs(cfd)<sqrt(eps));
cfd(I)=zeros(size(I));
cfd5 = reshape(cfd,level_maks,lv);

save cfd5.mat cfd5;

% Menampilkan koefisien-koefisien diskrit
axes(handles.sumbu2), colormap(pink(64));
img = image(flipud(wcodemat(cfd5,64,'row')));
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
set(get(img,'parent'),'YtickLabels',[]);
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
axes(handles.sumbu3),
ccf5 = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');

%Menyimpan koefisien-koefisien wavelet kontinyu
save ccf5.mat ccf5;

set(handles.teks_jumlah_data,'String',num2str(n));
set(handles.teks_jumlah_level,'String',num2str(level_kontinyu));
set(handles.teks_levelD,'String',num2str(levelD));
set(handles.FrekCuplik,'String',num2str(Fs2));

%figurebaru
% Menampilkan koefisien-koefisien diskrit
figure, colormap(pink(64));
img = image(flipud(wcodemat(cfd5,64,'row')));
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
set(get(img,'parent'),'YtickLabels',[]);
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
figure,
ccf = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');

function teks_jumlah_data_Callback(hObject, eventdata, handles)
% hObject    handle to teks_jumlah_data (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of teks_jumlah_data as text
%        str2double(get(hObject,'String')) returns contents of teks_jumlah_data as a double


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

% Hint: edit 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


% --- Executes on button press in tombol_peta_waktu_frekuensi_DCoffset_IterHarmonisa.
function tombol_peta_waktu_frekuensi_DCoffset_IterHarmonisa_Callback(hObject, eventdata, handles)
% hObject    handle to tombol_peta_waktu_frekuensi_DCoffset_IterHarmonisa (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

cla(handles.sumbu2,'reset');
cla(handles.sumbu3,'reset');

% Membaca parameter global
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
levelD = str2num(get(handles.editLevelD,'String'));

frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
subTransien = str2num(get(handles.editTransien,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
posisiSubtransien = str2num(get(handles.editposisiSubtransien,'String'));

level_kontinyu=levelMaks;
thr=ambangBatas;
n=banyakCuplik;

%Simpan n dan Fs2 dan levelD
save n.mat n;
save Fs2.mat Fs2;
save levelD.mat levelD;

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
frek100 = str2num(get(handles.edit100,'String'));
frek150 = str2num(get(handles.edit150,'String'));
frek200 = str2num(get(handles.edit200,'String'));
frek250 = str2num(get(handles.edit250,'String'));

amp100 = str2num(get(handles.edit101,'String'));
amp150 = str2num(get(handles.edit151,'String'));
amp200 = str2num(get(handles.edit201,'String'));
amp250 = str2num(get(handles.edit251,'String'));

% Membaca frekuensi-frekuensi inter-harmonisa dan amplitudo
frek25 = str2num(get(handles.edit25,'String'));
frek75 = str2num(get(handles.edit75,'String'));
frek125 = str2num(get(handles.edit125,'String'));
frek175 = str2num(get(handles.edit175,'String'));

amp25 = str2num(get(handles.edit2511,'String'));
amp75 = str2num(get(handles.edit751,'String'));
amp125 = str2num(get(handles.edit1251,'String'));
amp175 = str2num(get(handles.edit1751,'String'));


% Sinyal komposit yang memuat frekuensi-frekuensi inter-harmonisa
s =  ampFundamental*sin(2*frekFundamental.*linspace(0,pi,n));

s = s + amp25* sin(2*frek25.*linspace(0,pi,n)) + amp75* sin(2*frek75.*linspace(0,pi,n)) + ...
    amp125* sin(2*frek125.*linspace(0,pi,n)) + amp175* sin(2*frek175.*linspace(0,pi,n));

y = [s(1:100) s(101:n) 0];

%Simpan y dan level_kontinyu
save y6.mat y;
save level_kontinyu.mat level_kontinyu;

% Menampis sinyal komposit
axes(handles.sumbu1);
plot((n/Fs2)*(0:1/n:1),y,'y','LineWidth',2);
grid on
set(gca, 'XColor', 'r')
set(gca, 'YColor', 'r')
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal Inter-Harmonisa')
set(gca,'Color',[0 0 0]);

% Melakukan transformasi wavelet diskrit pada level 5 dengan sym2.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
level_maks = levelD;
[c,l] = wavedec(y,level_maks,'sym2');
lv = length(y);

% Mengekspansi koefisien-koefisien wavelet diskrit untuk ditampilkan.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
cfd = zeros(level_maks,lv);
for k = 1:level_maks
d = detcoef(c,l,k);
d = d(ones(1,2^k),:);
cfd(k,:) = wkeep(d(:)',lv);
end
cfd = cfd(:);
I = find(abs(cfd)<sqrt(eps));
cfd(I)=zeros(size(I));
cfd6 = reshape(cfd,level_maks,lv);

save cfd6.mat cfd6;
% Menampilkan koefisien-koefisien diskrit
axes(handles.sumbu2), colormap(pink(64));
img = image(flipud(wcodemat(cfd6,64,'row')));
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
set(get(img,'parent'),'YtickLabels',[]);
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
axes(handles.sumbu3),
ccf6 = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');

%Menyimpan koefisien-koefisien wavelet kontinyu
save ccf6.mat ccf6;

set(handles.teks_jumlah_data,'String',num2str(n));
set(handles.teks_jumlah_level,'String',num2str(level_kontinyu));
set(handles.teks_levelD,'String',num2str(levelD));
set(handles.FrekCuplik,'String',num2str(Fs2));

%figurebaru
% Menampilkan koefisien-koefisien diskrit
figure, colormap(pink(64));
img = image(flipud(wcodemat(cfd6,64,'row')));
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
set(get(img,'parent'),'YtickLabels',[]);
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
figure,
ccf = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');

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

% Hints: contents = get(hObject,'String') returns teks_mode contents as cell array
%        contents{get(hObject,'Value')} returns selected item from teks_mode


% --- Executes during object creation, after setting all properties.
function teks_mode_CreateFcn(hObject, eventdata, handles)
% hObject    handle to teks_mode (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


% --- Executes on button press in tombol_kembali.
function tombol_kembali_Callback(hObject, eventdata, handles)
% hObject    handle to tombol_kembali (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
run 'form_utama';
close 'wavelet_ubah';


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

% Hint: place code in OpeningFcn to populate sinyal



function teks_jumlah_level_Callback(hObject, eventdata, handles)
% hObject    handle to teks_jumlah_level (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of teks_jumlah_level as text
%        str2double(get(hObject,'String')) returns contents of teks_jumlah_level as a double


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

% Hint: edit 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



function teks_levelD_Callback(hObject, eventdata, handles)
% hObject    handle to teks_levelD (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of teks_levelD as text
%        str2double(get(hObject,'String')) returns contents of teks_levelD as a double


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

% Hint: edit 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


% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla(handles.sumbu2,'reset');
cla(handles.sumbu3,'reset');
% Membaca parameter global
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
levelD = str2num(get(handles.editLevelD,'String'));

frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
subTransien = str2num(get(handles.editTransien,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
posisiSubtransien = str2num(get(handles.editposisiSubtransien,'String'));

level_kontinyu=levelMaks;
thr=ambangBatas;
n=banyakCuplik;

%Posisi subtransien dikonversi menjadi cuplik
posisiSubtransien = round((Fs2) * posisiSubtransien);

%Simpan n dan Fs2 dan levelD
save n.mat n;
save Fs2.mat Fs2;
save levelD.mat levelD;

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
frek100 = str2num(get(handles.edit100,'String'));
frek150 = str2num(get(handles.edit150,'String'));
frek200 = str2num(get(handles.edit200,'String'));
frek250 = str2num(get(handles.edit250,'String'));

amp100 = str2num(get(handles.edit101,'String'));
amp150 = str2num(get(handles.edit151,'String'));
amp200 = str2num(get(handles.edit201,'String'));
amp250 = str2num(get(handles.edit251,'String'));

% Membaca frekuensi-frekuensi inter-harmonisa dan amplitudo
frek25 = str2num(get(handles.edit25,'String'));
frek75 = str2num(get(handles.edit75,'String'));
frek125 = str2num(get(handles.edit125,'String'));
frek175 = str2num(get(handles.edit175,'String'));

amp25 = str2num(get(handles.edit2511,'String'));
amp75 = str2num(get(handles.edit751,'String'));
amp125 = str2num(get(handles.edit1251,'String'));
amp175 = str2num(get(handles.edit1751,'String'));


% Sinyal komposit
% Frekuensi harmonisa dan subtransien
y = ampFundamental*sin(2*frekFundamental.*linspace(0,pi,n))+ amp100* sin(2*frek100.*linspace(0,pi,n))+...
    amp150*sin(2*frek150.*linspace(0,pi,n))+ amp200*sin(2*frek200.*linspace(0,pi,n))+...
    amp250*sin(2*frek250.*linspace(0,pi,n));% + 0.25.*rand(1,n);
y = [y(1:posisiSubtransien-1) subTransien y(posisiSubtransien+1:n)];


%Simpan y dan level_kontinyu
save y1.mat y;
save level_kontinyu.mat level_kontinyu;

% Menampis sinyal komposit
axes(handles.sumbu1);
plot((n/Fs2)*(0:1/n:1-1/n),y, 'y','LineWidth',2);
grid on
set(gca, 'XColor', 'r')
set(gca, 'YColor', 'r')
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal Harmonik Dengan Gelombang Subtransien')
set(gca,'Color',[0 0 0]);

% Melakukan transformasi wavelet diskrit dengan jenis wavelet sym2.
level_maks = levelD;
[c,l] = wavedec(y,level_maks,'sym2');
lv = length(y);

% Mengekspansi koefisien-koefisien wavelet diskrit untuk ditampilkan.
cfd = zeros(level_maks,lv);
for k = 1:level_maks
d = detcoef(c,l,k);
d = d(ones(1,2^k),:);
cfd(k,:) = wkeep(d(:)',lv);
end
cfd = cfd(:);
I = find(abs(cfd)<sqrt(eps));
cfd(I)=zeros(size(I));
cfd = abs(reshape(cfd,level_maks,lv));
save cfd1.mat cfd;

% Menampilkan koefisien-koefisien diskrit
axes(handles.sumbu2), colormap(pink(64));
img = image(flipud(wcodemat(cfd,64,'row')));
set(get(img,'parent'),'YtickLabels',[]);
grid on
set(gca, 'XColor', 'r')
set(gca, 'YColor', 'r')
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );

set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
axes(handles.sumbu3),
ccf1 = abs(cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT'));
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
grid on
set(gca, 'XColor', 'r')
set(gca, 'YColor', 'r')
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');

%Menyimpan koefisien-koefisien wavelet kontinyu
save ccf1.mat ccf1;

set(handles.teks_jumlah_data,'String',num2str(n));
set(handles.teks_jumlah_level,'String',num2str(level_kontinyu));
set(handles.teks_levelD,'String',num2str(levelD));
set(handles.FrekCuplik,'String',num2str(Fs2));

%Menampilkan figure baru
figure,
colormap(pink(64));
img = image(flipud(wcodemat(cfd,64,'row')));
set(get(img,'parent'),'YtickLabels',[]);
grid on
set(gca, 'XColor', 'r')
set(gca, 'YColor', 'r')
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );


figure,
ccf = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'r')
set(gca, 'YColor', 'r')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );

%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');


% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla(handles.sumbu2,'reset');
cla(handles.sumbu3,'reset');
% Membaca parameter global
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
levelD = str2num(get(handles.editLevelD,'String'));

frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
subTransien = str2num(get(handles.editTransien,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
posisiSubtransien = str2num(get(handles.editposisiSubtransien,'String'));

level_kontinyu=levelMaks;
thr=ambangBatas;
n=banyakCuplik;


%Simpan n dan Fs2 dan levelD
save n.mat n;
save Fs2.mat Fs2;
save levelD.mat levelD;

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
frek100 = str2num(get(handles.edit100,'String'));
frek150 = str2num(get(handles.edit150,'String'));
frek200 = str2num(get(handles.edit200,'String'));
frek250 = str2num(get(handles.edit250,'String'));

amp100 = str2num(get(handles.edit101,'String'));
amp150 = str2num(get(handles.edit151,'String'));
amp200 = str2num(get(handles.edit201,'String'));
amp250 = str2num(get(handles.edit251,'String'));

% Membaca frekuensi-frekuensi inter-harmonisa dan amplitudo
frek25 = str2num(get(handles.edit25,'String'));
frek75 = str2num(get(handles.edit75,'String'));
frek125 = str2num(get(handles.edit125,'String'));
frek175 = str2num(get(handles.edit175,'String'));

amp25 = str2num(get(handles.edit2511,'String'));
amp75 = str2num(get(handles.edit751,'String'));
amp125 = str2num(get(handles.edit1251,'String'));
amp175 = str2num(get(handles.edit1751,'String'));


%Membaca DC-Offset dan posisi DC-Offset
posisiDCoffset = str2num(get(handles.editposisiDCoffset,'String'));
dcOffset = str2num(get(handles.editOffset,'String'));

%Posisi DC-Offset dikonversi menjadi cuplik
posisiDCoffset = round((Fs2) * posisiDCoffset);

% Sinyal komposit
% Frekuensi harmonisa 100, 150, 200, dan 250 Hz Dengan DC-Offset
y = ampFundamental*sin(2*frekFundamental.*linspace(0,pi,n))+ amp100* sin(2*frek100.*linspace(0,pi,n))+...
    amp150*sin(2*frek150.*linspace(0,pi,n))+ amp200*sin(2*frek200.*linspace(0,pi,n))+...
    amp250*sin(2*frek250.*linspace(0,pi,n));% + 0.25.*rand(1,n);

y = [y(1:100) y(101:posisiDCoffset) dcOffset+y(posisiDCoffset+1:n)];

%Simpan y dan level_kontinyu
save y2.mat y;
save level_kontinyu.mat level_kontinyu;

% Menampis sinyal komposit dengan LPF
axes(handles.sumbu1);
plot((n/Fs2)*(0:1/n:1-1/n),y,'b','LineWidth',2);
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal Harmonik Dengan Gelombang DC-Offset')
set(gca,'Color',[0 0 0]);

% Melakukan transformasi wavelet diskrit pada level 5 dengan sym2.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
level_maks = levelD;
[c,l] = wavedec(y,level_maks,'sym2');
lv = length(y);

% Mengekspansi koefisien-koefisien wavelet diskrit untuk ditampilkan.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
cfd = zeros(level_maks,lv);
for k = 1:level_maks
d = detcoef(c,l,k);
d = d(ones(1,2^k),:);
cfd(k,:) = wkeep(d(:)',lv);
end
cfd = cfd(:);
I = find(abs(cfd)<sqrt(eps));
cfd(I)=zeros(size(I));
cfd2 = reshape(cfd,level_maks,lv);
save cfd2.mat cfd2;

% Menampilkan koefisien-koefisien diskrit
axes(handles.sumbu2), colormap(pink(64));
img = image(flipud(wcodemat(cfd2,64,'row')));
set(get(img,'parent'),'YtickLabels',[]);
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
axes(handles.sumbu3),
ccf2 = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');

%Menyimpan koefisien-koefisien wavelet kontinyu
save ccf2.mat ccf2;

set(handles.teks_jumlah_data,'String',num2str(n));
set(handles.teks_jumlah_level,'String',num2str(level_kontinyu));
set(handles.teks_levelD,'String',num2str(levelD));
set(handles.FrekCuplik,'String',num2str(Fs2));


% Menampilkan figure baru
figure, colormap(pink(64));
img = image(flipud(wcodemat(cfd2,64,'row')));
set(get(img,'parent'),'YtickLabels',[]);
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

%Menampilkan figure baru
figure,
ccf = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');


% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla(handles.sumbu2,'reset');
cla(handles.sumbu3,'reset');
% Membaca parameter global
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
levelD = str2num(get(handles.editLevelD,'String'));

frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
subTransien = str2num(get(handles.editTransien,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
posisiSubtransien = str2num(get(handles.editposisiSubtransien,'String'));

level_kontinyu=levelMaks;
thr=ambangBatas;
n=banyakCuplik;

%Simpan n dan Fs2 dan levelD
save n.mat n;
save Fs2.mat Fs2;
save levelD.mat levelD;

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
frek100 = str2num(get(handles.edit100,'String'));
frek150 = str2num(get(handles.edit150,'String'));
frek200 = str2num(get(handles.edit200,'String'));
frek250 = str2num(get(handles.edit250,'String'));

amp100 = str2num(get(handles.edit101,'String'));
amp150 = str2num(get(handles.edit151,'String'));
amp200 = str2num(get(handles.edit201,'String'));
amp250 = str2num(get(handles.edit251,'String'));

% Membaca frekuensi-frekuensi inter-harmonisa dan amplitudo
frek25 = str2num(get(handles.edit25,'String'));
frek75 = str2num(get(handles.edit75,'String'));
frek125 = str2num(get(handles.edit125,'String'));
frek175 = str2num(get(handles.edit175,'String'));

amp25 = str2num(get(handles.edit2511,'String'));
amp75 = str2num(get(handles.edit751,'String'));
amp125 = str2num(get(handles.edit1251,'String'));
amp175 = str2num(get(handles.edit1751,'String'));


%Membaca DC-Offset dan posisi DC-Offset
posisiDCoffset = str2num(get(handles.editposisiDCoffset,'String'));
dcOffset = str2num(get(handles.editOffset,'String'));

%Posisi DC-Offset dikonversi menjadi cuplik
posisiDCoffset = round((Fs2) * posisiDCoffset);

% Sinyal komposit
% Penambahan inter-harmonisa untuk frekuensi 25, 75, dan 125 Hz
% Intra-harmonisa adalah kelipatan tak-integer dari frekuensi fundamental
% Dan penambahan sinyal DC-Offset
y = ampFundamental*sin(2*frekFundamental.*linspace(0,pi,n)) + amp25* sin(2*frek25.*linspace(0,pi,n)) + amp75*sin(2*frek75.*linspace(0,pi,n)) + ...
    amp125*sin(2*frek125.*linspace(0,pi,n)) + amp175*sin(2*frek175.*linspace(0,pi,n));

%Penambahan DC offset
y = [y(1:100) y(101:posisiDCoffset) dcOffset+y(posisiDCoffset+1:n)];

%Simpan y dan level_kontinyu
save y3.mat y;
save level_kontinyu.mat level_kontinyu;

% Menampis sinyal komposit dengan LPF
axes(handles.sumbu1);
plot((n/Fs2)*(0:1/n:1-1/n),y,'r','LineWidth',2);
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal Inter-Harmonik Dengan Gelombang DC-Offset')
set(gca,'Color',[0 0 0]);

% Melakukan transformasi wavelet diskrit pada level 5 dengan sym2.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
level_maks = levelD;
[c,l] = wavedec(y,level_maks,'sym2');
lv = length(y);

% Mengekspansi koefisien-koefisien wavelet diskrit untuk ditampilkan.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
cfd = zeros(level_maks,lv);
for k = 1:level_maks
d = detcoef(c,l,k);
d = d(ones(1,2^k),:);
cfd(k,:) = wkeep(d(:)',lv);
end
cfd = cfd(:);
I = find(abs(cfd)<sqrt(eps));
cfd(I)=zeros(size(I));
cfd3 = reshape(cfd,level_maks,lv);

save cfd3.mat cfd3;

% Menampilkan koefisien-koefisien diskrit
axes(handles.sumbu2), colormap(pink(64));
img = image(flipud(wcodemat(cfd3,64,'row')));
set(get(img,'parent'),'YtickLabels',[]);
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
axes(handles.sumbu3),
ccf3 = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');

%Menyimpan koefisien-koefisien wavelet kontinyu
save ccf3.mat ccf3;

set(handles.teks_jumlah_data,'String',num2str(n));
set(handles.teks_jumlah_level,'String',num2str(level_kontinyu));
set(handles.teks_levelD,'String',num2str(levelD));
set(handles.FrekCuplik,'String',num2str(Fs2));

%figure baru
% Menampilkan koefisien-koefisien diskrit
figure, colormap(pink(64));
img = image(flipud(wcodemat(cfd3,64,'row')));
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
set(get(img,'parent'),'YtickLabels',[]);
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTick',levelD*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca,'YTickLabel',(Fs2/2)*[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0] );

% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
figure,
ccf = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');



function FrekCuplik_Callback(hObject, eventdata, handles)
% hObject    handle to FrekCuplik (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of FrekCuplik as text
%        str2double(get(hObject,'String')) returns contents of FrekCuplik as a double


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

% Hint: edit 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


% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Membaca parameter global
banykCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));

n=banykCuplik;
Fs=1000;

s=sin(2*50.*linspace(0,pi,n))+ 0.1*sin(2*100.*linspace(0,pi,n))+ 0.1*sin(2*150.*linspace(0,pi,n))+...
    0.1*sin(2*200.*linspace(0,pi,n))+ 0.1*sin(2*250.*linspace(0,pi,n))+ 0.5.*rand(1,n);

%axes(handles.sinyal);
subplot(3,3,1);plot(0:1/Fs:1-1/Fs,s);title('sinyal semula');
ylabel('amplitudo');xlabel('Detik');

%dekomposisi wavelet level 1 dari sinyal semula
[A1,D1]=dwt(s,'db4');
subplot(3,3,2);plot(1:length(A1), A1);
axis([1,length(A1), min(A1), max(A1)]);
title('koefisien aproksimasi lvl 1 A1');
ylabel('amplitudo');xlabel('cuplik');

subplot(3,3,3);plot(1:length(D1), D1);
axis([1,length(D1), min(D1), max(D1)]);
title('koefisien detail lvl 1 D1');
ylabel('amplitudo');xlabel('cuplik');


set(handles.teks_jumlah_data,'String',num2str(n));

%membuat figure baru
s1=sin(2*50.*linspace(0,pi,n));
figure,plot(s1);title('sinyal semula');
ylabel('amplitudo');xlabel('cuplik');
set(gca, 'YLIM',[-2 2]);

figure,plot(A1);title('koefisien aproksimasi lvl 1 A1');
axis([1,length(A1), min(A1), max(A1)]);
ylabel('amplitudo');xlabel('cuplik');
set(gca, 'YLIM',[-2 2]);

figure,plot(D1);title('koefisien detail lvl 1 D1');
axis([1,length(D1), min(D1), max(D1)]);
ylabel('amplitudo');xlabel('cuplik');
set(gca, 'YLIM',[-2 2]);



function edit100_Callback(hObject, eventdata, handles)
% hObject    handle to edit100 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit100 as text
%        str2double(get(hObject,'String')) returns contents of edit100 as a double


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

% Hint: edit 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



function edit101_Callback(hObject, eventdata, handles)
% hObject    handle to edit101 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit101 as text
%        str2double(get(hObject,'String')) returns contents of edit101 as a double


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

% Hint: edit 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



function edit25_Callback(hObject, eventdata, handles)
% hObject    handle to edit25 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit25 as text
%        str2double(get(hObject,'String')) returns contents of edit25 as a double


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

% Hint: edit 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



function edit2511_Callback(hObject, eventdata, handles)
% hObject    handle to edit2511 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2511 as text
%        str2double(get(hObject,'String')) returns contents of edit2511 as a double


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

% Hint: edit 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



function edit75_Callback(hObject, eventdata, handles)
% hObject    handle to edit75 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit75 as text
%        str2double(get(hObject,'String')) returns contents of edit75 as a double


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

% Hint: edit 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



function edit751_Callback(hObject, eventdata, handles)
% hObject    handle to edit751 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit751 as text
%        str2double(get(hObject,'String')) returns contents of edit751 as a double


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

% Hint: edit 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



function edit125_Callback(hObject, eventdata, handles)
% hObject    handle to edit125 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit125 as text
%        str2double(get(hObject,'String')) returns contents of edit125 as a double


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

% Hint: edit 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



function edit1251_Callback(hObject, eventdata, handles)
% hObject    handle to edit1251 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1251 as text
%        str2double(get(hObject,'String')) returns contents of edit1251 as a double


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

% Hint: edit 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



function edit175_Callback(hObject, eventdata, handles)
% hObject    handle to edit175 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit175 as text
%        str2double(get(hObject,'String')) returns contents of edit175 as a double


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

% Hint: edit 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



function edit1751_Callback(hObject, eventdata, handles)
% hObject    handle to edit1751 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1751 as text
%        str2double(get(hObject,'String')) returns contents of edit1751 as a double


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

% Hint: edit 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



function edit150_Callback(hObject, eventdata, handles)
% hObject    handle to edit150 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit150 as text
%        str2double(get(hObject,'String')) returns contents of edit150 as a double


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

% Hint: edit 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



function edit151_Callback(hObject, eventdata, handles)
% hObject    handle to edit151 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit151 as text
%        str2double(get(hObject,'String')) returns contents of edit151 as a double


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

% Hint: edit 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



function edit200_Callback(hObject, eventdata, handles)
% hObject    handle to edit200 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit200 as text
%        str2double(get(hObject,'String')) returns contents of edit200 as a double


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

% Hint: edit 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



function edit201_Callback(hObject, eventdata, handles)
% hObject    handle to edit201 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit201 as text
%        str2double(get(hObject,'String')) returns contents of edit201 as a double


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

% Hint: edit 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



function edit250_Callback(hObject, eventdata, handles)
% hObject    handle to edit250 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit250 as text
%        str2double(get(hObject,'String')) returns contents of edit250 as a double


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

% Hint: edit 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



function edit251_Callback(hObject, eventdata, handles)
% hObject    handle to edit2511 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2511 as text
%        str2double(get(hObject,'String')) returns contents of edit2511 as a double


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

% Hint: edit 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



function editCuplik_Callback(hObject, eventdata, handles)
% hObject    handle to editCuplik (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editCuplik as text
%        str2double(get(hObject,'String')) returns contents of editCuplik as a double


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

% Hint: edit 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



function editLevelK_Callback(hObject, eventdata, handles)
% hObject    handle to editLevelK (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editLevelK as text
%        str2double(get(hObject,'String')) returns contents of editLevelK as a double


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

% Hint: edit 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



function editLevelD_Callback(hObject, eventdata, handles)
% hObject    handle to editLevelD (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editLevelD as text
%        str2double(get(hObject,'String')) returns contents of editLevelD as a double


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

% Hint: edit 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



function editFrekCuplik_Callback(hObject, eventdata, handles)
% hObject    handle to editFrekCuplik (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editFrekCuplik as text
%        str2double(get(hObject,'String')) returns contents of editFrekCuplik as a double


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

% Hint: edit 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


% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));

level_kontinyu=levelMaks;
thr=ambangBatas;
n=banyakCuplik;

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
frek100 = str2num(get(handles.edit100,'String'));
frek150 = str2num(get(handles.edit150,'String'));
frek200 = str2num(get(handles.edit200,'String'));
frek250 = str2num(get(handles.edit250,'String'));

amp100 = str2num(get(handles.edit101,'String'));
amp150 = str2num(get(handles.edit151,'String'));
amp200 = str2num(get(handles.edit201,'String'));
amp250 = str2num(get(handles.edit2511,'String'));

% Membaca frekuensi-frekuensi inter-harmonisa dan amplitudo
frek25 = str2num(get(handles.edit25,'String'));
frek75 = str2num(get(handles.edit75,'String'));
frek125 = str2num(get(handles.edit125,'String'));
frek175 = str2num(get(handles.edit175,'String'));

amp25 = str2num(get(handles.edit2511,'String'));
amp75 = str2num(get(handles.edit751,'String'));
amp125 = str2num(get(handles.edit1251,'String'));
amp175 = str2num(get(handles.edit1751,'String'));

% Perancangan tapis HPF
Fs = 1000;
fc = 250;
Wn = (2/Fs)*fc;
b = fir1(20,Wn,'high',kaiser(21,3));

% Perancangan tapis LPF
fc2 = 50;
Wn2 = (2/Fs)*fc2;
blpf = fir1(20,Wn2,'low',kaiser(21,3));

% Sinyal komposit yang memuat harmonisa, DC offset, dan derau
DCOffset = 1;

t = 0:1/(n*(Fs2/n)):1/(Fs2/n);
%t = 0:(1/n):(n/Fs2);
y = zeros(n,length(t));
x = zeros(size(t));
for k = 1:2:100
    x = x + sin(frekFundamental*k*2*pi*t)/k;
    y((k+1),:)=x;
end
%plot(y(1:100,:)');
%title('sinyal komposit dari 50 sinyal harmonik')

% Frekuensi harmonisa 100, 150, 200, dan 250 Hz
%s = sin(2*50.*linspace(0,pi,n))+ amp100* sin(2*frek100.*linspace(0,pi,n))+...
%    amp150*sin(2*frek150.*linspace(0,pi,n))+ amp200*sin(2*frek200.*linspace(0,pi,n))+...
%    amp250*sin(2*frek250.*linspace(0,pi,n));% + 0.25.*rand(1,n);

%s = [s(1:99) 5 s(101:500) DCOffset+s(501:n)];

% Menampis sinyal komposit dengan LPF
%y = filter(b,1,s) + filter(blpf,1,s);
subplot(321), plot(y'+ ampFundamental - 1);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal THD (Total Harmonic Distortion)')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',1*(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
set(gca, 'XLIM',[0 n]);


y = y(100,:);
s=y+ampFundamental-1;
% Melakukan transformasi wavelet diskrit pada level 5 dengan sym2.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
level_maks = 10;
[c,l] = wavedec(y,level_maks,'sym2');
lv = length(s);

% Mengekspansi koefisien-koefisien wavelet diskrit untuk ditampilkan.
% Level 1 sampai level maks terkait dengan skala 2, 4, 8, 16 dan 32.
cfd = zeros(level_maks,lv);
for k = 1:level_maks
d = detcoef(c,l,k);
d = d(ones(1,2^k),:);
cfd(k,:) = wkeep(d(:)',lv);
end
cfd = cfd(:);
I = find(abs(cfd)<sqrt(eps));
cfd(I)=zeros(size(I));
cfd = reshape(cfd,level_maks,lv);

% Menampilkan koefisien-koefisien diskrit
subplot(322), colormap(pink(64));
img = image(flipud(wcodemat(cfd,64,'row')));
set(get(img,'parent'),'YtickLabels',[]);
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Level')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',1*(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );


% Melakukan transformasi wavelet kontinyu dengan sym2 pada semua
% skala integer dari 1 sampai level_kontinyu.
%level_kontinyu = 50;
subplot(323)
ccf = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot','scalCNT');
%axis off
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',1*(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
%axis([50 100 axislims(3) axislims(4)]);
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Detik)');


% Melakukan ambang-batas halus terhadap hasil dekomposisi wavelet diskret
%thr = 0.1;
ccf_ambang1 = wthresh(cfd,'h',thr);
subplot(324), contour(ccf_ambang1); title('Hasil ambang-batas halus terhadap wavelet diskret')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',1*(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
xlabel('Waktu(Detik)');

% Melakukan ambang-batas halus terhadap hasil dekomposisi wavelet kontinyu
%thr = 0.1;
ccf_ambang2 = wthresh(ccf,'s',thr);
sumbux=0:n;
sumbuy=1:0.5*Fs2/level_kontinyu:0.5*Fs2;
[sumbu_X,sumbu_Y] = meshgrid(sumbux,sumbuy);
size(sumbu_X);
size(ccf_ambang2);
subplot(325), contour(sumbu_X, sumbu_Y,ccf_ambang2); title('Hasil ambang-batas halus terhadap wavelet kontinyu');ylabel('Frekuensi');
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',1*(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
xlabel('Waktu(Detik)');

% Melakukan ambang-batas kasar terhadap hasil dekomposisi wavelet kontinyu
%thr = 0.1;
ccf_ambang3 = wthresh(ccf,'h',thr);
subplot(326), contour(sumbu_X, sumbu_Y,ccf_ambang3); title('Hasil ambang-batas kasar terhadap wavelet kontinyu');
ylabel('Frekuensi');
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',1*(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );
xlabel('Waktu(Detik)');

set(handles.teks_jumlah_data,'String',num2str(n));
set(handles.teks_jumlah_level,'String',num2str(level_kontinyu));
set(handles.teks_levelD,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));

% Membuat figure baru
figure, ccf = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot');
title('Koefisien Absolut dari Transformasi Wavelet Kontinyu.')
colormap(pink(64));
ylabel('Frekuensi')
xlabel('Waktu(Cuplik)');
set(gca, 'XLIM',[0 Fs]);
set(gca, 'XTick',[0:1:Fs]);

% Membuat figure baru
% Melakukan ambang-batas halus terhadap hasil dekomposisi wavelet kontinyu
%thr = 0.1;
ccf_ambang2 = wthresh(ccf,'s',thr);
sumbux=0:n;
sumbuy=1:0.5*Fs2/level_kontinyu:0.5*Fs2;
[sumbu_X,sumbu_Y] = meshgrid(sumbux,sumbuy);
size(sumbu_X);
size(ccf_ambang2);
figure, contour(sumbu_X, sumbu_Y,ccf_ambang2); title('Hasil ambang-batas halus terhadap wavelet kontinyu');ylabel('Frekuensi');
set(gca, 'XLIM',[0 1000]);
set(gca, 'XTick',[0:1:1000]);

% Melakukan ambang-batas kasar terhadap hasil dekomposisi wavelet kontinyu
%thr = 0.1;
ccf_ambang3 = wthresh(ccf,'h',thr);
figure, contour(sumbu_X, sumbu_Y,ccf_ambang3); title('Hasil ambang-batas kasar terhadap wavelet kontinyu');
ylabel('Frekuensi');
set(gca, 'XLIM',[0 1000]);
set(gca, 'XTick',[0:1:1000]);


% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%membuat objek figure baru
run 'wavelet_ubah2';

% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close 'wavelet_ubah';
run 'form_utama';



function editfrekFundamental_Callback(hObject, eventdata, handles)
% hObject    handle to editfrekFundamental (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editfrekFundamental as text
%        str2double(get(hObject,'String')) returns contents of editfrekFundamental as a double

frekFundamental = str2num(get(handles.editfrekFundamental,'String'));

set(handles.edit100,'String',num2str(2*frekFundamental));
set(handles.edit150,'String',num2str(3*frekFundamental));
set(handles.edit200,'String',num2str(4*frekFundamental));
set(handles.edit250,'String',num2str(5*frekFundamental));

set(handles.edit25,'String',num2str(0.5*frekFundamental));
set(handles.edit75,'String',num2str(1.5*frekFundamental));
set(handles.edit125,'String',num2str(2.5*frekFundamental));
set(handles.edit175,'String',num2str(3.5*frekFundamental));


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

% Hint: edit 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



function editampFundamental_Callback(hObject, eventdata, handles)
% hObject    handle to editampFundamental (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editampFundamental as text
%        str2double(get(hObject,'String')) returns contents of editampFundamental as a double


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

% Hint: edit 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



function editTransien_Callback(hObject, eventdata, handles)
% hObject    handle to editTransien (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editTransien as text
%        str2double(get(hObject,'String')) returns contents of editTransien as a double


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

% Hint: edit 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



function editOffset_Callback(hObject, eventdata, handles)
% hObject    handle to editOffset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editOffset as text
%        str2double(get(hObject,'String')) returns contents of editOffset as a double


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

% Hint: edit 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



function editposisiSubtransien_Callback(hObject, eventdata, handles)
% hObject    handle to editposisiSubtransien (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editposisiSubtransien as text
%        str2double(get(hObject,'String')) returns contents of editposisiSubtransien as a double


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

% Hint: edit 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



function editposisiDCoffset_Callback(hObject, eventdata, handles)
% hObject    handle to editposisiDCoffset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editposisiDCoffset as text
%        str2double(get(hObject,'String')) returns contents of editposisiDCoffset as a double


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

% Hint: edit 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


% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Membaca parameter global
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editLevelD,'String'));
levelMaks = str2num(get(handles.editLevelK,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
levelD = str2num(get(handles.editLevelD,'String'));

frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
subTransien = str2num(get(handles.editTransien,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
posisiSubtransien = str2num(get(handles.editposisiSubtransien,'String'));

level_kontinyu=levelMaks;
thr=ambangBatas;
n=banyakCuplik;

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
frek100 = str2num(get(handles.edit100,'String'));
frek150 = str2num(get(handles.edit150,'String'));
frek200 = str2num(get(handles.edit200,'String'));
frek250 = str2num(get(handles.edit250,'String'));

amp100 = str2num(get(handles.edit101,'String'));
amp150 = str2num(get(handles.edit151,'String'));
amp200 = str2num(get(handles.edit201,'String'));
amp250 = str2num(get(handles.edit251,'String'));

% Membaca frekuensi-frekuensi inter-harmonisa dan amplitudo
frek25 = str2num(get(handles.edit25,'String'));
frek75 = str2num(get(handles.edit75,'String'));
frek125 = str2num(get(handles.edit125,'String'));
frek175 = str2num(get(handles.edit175,'String'));

amp25 = str2num(get(handles.edit2511,'String'));
amp75 = str2num(get(handles.edit751,'String'));
amp125 = str2num(get(handles.edit1251,'String'));
amp175 = str2num(get(handles.edit1751,'String'));


% Sinyal komposit
% Frekuensi harmonisa 100, 150, 200, dan 250 Hz
s = ampFundamental*sin(2*frekFundamental.*linspace(0,pi,n))+ amp100* sin(2*frek100.*linspace(0,pi,n))+...
    amp150*sin(2*frek150.*linspace(0,pi,n))+ amp200*sin(2*frek200.*linspace(0,pi,n))+...
    amp250*sin(2*frek250.*linspace(0,pi,n));% + 0.25.*rand(1,n);

y1 = [s(1:100) s(100) s(101:n)];


% Menampis sinyal komposit
axes(handles.sumbu1);
plot((n/Fs2)*(0:1/n:1),y1,'y','LineWidth',2);
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal Harmonik')
set(gca,'Color',[0 0 0]);


% Sinyal komposit yang memuat frekuensi-frekuensi inter-harmonisa
axes(handles.sumbu2);
s =  ampFundamental*sin(2*frekFundamental.*linspace(0,pi,n));

s = s + amp25* sin(2*frek25.*linspace(0,pi,n)) + amp75* sin(2*frek75.*linspace(0,pi,n)) + ...
    amp125* sin(2*frek125.*linspace(0,pi,n)) + amp175* sin(2*frek175.*linspace(0,pi,n));

y2 = [s(1:100) s(101:n) 0];
plot((n/Fs2)*(0:1/n:1),y2,'r','LineWidth',2);
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal Interharmonik')
set(gca,'Color',[0 0 0]);

%Mengosongkan sumbu3
cla(handles.sumbu3);
%set(handles.sumbu3,'visible','off');
%set(get(handles.sumbu3,'children'),'visible','off');
%axis(handles.sumbu3, 'off');
axes(handles.sumbu3);
y3=y1+y2;
plot((n/Fs2)*(0:1/n:1),y2,'r',(n/Fs2)*(0:1/n:1),y1,'y','LineWidth',2);
hold on
plot((n/Fs2)*(0:1/n:1),y3,'c','LineWidth',3);
grid on
set(gca, 'XColor', 'b')
set(gca, 'YColor', 'b')
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal Harmonik & Interharmonik & Penjumlahan Keduanya')
set(gca,'Color',[0 0 0]);

% --------------------------------------------------------------------
function figure_tabel_Callback(hObject, eventdata, handles)
% hObject    handle to figure_tabel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
run tabel;


% --------------------------------------------------------------------
function tabel_cwt_Callback(hObject, eventdata, handles)
% hObject    handle to tabel_cwt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

run tabel_cwt;


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


% --- Executes on key press with focus on editfrekFundamental and none of its controls.
function editfrekFundamental_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to editfrekFundamental (see GCBO)
% eventdata  structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)

frekFundamental = str2num(get(handles.editfrekFundamental,'String'));

set(handles.edit100,'String',num2str(2*frekFundamental));

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
%frek100 = str2num(get(handles.edit100,'String'));
%frek150 = str2num(get(handles.edit150,'String'));
%frek200 = str2num(get(handles.edit200,'String'));
%frek250 = str2num(get(handles.edit250,'String'));







No comments: