Friday, September 1, 2017

TAPIS FIR BERBASIS PENCUPLIKAN FREKUENSI & IMPLEMENTASINYA PADA AUDIO DIGITAL














Berikut adalah kode sumber callback dari tombol Lowpass:

function Lowpass_Callback(hObject, eventdata, handles)
% hObject    handle to Lowpass (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)

M=60; alpha=(M-1)/2; l=0:M-1; w1=(2*pi/M)*l;

%Membaca nilai slider
nilaiSlider = get(handles.slider1,'Value');

% Respon amplitudo ideal tercuplik
Hrs=[ones(1,3+nilaiSlider),0.5925,0.1099,zeros(1,47-nilaiSlider),0.1099,0.5925,ones(1,6)];

% respon amplitudo ideal
Hdr=[1,1,0,0]; wd1=[0,omega1p,omega1s,1];

k1=0:floor((M-1)/2); k2=floor((M-1)/2)+1:M-1;
angH=[-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H=Hrs.*exp(j*angH);

%Respon aktual
h=real(ifft(H,M));
[db,mag,pha,grd,w]=freqz_m(h,1);


[Hr,ww,a,L]=Hr_Tipe2(h);

%Menampilkan sampel-sampel frekuensi
axes(handles.axes7);
plot(w1(1:M/2)/pi, Hrs(1:M/2), 'o', wd1/2, Hdr,'color','r');
axis([0,1,-0.1,1.1]); title('Sampel-sampel frekuensi: M=60')
xlabel('frekuensi dalam unit pi'); ylabel('Hr(k)')
set(gca,'color',[0,0,0]);

%Menampilkan respon impuls
axes(handles.axes8);
stem(l,h,'color','r');
axis([-1,M,-0.1,0.4]); title('Respon impuls')
xlabel('frekuensi dalam unit pi'); ylabel('h(n)')
set(gca,'color',[0,0,0]);

%Menampilkan respon amplitudo
axes(handles.axes9);
plot(ww/pi, Hr, w1(1:M/2)/pi, Hrs(1:M/2), 'o','color','r');
axis([0,1,-0.2,1.2]); title('Respon amplitudo')
xlabel('frekuensi dalam unit pi'); ylabel('Hr(w)')
set(gca,'color',[0,0,0]);

%Menampilkan magnitudo dalam dB
axes(handles.axes3);
plot(w/pi, db,'color','r', 'LineWidth' ,2);
axis([0,1,-90,10]); title('Respon magnitudo')
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 lowpass
lowpass = h;

Berikut adalah kode sumber callback dari tombol Bandpass:

function Bandpass_Callback(hObject, eventdata, handles)
% hObject    handle to Bandpass (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((omega1p > omega1s)&&(omega2s > omega2p))
M=40; alpha=(M-1)/2; l=0:M-1; w1=(2*pi/M)*l;
T1=0.109021; T2=0.59417456;

%Membaca nilai slider
nilaiSlider = get(handles.slider1,'Value')

% Respon amplitudo ideal tercuplik
Hrs=[zeros(1,5-nilaiSlider),T1,T2,ones(1,7+nilaiSlider),T2,T1,zeros(1,9+nilaiSlider),T1,T2,ones(1,7-nilaiSlider),T2,T1,zeros(1,4)];

Hdr=[0,0,1,1,0,0]; wd1=[0,omega1s,omega1p,omega2p,omega2s,1]; % respon amplitudo ideal
k1=0:floor((M-1)/2); k2=floor((M-1)/2)+1:M-1;
angH=[-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H=Hrs.*exp(j*angH);
h=real(ifft(H,M));
[db,mag,pha,grd,w]=freqz_m(h,1);
[Hr,ww,a,L]=Hr_Tipe2(h);

%Menampilkan sampel-sampel frekuensi
axes(handles.axes7);
plot(w1(1:M/2)/pi, Hrs(1:M/2), 'o', wd1, Hdr,'color','r');
axis([0,1,-0.1,1.1]); title('Sampel-sampel frekuensi: M=60')
xlabel('frekuensi dalam unit pi'); ylabel('Hr(k)')
set(gca,'color',[0,0,0]);

%Menampilkan respon impuls
axes(handles.axes8);
stem(l,h,'color','r');
axis([-1,M,-0.1,0.4]); title('Respon impuls')
xlabel('frekuensi dalam unit pi'); ylabel('h(n)')
set(gca,'color',[0,0,0]);

%Menampilkan respon amplitudo
axes(handles.axes9);
plot(ww/pi, Hr, w1(1:M/2)/pi, Hrs(1:M/2), 'o','color','r');
axis([0,1,-0.2,1.2]); title('Respon amplitudo')
xlabel('frekuensi dalam unit pi'); ylabel('Hr(w)')
set(gca,'color',[0,0,0]);

%Menampilkan magnitudo dalam dB
axes(handles.axes3);
plot(w/pi, db,'color','r', 'LineWidth' ,2);
axis([0,1,-90,10]); title('Respon magnitudo')
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('Omega1p Harus Lebih Besar dari Omega1s dan Omega2s Harus Lebih Besar dari Omega2p');
end

%Menyimpan data global
global bandpass

bandpass = h;

Berikut adalah kode sumber callback dari tombol Bandstop:

function Bandstop_Callback(hObject, eventdata, handles)
% hObject    handle to Bandstop (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'));

if((omega1s > omega1p)&&(omega2p > omega2s))
M=40; alpha=(M-1)/2; l=0:M-1; w1=(2*pi/M)*l;
T1=0.109021; T2=0.59417456;

%Membaca nilai slider
nilaiSlider = get(handles.slider1,'Value')

% Respon amplitudo ideal tercuplik
Hrs=[ones(1,5-nilaiSlider),T2,T1,zeros(1,7+nilaiSlider),T1,T2,ones(1,9+nilaiSlider),T2,T1,zeros(1,7-nilaiSlider),T1,T2,ones(1,4)];

% respon amplitudo ideal
Hdr=[1,1,0,0,1,1]; wd1=[0,omega1p,omega1s,omega2s,omega2p,1]; 

k1=0:floor((M-1)/2); k2=floor((M-1)/2)+1:M-1;
angH=[-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H=Hrs.*exp(j*angH);
h=real(ifft(H,M));
[db,mag,pha,grd,w]=freqz_m(h,1);
[Hr,ww,a,L]=Hr_Tipe2(h);

%Menampilkan sampel-sampel frekuensi
axes(handles.axes7);
plot(w1(1:M/2)/pi, Hrs(1:M/2), 'o', wd1, Hdr,'color','r');
axis([0,1,-0.1,1.1]); title('Sampel-sampel frekuensi: M=60')
xlabel('frekuensi dalam unit pi'); ylabel('Hr(k)')
set(gca,'color',[0,0,0]);

%Menampilkan respon impuls
axes(handles.axes8);
stem(l,h,'color','r');
axis([-1,M,-0.1,0.4]); title('Respon impuls')
xlabel('frekuensi dalam unit pi'); ylabel('h(n)')
set(gca,'color',[0,0,0]);

%Menampilkan respon amplitudo
axes(handles.axes9);
plot(ww/pi, Hr, w1(1:M/2)/pi, Hrs(1:M/2), 'o','color','r');
axis([0,1,-0.2,1.2]); title('Respon amplitudo')
xlabel('frekuensi dalam unit pi'); ylabel('Hr(w)')
set(gca,'color',[0,0,0]);

%Menampilkan magnitudo dalam dB
axes(handles.axes3);
plot(w/pi, db,'color','r', 'LineWidth' ,2);
axis([0,1,-90,10]); title('Respon magnitudo')
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 dan Omega2p Harus Lebih Besar dari Omega2s');
end

%Menyimpan data global
global bandstop

bandstop = h;

Berikut adalah kode sumber callback dari tombol Highpass:

function Highpass_Callback(hObject, eventdata, handles)
% hObject    handle to Highpass (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(omega2s > omega2p)
M=60; alpha=(M-1)/2; l=0:M-1; w1=(2*pi/M)*l;

%Membaca nilai slider
nilaiSlider = get(handles.slider1,'Value');

M=33; alpha=(M-1)/2; l=0:M-1; w1=(2*pi/M)*l;
T1=0.1095; T2=0.598;

% Respon amplitudo ideal tercuplik
Hrs=[zeros(1,11-nilaiSlider),T1,T2,ones(1,8+nilaiSlider),T2,T1,zeros(1,10)];

% respon amplitudo ideal
Hdr=[0,0,1,1]; wd1=[0,0.6,0.8,1];
k1=0:floor((M-1)/2); k2=floor((M-1)/2)+1:M-1;
angH=[-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H=Hrs.*exp(j*angH);

%Respon aktual
h=real(ifft(H,M));
[db,mag,pha,grd,w]=freqz_m(h,1);
[Hr,ww,a,L]=Hr_Tipe1(h);

%Menampilkan sampel-sampel frekuensi
axes(handles.axes7);
plot(w1(1:M/2)/pi, Hrs(1:M/2), 'o', wd1/2, Hdr,'color','r');
axis([0,1,-0.1,1.1]); title('Sampel-sampel frekuensi: M=60')
xlabel('frekuensi dalam unit pi'); ylabel('Hr(k)')
set(gca,'color',[0,0,0]);

%Menampilkan respon impuls
axes(handles.axes8);
stem(l,h,'color','r');
axis([-1,M,-0.1,0.4]); title('Respon impuls')
xlabel('frekuensi dalam unit pi'); ylabel('h(n)')
set(gca,'color',[0,0,0]);

%Menampilkan respon amplitudo
axes(handles.axes9);
plot(ww/pi, Hr, w1(1:M/2)/pi, Hrs(1:M/2), 'o','color','r');
axis([0,1,-0.2,1.2]); title('Respon amplitudo')
xlabel('frekuensi dalam unit pi'); ylabel('Hr(w)')
set(gca,'color',[0,0,0]);

%Menampilkan magnitudo dalam dB
axes(handles.axes3);
plot(w/pi, db,'color','r', 'LineWidth' ,2);
axis([0,1,-90,10]); title('Respon magnitudo')
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('Omega2s Harus Lebih Besar dari Omega2p');
end

%Menyimpan data global
global highpass

highpass = h;





No comments: