function varargout = firrec(varargin)

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @firrec_OpeningFcn, ...
                   'gui_OutputFcn',  @firrec_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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

function firrec_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = firrec_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;

function edit1_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function edit1_Callback(hObject, eventdata, handles)
 N = str2num(get(hObject, 'String'));
data = getappdata(gcbf, 'UserData');
data.N = N;
setappdata(gcbf, 'UserData', data);

function edit2_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function edit2_Callback(hObject, eventdata, handles)
cf = str2num(get(hObject, 'String'));
 if(( cf > 1) | (cf < 0))
    set(hObject, 'String', 0);
    errordlg('cutoff frequency must be between 0 and 1','Error ');
end
data = getappdata(gcbf, 'UserData');
data.cf = cf;
setappdata(gcbf, 'UserData', data);

function pushbutton1_Callback(hObject, eventdata, handles)
data = getappdata(gcbf, 'UserData');
w=ones(1,data.N+1);	%Rectangular window
b = fir1(data.N,data.cf,w)
freqz(b,1,1024);
xlabel('Normalized frequency');
ylabel('Gain, dB');

function listbox1_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function listbox1_Callback(hObject, eventdata, handles)

function pushbutton2_Callback(hObject, eventdata, handles)
data = getappdata(gcbf, 'UserData');
w=ones(1,data.N+1);	%Rectangular window
b = fir1(data.N,data.cf,w)
set(handles.listbox1, 'String', b);

