Saturday, June 17, 2017

Cara Membuat GUI MATLAB Untuk METODE STFT UNTUK ANALISA GELOMBANG HARMONISA











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

% Last Modified by GUIDE v2.5 02-Mar-2017 11:46:11

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = waktu_frekuensi_STFT_animasi__FINAL_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'));

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


thr=ambangBatas;
n=banyakCuplik;
nwin = str2num(get(handles.editpjgJendela,'String'));

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


kontrol = 0;
%s=y(1:100,:)';
for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

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

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

% Menghitung STFT Jendela Segitiga
jendela='Segitiga';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(322),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Segitiga (dB)')
%colorbar;


% Menghitung STFT Jendela Hanning
jendela='Hanning';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(323),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hanning (dB)')



% Menghitung STFT Jendela Hamming
jendela='Hamming';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(324),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hamming (dB)')



% Menghitung STFT Jendela Blackman
jendela='Blackman';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(325),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Blackman (dB)')


% Menghitung STFT Jendela Kaiser
%menenukan jenis jendela berdasarkan pilihan

jendela='Kaiser';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
    elseif strcmp(jendela,'Kaiser')==1
    K = sum(kaiser(wlen,2.5))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(326),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Kaiser (dB)')

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

pause(0.1)
end




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

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

thr=ambangBatas;
n=banyakCuplik;
nwin = str2num(get(handles.editpjgJendela,'String'));

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

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



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

% Menghitung STFT Jendela Segitiga
jendela='Segitiga';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(322),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Segitiga (dB)')
%colorbar;


% Menghitung STFT Jendela Hanning
jendela='Hanning';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(323),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hanning (dB)')



% Menghitung STFT Jendela Hamming
jendela='Hamming';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(324),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hamming (dB)')



% Menghitung STFT Jendela Blackman
jendela='Blackman';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(325),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Blackman (dB)')


% Menghitung STFT Jendela Kaiser
%menenukan jenis jendela berdasarkan pilihan

jendela='Kaiser';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
    elseif strcmp(jendela,'Kaiser')==1
    K = sum(kaiser(wlen,2.5))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(326),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Kaiser (dB)')

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

pause(0.1)
end





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

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

thr=ambangBatas;
n=banyakCuplik;
nwin = str2num(get(handles.editpjgJendela,'String'));

% 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:100) s(101:n) zeros(1,1)];

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);
sumbux = [(n/Fs2)*(0:1/n:1)];
size(y)
size(sumbux)
subplot(321), plot(sumbux,y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF')



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

% Menghitung STFT Jendela Segitiga
jendela='Segitiga';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(322),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Segitiga (dB)')
%colorbar;


% Menghitung STFT Jendela Hanning
jendela='Hanning';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(323),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hanning (dB)')



% Menghitung STFT Jendela Hamming
jendela='Hamming';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(324),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hamming (dB)')



% Menghitung STFT Jendela Blackman
jendela='Blackman';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(325),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Blackman (dB)')


% Menghitung STFT Jendela Kaiser
%menenukan jenis jendela berdasarkan pilihan

jendela='Kaiser';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
    elseif strcmp(jendela,'Kaiser')==1
    K = sum(kaiser(wlen,2.5))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(326),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Kaiser (dB)')

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

pause(0.1)
end


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

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

thr=ambangBatas;
n=banyakCuplik;
nwin = str2num(get(handles.editpjgJendela,'String'));

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

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);
sumbux = [(n/Fs2)*(0:1/n:1)];
size(y)
size(sumbux)
subplot(321), plot(sumbux,y);
xlabel('Detik');ylabel('Amplitudo');
title('Sinyal hasil LPF dan HPF')



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

% Menghitung STFT Jendela Segitiga
jendela='Segitiga';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(322),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Segitiga (dB)')
%colorbar;


% Menghitung STFT Jendela Hanning
jendela='Hanning';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(323),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hanning (dB)')



% Menghitung STFT Jendela Hamming
jendela='Hamming';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(324),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hamming (dB)')



% Menghitung STFT Jendela Blackman
jendela='Blackman';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(325),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Blackman (dB)')


% Menghitung STFT Jendela Kaiser
%menenukan jenis jendela berdasarkan pilihan

jendela='Kaiser';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
    elseif strcmp(jendela,'Kaiser')==1
    K = sum(kaiser(wlen,2.5))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(326),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Kaiser (dB)')

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

pause(0.1)
end


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

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


thr=ambangBatas;
n=banyakCuplik;
nwin = str2num(get(handles.editpjgJendela,'String'));

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

% Menghitung STFT Jendela Segitiga
jendela='Segitiga';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(322),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Segitiga (dB)')
%colorbar;


% Menghitung STFT Jendela Hanning
jendela='Hanning';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(323),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hanning (dB)')



% Menghitung STFT Jendela Hamming
jendela='Hamming';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(324),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hamming (dB)')



% Menghitung STFT Jendela Blackman
jendela='Blackman';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(325),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Blackman (dB)')


% Menghitung STFT Jendela Kaiser
%menenukan jenis jendela berdasarkan pilihan

jendela='Kaiser';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
    elseif strcmp(jendela,'Kaiser')==1
    K = sum(kaiser(wlen,2.5))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(326),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Kaiser (dB)')

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

pause(0.1)
end



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

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

thr=ambangBatas;
n=banyakCuplik;
nwin = str2num(get(handles.editpjgJendela,'String'));

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



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

% Menghitung STFT Jendela Segitiga
jendela='Segitiga';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(322),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Segitiga (dB)')
%colorbar;


% Menghitung STFT Jendela Hanning
jendela='Hanning';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(323),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hanning (dB)')



% Menghitung STFT Jendela Hamming
jendela='Hamming';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(324),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hamming (dB)')



% Menghitung STFT Jendela Blackman
jendela='Blackman';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(325),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Blackman (dB)')


% Menghitung STFT Jendela Kaiser
%menenukan jenis jendela berdasarkan pilihan

jendela='Kaiser';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
    elseif strcmp(jendela,'Kaiser')==1
    K = sum(kaiser(wlen,2.5))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(326),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Kaiser (dB)')

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

pause(0.1)
end



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

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

thr=ambangBatas;
n=banyakCuplik;
nwin = str2num(get(handles.editpjgJendela,'String'));

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



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

% Menghitung STFT Jendela Segitiga
jendela='Segitiga';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(322),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Segitiga (dB)')
%colorbar;


% Menghitung STFT Jendela Hanning
jendela='Hanning';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(323),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hanning (dB)')



% Menghitung STFT Jendela Hamming
jendela='Hamming';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(324),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hamming (dB)')



% Menghitung STFT Jendela Blackman
jendela='Blackman';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(325),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Blackman (dB)')


% Menghitung STFT Jendela Kaiser
%menenukan jenis jendela berdasarkan pilihan

jendela='Kaiser';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
    elseif strcmp(jendela,'Kaiser')==1
    K = sum(kaiser(wlen,2.5))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(326),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Kaiser (dB)')

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

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

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


thr=ambangBatas;
n=banyakCuplik;
nwin = str2num(get(handles.editpjgJendela,'String'));

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


kontrol = 0;
%s=y(1:100,:)';
for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

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

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

% Menghitung STFT Jendela Segitiga
jendela='Segitiga';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(322),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Segitiga (dB)')
%colorbar;


% Menghitung STFT Jendela Hanning
jendela='Hanning';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(323),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hanning (dB)')



% Menghitung STFT Jendela Hamming
jendela='Hamming';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(324),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hamming (dB)')



% Menghitung STFT Jendela Blackman
jendela='Blackman';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(325),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Blackman (dB)')


% Menghitung STFT Jendela Kaiser
%menenukan jenis jendela berdasarkan pilihan

jendela='Kaiser';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
    elseif strcmp(jendela,'Kaiser')==1
    K = sum(kaiser(wlen,2.5))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(326),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Kaiser (dB)')

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

pause(0.1)
end



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


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

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


thr=ambangBatas;
n=banyakCuplik;
nwin = str2num(get(handles.editpjgJendela,'String'));

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


kontrol = 0;
%s=y(1:100,:)';
for geser = 2:30:n-1
 
%kontrol = (geser/n)+1;

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

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

% Menghitung STFT Jendela Segitiga
jendela='Segitiga';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(322),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Segitiga (dB)')
%colorbar;


% Menghitung STFT Jendela Hanning
jendela='Hanning';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(323),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hanning (dB)')



% Menghitung STFT Jendela Hamming
jendela='Hamming';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(324),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Hamming (dB)')



% Menghitung STFT Jendela Blackman
jendela='Blackman';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(325),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Blackman (dB)')


% Menghitung STFT Jendela Kaiser
%menenukan jenis jendela berdasarkan pilihan

jendela='Kaiser';
x=s;
fs=Fs2;
xmax = max(abs(x));                 % mencari nilai basolut maksimal
x = x/xmax;                         % merubah ukuran sinyal

% mendefinisikan parameter-parameter analisis
xlen = length(x);                   % mencari panjang sinyal
wlen = nwin;                        % nenentukan panjang jendela
h = wlen/4;                         % menentukan ukuran hop
nfft = 4096;                        % menentukan jumlah point/titik fft


if strcmp(jendela,'Segitiga')==1
    K = sum(rectwin(wlen))/wlen;
elseif strcmp(jendela,'Hanning')==1
    K = sum(hann(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Hamming')==1
    K = sum(hamming(wlen, 'periodic'))/wlen;
elseif strcmp(jendela,'Blackman')==1
    K = sum(blackman(wlen, 'periodic'))/wlen;
    elseif strcmp(jendela,'Kaiser')==1
    K = sum(kaiser(wlen,2.5))/wlen;
end


% melakukan proses STFT
[sfrek, f, t] = stft(x, wlen, h, nfft, fs,jendela);
sfrek = abs(sfrek)/wlen/K;
size(t)
size(f)
size(sfrek)

if rem(nfft, 2)                  
    sfrek(2:end, :) = sfrek(2:end, :).*2;
else                              
    sfrek(2:end-1, :) = sfrek(2:end-1, :).*2;
end

% mengkonversi nilai amplitudo dalam dB (min = -120 dB)
sfrek = 20*log10(sfrek + 1e-6);

% Ambang-batas halus
sfrek1 = wthresh(sfrek,'h',thr);

% plot energi tanpa ambang-batas
subplot(326),
imagesc(t, f, sfrek1);
set(gca,'YDir','normal')
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Waktu, detik')
ylabel('Frekuensi, Hz')
title('Energi Sinyal Dengan Ambang-Batas Dan Jendela Kaiser (dB)')

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

pause(0.1)
end




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



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


No comments: