Monday, December 11, 2017

Analisis Harmonik Berbasis Transformasi Wavelet Diskret


Antarmuka GUI MATLAB ini dapat dipakai untuk laboratorium sinyal bagi mahasiswa dan untuk menunjang penelitian bagi para peneliti. Anda bisa memesannya pada form pemesanan di bawah ini.












KODE SUMBER SALAH SATU EVENT CALLBACK:


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

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

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

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

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

% Membaca frekuensi-frekuensi harmonisa dan amplitudo
frek100 = str2num(get(handles.edit100,'String'));
frek150 = str2num(get(handles.edit150,'String'));
frek200 = str2num(get(handles.edit200,'String'));
frek250 = str2num(get(handles.edit250,'String'));
 
amp100 = str2num(get(handles.edit101,'String'));
amp150 = str2num(get(handles.edit151,'String'));
amp200 = str2num(get(handles.edit201,'String'));
amp250 = str2num(get(handles.edit251,'String'));
 
% Membaca frekuensi-frekuensi inter-harmonisa dan amplitudo
frek25 = str2num(get(handles.edit25,'String'));
frek75 = str2num(get(handles.edit75,'String'));
frek125 = str2num(get(handles.edit125,'String'));
frek175 = str2num(get(handles.edit175,'String'));
 
amp25 = str2num(get(handles.edit2511,'String'));
amp75 = str2num(get(handles.edit751,'String'));
amp125 = str2num(get(handles.edit1251,'String'));
amp175 = str2num(get(handles.edit1751,'String'));


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


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

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

% Melakukan transformasi wavelet diskrit dengan jenis wavelet sym2.
level_maks = levelD;
[c,l] = wavedec(y,level_maks,'sym2');
lv = length(y);
 
% Mengekspansi koefisien-koefisien wavelet diskrit untuk ditampilkan.
cfd = zeros(level_maks,lv);
for k = 1:level_maks
d = detcoef(c,l,k);
d = d(ones(1,2^k),:);
cfd(k,:) = wkeep(d(:)',lv);
end
cfd = cfd(:);
I = find(abs(cfd)<sqrt(eps));
cfd(I)=zeros(size(I));
cfd = abs(reshape(cfd,level_maks,lv));
save cfd1.mat cfd;
 
% Menampilkan koefisien-koefisien diskrit
axes(handles.sumbu2), colormap(pink(64));
img = image(flipud(wcodemat(cfd,64,'row')));
set(get(img,'parent'),'YtickLabels',[]);
grid on
set(gca, 'XColor', 'r')
set(gca, 'YColor', 'r')
title('Koefisien Absolut dari Transformasi Wavelet Diskrit.')
ylabel('Frekuensi')
set(gca,'XTick',[0 0.1*n 0.2*n 0.3*n 0.4*n 0.5*n 0.6*n 0.7*n 0.8*n 0.9*n 1*n] );
set(gca,'XTickLabel',(n/Fs2)*[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] );

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

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

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

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


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

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


No comments: