Berikut telah dirancang GUI MATLAB yang
mengaplikasikan jendela Hamming sebagai differensiator FIR. Tapis ini juga
diterapkan untuk menapis audio digital.
Berikut adalah kode sumber callback dari
tombol Differensiator FIR:
function
Diff_FIR_Callback(hObject, eventdata, handles)
% hObject handle to Diff_FIR (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
global x;
% Membaca semua
parameter tapis
omega1s =
str2num(get(handles.omega1s,'String'));
omega2s =
str2num(get(handles.omega2s,'String'));
omega1p =
str2num(get(handles.omega1p,'String'));
omega2p =
str2num(get(handles.omega2p,'String'));
A1s =
str2num(get(handles.A1s,'String'));
A2s =
str2num(get(handles.A2s,'String'));
R1p =
str2num(get(handles.R1p,'String'));
R2p =
str2num(get(handles.R2p,'String'));
%Mengalikan dengan
pi
omega1s = omega1s *
pi;
omega1p = omega1p *
pi;
omega2s = omega2s *
pi;
omega2p = omega2p *
pi;
if(omega1s >
omega1p)
%Menghitung
tr_lebar=omega1s-omega1p;
M=ceil(6.6*pi/tr_lebar)+1
alpha=(M-1)/2;
n=[0:1:M-1];
wc=(omega1s+omega1p)/2; %frekuensi cut-off ideal
%Tanggapan tapis
ideal
hd=(cos(pi*(n-alpha)))./(n-alpha);
hd(alpha+1)=0;
%Tanggapan tapis
aktual
w_ham=(hamming(M))';
h=hd.*w_ham;
%Tanggapan
frekuensi
[db,mag,pha,grd,w]=freqz_m(h,[1]);
delta_w=2*pi/1000;
%Menghitung riak
dan atenuasi
Rp=(min(db(1:1:omega1p/delta_w+1))) % riak passband aktual
As=round(max(db(omega1s/delta_w+1:1:501))) % attenuasi stopband minimum
%Menampilkan
tanggapan impuls ideal
axes(handles.axes7);
stem(n,hd,'color','r');
title('Respon impuls ideal');
axis([0 M-1 -1
1]);xlabel('n'); ylabel('hd(n)');
set(gca,'color',[0,0,0]);
%Menampilkan
jendela Hamming
axes(handles.axes8);
stem(n,w_ham,'color','r');
title('Jendela Hamming');
axis([0 M-1 0
1.1]);xlabel('n'); ylabel('wn');
set(gca,'color',[0,0,0]);
%Menampilkan
tanggapan impuls aktual
axes(handles.axes9);
stem(n,h,'color','r');title('Respon
impuls aktual');
axis([0 M-1 -0.1
0.3]);xlabel('n'); ylabel('h(n)');
set(gca,'color',[0,0,0]);
%Menampilkan
tanggapan dalam dB
axes(handles.axes3);
plot(w/pi,db,'color','r',
'LineWidth' ,2);title('Respon magnitudo dalam dB'); grid on;
axis([0 1 -100
10]);xlabel('frekuensi dalam unit pi'); ylabel('dB');
set(gca,'color',[0,0,0]);
% Menghitung Hasil
Penapisan
y =
conv(double(x),double(h), 'same');
axes(handles.axes2);
t =
0:length(y)-1; %vektor indeks
stem(t,y,'linewidth',1,'color','y');title('Keluaran
Tapis')
set(gca,'color',[0,0,0]);
else
h = msgbox('Omega1s Harus Lebih Besar dari
Omega1p');
end
%Menyimpan data
global
global
differensiator
differensiator = h;
Berikut adalah kode sumber callback dari
tombol DIFFERENSIATOR:
function
Differensiator_Callback(hObject, eventdata, handles)
% hObject handle to Differensiator (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
%Membaca data
global
global
differensiator
h = differensiator;
global x_audio;
% Menghitung Hasil
Penapisan
y =
conv(h,x_audio);
axes(handles.axes2);
t =
0:length(y)-1; %vektor indeks
plot(t,y,'linewidth',1,'color','r');title('Keluaran
Tapis')
set(gca,'color',[0,0,0]);
axes(handles.axes3)
specgram(y, 1024,
handles.Fs);
title('Spektrum
Sinyal');
handles.fileDimuat
= 1;
set(gca,'color',[0,0,0]);
handles.x=y;
guidata(hObject,
handles);
No comments:
Post a Comment