Friday, May 19, 2017

Cara Membuat GUI MATLAB Untuk DASAR SINYAL DAN SISTEM DISKRET UNTUK LABORATORIUM PEMROSESAN SINYAL DIGITAL

Anda bisa mengunduh kode sumber GUI MATLAB di sini:

https://www.4shared.com/rar/lqmwEjT2ca/Sinusoidal.html




















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

% Last Modified by GUIDE v2.5 19-May-2017 22:10:08

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = tipe_runtun_diskret_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%Menetapkan n0=1
set(handles.n0,'string',1);

% Membaca n0, n1, dan n2
n0 = str2num(get(handles.n0,'String'));
n1 = str2num(get(handles.n1,'String'));
n2 = str2num(get(handles.n2,'String'));
eksp = str2num(get(handles.eksp,'String'));

%Membaca parameter-parameter sinusoidal
A = str2num(get(handles.A,'String'));
Frek = str2num(get(handles.Frek,'String'));
Fase = str2num(get(handles.Fase,'String'));
Fs = str2num(get(handles.Fs,'String'));

%Memilih pilihan dari menu popup
switch get(handles.popupmenu1,'Value')
    case 1
       n = [n1:n2]; x = [(n-n0) == 0];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Impulse Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Impulse Diskret');
          pause(0.1);
       end
    case 2
       n = [n1:n2]; x = [(n-n0) >= 0];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Tangga Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Tangga Diskret');
          pause(0.1)
       end
     
    case 3
       n = [n1:n2]; x = [(n-n0) >= 0].*[(eksp).^(n-n0)];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Eksponensial Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Eksponensial Diskret');
          pause(0.1)
       end
     
    case 4
       n = [n1:n2]; x = [(n-n0) >= 0].*[A*sin(2*pi*(Frek)*((n-n0)/Fs)+Fase)];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Sinusoidal Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Sinusoidal Diskret');
          pause(0.1)
       end
     
    case 5
       n = [n1:n2]; x = [(n-n0) >= 0].*(rand(1,(n2-n1+1))-0.5);
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Acak Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Acak Diskret');
          pause(0.1)
       end

%Menetapkan n0=1
set(handles.n0,'string',1);
end



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


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


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


% --- Executes during object creation, after setting all properties.
function n2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to n2 (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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


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



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


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


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


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


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


% --- Executes during object creation, after setting all properties.
function Fs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Fs (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global n0;
global n1;
global x;
% Membaca n0, n1, dan n2
n0 = str2num(get(handles.n0,'String'));
n1 = str2num(get(handles.n1,'String'));
n2 = str2num(get(handles.n2,'String'));
eksp = str2num(get(handles.eksp,'String'));

%Membaca parameter-parameter sinusoidal
A = str2num(get(handles.A,'String'));
Frek = str2num(get(handles.Frek,'String'));
Fase = str2num(get(handles.Fase,'String'));
Fs = str2num(get(handles.Fs,'String'));

%Memilih pilihan dari menu popup
switch get(handles.popupmenu1,'Value')
    case 1
       n = [n1:n2]; x = [(n-n0) == 0];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Impulse Diskret');

    case 2
       n = [n1:n2]; x = [(n-n0) >= 0];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Tangga Diskret');
     
    case 3
       n = [n1:n2]; x = [(n-n0) >= 0].*[(eksp).^(n-n0)];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Eksponensial Diskret');
     
    case 4
       n = [n1:n2]; x = [(n-n0) >= 0].*[A*sin(2*pi*(Frek)*((n-n0)/Fs)+Fase)];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Sinusoidal Diskret');
     
    case 5
       n = [n1:n2]; x = [(n-n0) >= 0].*(rand(1,(n2-n1+1))-0.5);
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Acak Diskret');

end


% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton1
global x;

status_tombol = get(hObject,'Value')
if status_tombol == get(hObject,'Max')
set(handles.togglebutton1,'String','HENTIKAN');
elseif status_tombol == get(hObject,'Min')
set(handles.togglebutton1,'String','ANIMASIKAN');
end


% Membaca n0, n1, dan n2
n0 = str2num(get(handles.n0,'String'));
n1 = str2num(get(handles.n1,'String'));
n2 = str2num(get(handles.n2,'String'));
eksp = str2num(get(handles.eksp,'String'));

%Membaca parameter-parameter sinusoidal
A = str2num(get(handles.A,'String'));
Frek = str2num(get(handles.Frek,'String'));
Fase = str2num(get(handles.Fase,'String'));
Fs = str2num(get(handles.Fs,'String'));

%Memilih pilihan dari menu popup
switch get(handles.popupmenu1,'Value')
    case 1
       n = [n1:n2]; x = [(n-n0) == 0];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Impulse Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          status_tombol = get(hObject,'Value');
          if (~status_tombol)
             break;
          end
       
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Impulse Diskret');
          pause(0.1);
       end
       status_tombol = 0;
       set(handles.togglebutton1,'String','ANIMASIKAN');
           
    case 2
       n = [n1:n2]; x = [(n-n0) >= 0];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Tangga Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Tangga Diskret');
          pause(0.1)
       end
       status_tombol = 0;
       set(handles.togglebutton1,'String','ANIMASIKAN');
     
    case 3
       n = [n1:n2]; x = [(n-n0) >= 0].*[(eksp).^(n-n0)];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Eksponensial Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Eksponensial Diskret');
          pause(0.1)
       end
       status_tombol = 0;
       set(handles.togglebutton1,'String','ANIMASIKAN');
     
    case 4
       n = [n1:n2]; x = [(n-n0) >= 0].*[A*sin(2*pi*(Frek)*((n-n0)/Fs)+Fase)];
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Sinusoidal Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Sinusoidal Diskret');
          pause(0.1)
       end
       status_tombol = 0;
       set(handles.togglebutton1,'String','ANIMASIKAN');
     
    case 5
       n = [n1:n2]; x = [(n-n0) >= 0].*(rand(1,(n2-n1+1))-0.5);
       %Menampilkan grafik
       axes(handles.axes1)
       stem(n,x); title('Runtun Acak Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x =circshift(x',1);
          x=x';
          if (geser <= (n2-n0))
             set(handles.n0,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes1)
          stem(n,x); title('Runtun Acak Diskret');
          pause(0.1)
       end
       status_tombol = 0;
       set(handles.togglebutton1,'String','ANIMASIKAN');

%Menetapkan n0 = 0
%set(handles.n0,'string',0);

end


% --- Executes on button press in togglebutton2.
function togglebutton2_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton2
global x1;
status_tombol = get(hObject,'Value')
if status_tombol == get(hObject,'Max')
set(handles.togglebutton2,'String','HENTIKAN');
elseif status_tombol == get(hObject,'Min')
set(handles.togglebutton2,'String','ANIMASIKAN');
end


% Membaca n0, n1, dan n2
n0 = str2num(get(handles.n01,'String'));
n1 = str2num(get(handles.n11,'String'));
n2 = str2num(get(handles.n21,'String'));
eksp = str2num(get(handles.eksp1,'String'));

%Membaca parameter-parameter sinusoidal
A = str2num(get(handles.A1,'String'));
Frek = str2num(get(handles.Frek1,'String'));
Fase = str2num(get(handles.Fase1,'String'));
Fs = str2num(get(handles.Fs1,'String'));

%Memilih pilihan dari menu popup
switch get(handles.popupmenu2,'Value')
    case 1
       n = [n1:n2]; x1 = [(n-n0) == 0];
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Impulse Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x1 =circshift(x1',1);
          x1=x1';
          status_tombol = get(hObject,'Value');
          if (~status_tombol)
             break;
          end
       
          if (geser <= (n2-n0))
             set(handles.n01,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes2)
          stem(n,x1); title('Runtun Impulse Diskret');
          pause(0.1);
       end
       status_tombol = 0;
       set(handles.togglebutton2,'String','ANIMASIKAN');
           
    case 2
       n = [n1:n2]; x1 = [(n-n0) >= 0];
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Tangga Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x1 =circshift(x1',1);
          x1=x1';
          if (geser <= (n2-n0))
             set(handles.n01,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes2)
          stem(n,x1); title('Runtun Tangga Diskret');
          pause(0.1)
       end
       status_tombol = 0;
       set(handles.togglebutton2,'String','ANIMASIKAN');
     
    case 3
       n = [n1:n2]; x1 = [(n-n0) >= 0].*[(eksp).^(n-n0)];
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Eksponensial Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x1 =circshift(x1',1);
          x1=x1';
          if (geser <= (n2-n0))
             set(handles.n01,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes2)
          stem(n,x1); title('Runtun Eksponensial Diskret');
          pause(0.1)
       end
       status_tombol = 0;
       set(handles.togglebutton2,'String','ANIMASIKAN');
     
    case 4
       n = [n1:n2]; x1 = [(n-n0) >= 0].*[A*sin(2*pi*(Frek)*((n-n0)/Fs)+Fase)];
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Sinusoidal Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x1 =circshift(x1',1);
          x1=x1';
          if (geser <= (n2-n0))
             set(handles.n01,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes2)
          stem(n,x1); title('Runtun Sinusoidal Diskret');
          pause(0.1)
       end
       status_tombol = 0;
       set(handles.togglebutton2,'String','ANIMASIKAN');
     
    case 5
       n = [n1:n2]; x1 = [(n-n0) >= 0].*(rand(1,(n2-n1+1))-0.5);
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Acak Diskret');
     
       %Animasi
       for geser = 1:(n2-n1)
          x1 =circshift(x1',1);
          x1=x1';
          if (geser <= (n2-n0))
             set(handles.n01,'string',(n0+geser));
          end
          if (geser > (n2-n0))
             break;
             %set(handles.n0,'string',(geser-(n2-n1)));
          end
          axes(handles.axes2)
          stem(n,x1); title('Runtun Acak Diskret');
          pause(0.1)
       end
       status_tombol = 0;
       set(handles.togglebutton2,'String','ANIMASIKAN');

%Menetapkan n0 = 0
%set(handles.n0,'string',0);

end


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global x1;

% Membaca n0, n1, dan n2
n0 = str2num(get(handles.n01,'String'));
n1 = str2num(get(handles.n11,'String'));
n2 = str2num(get(handles.n21,'String'));
eksp = str2num(get(handles.eksp1,'String'));

%Membaca parameter-parameter sinusoidal
A = str2num(get(handles.A1,'String'));
Frek = str2num(get(handles.Frek1,'String'));
Fase = str2num(get(handles.Fase1,'String'));
Fs = str2num(get(handles.Fs1,'String'));

%Memilih pilihan dari menu popup
switch get(handles.popupmenu2,'Value')
    case 1
       n = [n1:n2]; x1 = [(n-n0) == 0];
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Impulse Diskret');

    case 2
       n = [n1:n2]; x1 = [(n-n0) >= 0];
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Tangga Diskret');
     
    case 3
       n = [n1:n2]; x1 = [(n-n0) >= 0].*[(eksp).^(n-n0)];
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Eksponensial Diskret');
     
    case 4
       n = [n1:n2]; x1 = [(n-n0) >= 0].*[A*sin(2*pi*(Frek)*((n-n0)/Fs)+Fase)];
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Sinusoidal Diskret');
     
    case 5
       n = [n1:n2]; x1 = [(n-n0) >= 0].*(rand(1,(n2-n1+1))-0.5);
       %Menampilkan grafik
       axes(handles.axes2)
       stem(n,x1); title('Runtun Acak Diskret');

end


% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2


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



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


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


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


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


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


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


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


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


% --- Executes during object creation, after setting all properties.
function n01_CreateFcn(hObject, eventdata, handles)
% hObject    handle to n01 (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 pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global x;
global x1;

% Membaca n0, n1, dan n2 untuk sinyal 1
n0 = str2num(get(handles.n0,'String'));
n1 = str2num(get(handles.n1,'String'));
n2 = str2num(get(handles.n2,'String'));
eksp = str2num(get(handles.eksp,'String'));

%Membaca parameter-parameter sinusoidal untuk sinyal 1
A = str2num(get(handles.A,'String'));
Frek = str2num(get(handles.Frek,'String'));
Fase = str2num(get(handles.Fase,'String'));
Fs = str2num(get(handles.Fs,'String'));

% Membaca n0, n1, dan n2
n01 = str2num(get(handles.n01,'String'));
n11 = str2num(get(handles.n11,'String'));
n21 = str2num(get(handles.n21,'String'));
eksp1 = str2num(get(handles.eksp1,'String'));

%Membaca parameter-parameter sinusoidal
A1 = str2num(get(handles.A1,'String'));
Frek1 = str2num(get(handles.Frek1,'String'));
Fase1 = str2num(get(handles.Fase1,'String'));
Fs1 = str2num(get(handles.Fs1,'String'));
   
n = min(min(n1),min(n11)):max(max(n2),max(n21)); % durasi dari y(n)
y1 = zeros(1,length(n)); y2 = y1; % inisialisasi
y1(find((n>=min(n1))&(n<=max(n2))==1))=x; % x1 dengan durasi y
y2(find((n>=min(n11))&(n<=max(n21))==1))=x1; % x2 dengan durasi y
y = y1+y2; % runtun penjumlahan

axes(handles.axes3)
stem(n,y); title('Runtun Penjumlahan');


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global x;
global x1;

% Membaca n0, n1, dan n2 untuk sinyal 1
n0 = str2num(get(handles.n0,'String'));
n1 = str2num(get(handles.n1,'String'));
n2 = str2num(get(handles.n2,'String'));
eksp = str2num(get(handles.eksp,'String'));

%Membaca parameter-parameter sinusoidal untuk sinyal 1
A = str2num(get(handles.A,'String'));
Frek = str2num(get(handles.Frek,'String'));
Fase = str2num(get(handles.Fase,'String'));
Fs = str2num(get(handles.Fs,'String'));

% Membaca n0, n1, dan n2
n01 = str2num(get(handles.n01,'String'));
n11 = str2num(get(handles.n11,'String'));
n21 = str2num(get(handles.n21,'String'));
eksp1 = str2num(get(handles.eksp1,'String'));

%Membaca parameter-parameter sinusoidal
A1 = str2num(get(handles.A1,'String'));
Frek1 = str2num(get(handles.Frek1,'String'));
Fase1 = str2num(get(handles.Fase1,'String'));
Fs1 = str2num(get(handles.Fs1,'String'));
   
n = min(min(n1),min(n11)):max(max(n2),max(n21)); % durasi dari y(n)
y1 = zeros(1,length(n)); y2 = y1; % inisialisasi
y1(find((n>=min(n1))&(n<=max(n2))==1))=x; % x1 dengan durasi y
y2(find((n>=min(n11))&(n<=max(n21))==1))=x1; % x2 dengan durasi y
y = y1.*y2; % runtun perkalian

axes(handles.axes3)
stem(n,y); title('Runtun Perkalian');


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global x;
global x1;

% Membaca n0, n1, dan n2 untuk sinyal 1
n0 = str2num(get(handles.n0,'String'));
n1 = str2num(get(handles.n1,'String'));
n2 = str2num(get(handles.n2,'String'));
eksp = str2num(get(handles.eksp,'String'));

%Membaca parameter-parameter sinusoidal untuk sinyal 1
A = str2num(get(handles.A,'String'));
Frek = str2num(get(handles.Frek,'String'));
Fase = str2num(get(handles.Fase,'String'));
Fs = str2num(get(handles.Fs,'String'));

% Membaca n0, n1, dan n2
n01 = str2num(get(handles.n01,'String'));
n11 = str2num(get(handles.n11,'String'));
n21 = str2num(get(handles.n21,'String'));
eksp1 = str2num(get(handles.eksp1,'String'));

%Membaca parameter-parameter sinusoidal
A1 = str2num(get(handles.A1,'String'));
Frek1 = str2num(get(handles.Frek1,'String'));
Fase1 = str2num(get(handles.Fase1,'String'));
Fs1 = str2num(get(handles.Fs1,'String'));
   
n = min(min(n1),min(n11)):max(max(n2),max(n21)); % durasi dari y(n)
y1 = zeros(1,length(n)); y2 = y1; % inisialisasi
y1(find((n>=min(n1))&(n<=max(n2))==1))=x; % x1 dengan durasi y
y2(find((n>=min(n11))&(n<=max(n21))==1))=x1; % x2 dengan durasi y
y = y1-y2; % runtun pengurangan

axes(handles.axes3)
stem(n,y); title('Runtun Pengurangan');


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global x;
global x1;

% Membaca n0, n1, dan n2 untuk sinyal 1
n0 = str2num(get(handles.n0,'String'));
n1 = str2num(get(handles.n1,'String'));
n2 = str2num(get(handles.n2,'String'));
eksp = str2num(get(handles.eksp,'String'));

%Membaca parameter-parameter sinusoidal untuk sinyal 1
A = str2num(get(handles.A,'String'));
Frek = str2num(get(handles.Frek,'String'));
Fase = str2num(get(handles.Fase,'String'));
Fs = str2num(get(handles.Fs,'String'));

% Membaca n0, n1, dan n2
n01 = str2num(get(handles.n01,'String'));
n11 = str2num(get(handles.n11,'String'));
n21 = str2num(get(handles.n21,'String'));
eksp1 = str2num(get(handles.eksp1,'String'));

%Membaca parameter-parameter sinusoidal
A1 = str2num(get(handles.A1,'String'));
Frek1 = str2num(get(handles.Frek1,'String'));
Fase1 = str2num(get(handles.Fase1,'String'));
Fs1 = str2num(get(handles.Fs1,'String'));
   
%nyb = n1+n11; nye = length(x) + length(x1);
%ny = [nyb:nye];
n_bawah = n1+n11;
batasatas = length(x) + length(x1);
%n_atas=batasatas+batasatas-1;
ny=n_bawah:batasatas-(abs(n_bawah)+2);
length(ny)

y = conv(double(x),double(x1)); % runtun konvolusi

length(y)
axes(handles.axes3)
stem(ny,y); title('Runtun Hasil Konvolusi');



No comments: