Saturday, June 17, 2017

Cara Membuat GUI MATLAB Untuk METODE DWT MULTI-LEVEL UNTUK ANALISA GELOMBANG HARMONISA












SEMUA EVENT CALLBACK GUI MATLAB:

function varargout = waktu_frekuensi_wavelet_animasi(varargin)
% WAKTU_FREKUENSI_WAVELET_ANIMASI M-file for waktu_frekuensi_wavelet_animasi.fig
%      WAKTU_FREKUENSI_WAVELET_ANIMASI, by itself, creates a new WAKTU_FREKUENSI_WAVELET_ANIMASI or raises the existing
%      singleton*.
%
%      H = WAKTU_FREKUENSI_WAVELET_ANIMASI returns the handle to a new WAKTU_FREKUENSI_WAVELET_ANIMASI or the handle to
%      the existing singleton*.
%
%      WAKTU_FREKUENSI_WAVELET_ANIMASI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in WAKTU_FREKUENSI_WAVELET_ANIMASI.M with the given input arguments.
%
%      WAKTU_FREKUENSI_WAVELET_ANIMASI('Property','Value',...) creates a new WAKTU_FREKUENSI_WAVELET_ANIMASI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before waktu_frekuensi_wavelet_animasi_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to waktu_frekuensi_wavelet_animasi_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 waktu_frekuensi_wavelet_animasi

% Last Modified by GUIDE v2.5 21-Feb-2017 17:06:48

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @waktu_frekuensi_wavelet_animasi_OpeningFcn, ...
                   'gui_OutputFcn',  @waktu_frekuensi_wavelet_animasi_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 waktu_frekuensi_wavelet_animasi is made visible.
function waktu_frekuensi_wavelet_animasi_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 waktu_frekuensi_wavelet_animasi (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = waktu_frekuensi_wavelet_animasi_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.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'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)
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
subTransien = str2num(get(handles.editTransien,'String'));
dcOffset = str2num(get(handles.editOffset,'String'));
posisiSubtransien = str2num(get(handles.editposisiSubtransien,'String'));
posisiDCoffset = str2num(get(handles.editposisiDCoffset,'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

%DCOffset = 10;
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];
s = s0 + s1 + s2;
kontrol = 0;

for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

s =circshift(s',25);
s=s';

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

%s = [s(1:posisiSubtransien) subTransien s(posisiSubtransien+1:posisiDCoffset) dcOffset+s(posisiDCoffset+1:n)];

% Menampis sinyal komposit dengan LPF
y = filter(b,1,s) + filter(blpf,1,s);
subplot(321), plot((n/Fs2)*(0:1/n:1),y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF')

% 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',(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',(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',(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',(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',(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_nilai_ambang,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));

pause(0.1)
if (kontrol == 5)
    break
end
end


% 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]);





% --- 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)
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'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 = 350;
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
% 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);

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

for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

s =circshift(s',25);
s=s';

% Menampis sinyal komposit dengan LPF
y = filter(b,1,s) + filter(blpf,1,s);
subplot(321), plot((n/Fs2)*(0:1/n:1),y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF')

% 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',(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',(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',(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',(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',(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_nilai_ambang,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));

pause(0.1)
end

% 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 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)
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'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
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));

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

for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

s =circshift(s',25);
s=s';

% Menampis sinyal komposit dengan LPF
y = filter(b,1,s) + filter(blpf,1,s);
subplot(321), plot((n/Fs2)*(0:1/n:1),y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF')

% 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',(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',(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',(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',(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',(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_nilai_ambang,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));

pause(0.1)
end

% 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]);


% --- 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_nilai_ambang_Callback(hObject, eventdata, handles)
% hObject    handle to teks_nilai_ambang (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_nilai_ambang as text
%        str2double(get(hObject,'String')) returns contents of teks_nilai_ambang as a double


% --- Executes during object creation, after setting all properties.
function teks_nilai_ambang_CreateFcn(hObject, eventdata, handles)
% hObject    handle to teks_nilai_ambang (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)
% Membaca parameter global
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'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.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
% 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);
s = [s(1:posisiSubtransien-1) subTransien s(posisiSubtransien+1:n)];

kontrol = 0;

for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

s =circshift(s',25);
s=s';

% Menampis sinyal komposit dengan LPF
y = filter(b,1,s) + filter(blpf,1,s);
x=(n/Fs2)*(0:1/n:1-1/n);
subplot(321), plot(x,y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF');

%Animasi garis
%hold on
%p = plot(x(100),y(100),'o','MarkerFaceColor','red');
%hold off
%axis manual
%for k = 2:length(x)
%    set(p,'XData',x(k));
%    set(p,'YData',y(k));
%    drawnow
%end

% 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',(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',(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;
cfd = cfd./max(max(cfd));
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',(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 = ccf./max(max(ccf));
ccf_ambang2 = wthresh(ccf,'s',thr);
sumbux=1: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',(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 = ccf./max(max(ccf));
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',(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_nilai_ambang,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));

pause(0.1)
end

% Membuat figure baru
figure, ccf = cwt(y,1:0.5*Fs2/level_kontinyu:0.5*Fs2,'sym2','plot');
%mesh(ccf);
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=1: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]);




% --- 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)
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
dcOffset = str2num(get(handles.editOffset,'String'));
posisiDCoffset = str2num(get(handles.editposisiDCoffset,'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;

% 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);

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


kontrol = 0;

for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

s =circshift(s',25);
s=s';

% Menampis sinyal komposit dengan LPF
y = filter(b,1,s) + filter(blpf,1,s);
subplot(321), plot((n/Fs2)*(0:1/n:1-1/n),y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF')

% 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',(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',(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',(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=1: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',(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',(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_nilai_ambang,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));

pause(0.1)
end

% 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=1: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]);



% --- 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)
banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'String'));
frekFundamental = str2num(get(handles.editfrekFundamental,'String'));
ampFundamental = str2num(get(handles.editampFundamental,'String'));
dcOffset = str2num(get(handles.editOffset,'String'));
posisiDCoffset = str2num(get(handles.editposisiDCoffset,'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));


% Penambahan inter-harmonisa untuk frekuensi 25, 75, dan 125 Hz
% Intra-harmonisa adalah kelipatan tak-integer dari frekuensi fundamental
s = 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
s = [s(1:100) s(101:posisiDCoffset) dcOffset+s(posisiDCoffset+1:n)];

kontrol = 0;

for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

s =circshift(s',25);
s=s';

% Menampis sinyal komposit dengan LPF
y = filter(b,1,s) + filter(blpf,1,s);
subplot(321), plot((n/Fs2)*(0:1/n:1-1/n),y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF')

% 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',(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',(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',(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=1: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',(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',(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_nilai_ambang,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));

pause(0.1)
end
% 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=1: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 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.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'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 editLevel_Callback(hObject, eventdata, handles)
% hObject    handle to editLevel (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 editLevel as text
%        str2double(get(hObject,'String')) returns contents of editLevel as a double


% --- Executes during object creation, after setting all properties.
function editLevel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editLevel (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 editAmbang_Callback(hObject, eventdata, handles)
% hObject    handle to editAmbang (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 editAmbang as text
%        str2double(get(hObject,'String')) returns contents of editAmbang as a double


% --- Executes during object creation, after setting all properties.
function editAmbang_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editAmbang (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.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'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)];


for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

y =circshift(y',25);
%w=y';

% Menampis sinyal komposit dengan LPF
%y = filter(b,1,s) + filter(blpf,1,s);
y=y';
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]);


z = y(100,:);
s=z+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(s,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(s,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;
cfd = cfd./max(max(cfd));
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',(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 = ccf./max(max(ccf));
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(sumbux)
%size(ccf_ambang2)
%size(sumbuy)
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',(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 = ccf./max(max(ccf));
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',(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_nilai_ambang,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));
pause(0.1)
end

% Membuat figure baru
figure, ccf = cwt(s,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


% --- 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 pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton15 (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.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'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.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
% Frekuensi harmonisa 100, 150, 200, dan 250 Hz
s2 = 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);

for posisiSubtransien = 2:25:n-1
%posisiSubtransien = 50;
s1 = [zeros(1,posisiSubtransien-1) subTransien zeros(1,n-posisiSubtransien)];
s = s1+ s2;

% Menampis sinyal komposit dengan LPF
y = filter(b,1,s) + filter(blpf,1,s);
x=(n/Fs2)*(0:1/n:1-1/n);
subplot(321), plot(x,y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF');


%Animasi garis
%hold on
%p = plot(x(100),y(100),'o','MarkerFaceColor','red');
%hold off
%axis manual
%for k = 2:length(x)
%    set(p,'XData',x(k));
%    set(p,'YData',y(k));
%    drawnow
%end

% 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',(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',(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;
cfd = cfd./max(max(cfd));
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',(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 = ccf./max(max(ccf));
ccf_ambang2 = wthresh(ccf,'s',thr);
sumbux=1: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',(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 = ccf./max(max(ccf));
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',(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_nilai_ambang,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));

pause(0.1)
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)

banyakCuplik = str2num(get(handles.editCuplik,'String'));
ambangBatas = str2num(get(handles.editAmbang,'String'));
levelMaks = str2num(get(handles.editLevel,'String'));
Fs2 = str2num(get(handles.editFrekCuplik,'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'));
dcOffset = str2num(get(handles.editOffset,'String'));
%posisiDCoffset = str2num(get(handles.editposisiDCoffset,'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
% Frekuensi harmonisa 100, 150, 200, dan 250 Hz
s2 = 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);

for posisiDCoffset = 2:25:n-1
%s = [s(1:100) s(101:posisiDCoffset) dcOffset+s(posisiDCoffset+1:n)];
s1 = [zeros(1,posisiDCoffset-1) dcOffset+zeros(1,n-posisiDCoffset+1)];

 
%posisiSubtransien = 50;
%s1 = [zeros(1,posisiSubtransien-1) subTransien zeros(1,n-posisiSubtransien)];
s = s1+ s2;

% Menampis sinyal komposit dengan LPF
y = filter(b,1,s) + filter(blpf,1,s);
x=(n/Fs2)*(0:1/n:1-1/n);
subplot(321), plot(x,y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF');


%Animasi garis
%hold on
%p = plot(x(100),y(100),'o','MarkerFaceColor','red');
%hold off
%axis manual
%for k = 2:length(x)
%    set(p,'XData',x(k));
%    set(p,'YData',y(k));
%    drawnow
%end

% 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',(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',(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;
cfd = cfd./max(max(cfd));
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',(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 = ccf./max(max(ccf));
ccf_ambang2 = wthresh(ccf,'s',thr);
sumbux=1: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',(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 = ccf./max(max(ccf));
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',(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_nilai_ambang,'String',num2str(thr));
set(handles.FrekCuplik,'String',num2str(Fs2));

pause(0.1)

if (n-posisiDCoffset) < 26
    posisiDCoffset = 2;
end

end



No comments: