function varargout = sampling(varargin) % SAMPLING Application M-file for sampling.fig % FIG = SAMPLING launch sampling GUI. % SAMPLING('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 12-May-2004 04:40:58 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'new'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); set(fig, 'Name', 'Sampling Demonstration'); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); runinter(handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end % -------------------------------------------------------------------- function varargout = Interpol_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.Interpol. %disp('Interpol Callback not implemented yet.') runinter(handles); % -------------------------------------------------------------------- function varargout = editN_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.editN. %disp('editN Callback not implemented yet.') runinter(handles); % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. %disp('pushbutton1 Callback not implemented yet.') runinter(handles); function runinter(handles) m = 2^11; x = m*real(ifft([randn(1, 20), zeros(1, m - 20)])); N = str2num(get(handles.editN, 'String')); % The sampling rate meth = get(handles.Interpol, 'Value'); switch get(handles.Interpol, 'Value') case {1, 3} h = [zeros(1, 10*N), ones(1, N)]; case 4 h = [zeros(1, 10*N-N+1), [1:N, N-1:-1:0]/N]; case 2 h = sin(pi*(-10*N:10*N)/N+1e-9)./(pi.*(-10*N:10*N)/N+1e-9); otherwise disp('Wrong option') end ii = floor(N/2):N:m; set(handles.axesdata, 'Nextplot', 'Replace') plot(1:m, x, 'Parent', handles.axesdata); set(handles.axesdata, 'Xlim', [0, m]); set(handles.axesdata, 'Nextplot', 'Add'); plot(ii, x(ii), 'or', 'Parent', handles.axesdata); x1 = zeros(size(x)); x1(ii) = x(ii); x2 = conv(h, x1); xi = x2((10*N+1):(10*N+m)); plot(1:m, xi, 'r', 'Parent', handles.axesdata) set(handles.axeserr, 'Nextplot', 'Replace') plot(1:m, xi - x, 'Parent', handles.axeserr) set(handles.axeserr, 'Xlim', [0, m]); %set(handles.axeserr, 'Nextplot', 'Add') %plot(ii, zeros(size(ii)), 'or', 'Parent', handles.axeserr) set(handles.axeserr, 'Ylim', get(handles.axesdata, 'Ylim')); %plot(1:m, xi, 1:m, x, ii, x(ii), 'o')