This document contains MATLAB code for a GUI called untitled1. It includes initialization code to create the GUI, as well as callback functions for different GUI components like pop-up menus and buttons. The callback functions implement various signal processing tasks like plotting continuous and discrete time signals, convolution, Fourier series, and Fourier transforms.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
28 views6 pages
CODE
This document contains MATLAB code for a GUI called untitled1. It includes initialization code to create the GUI, as well as callback functions for different GUI components like pop-up menus and buttons. The callback functions implement various signal processing tasks like plotting continuous and discrete time signals, convolution, Fourier series, and Fourier transforms.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6
function varargout = untitled1(varargin) % Default generate by GUI
% UNTITLED1 MATLAB code for untitled1.fig
% UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing % singleton*. % H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to % the existing singleton*. % UNTITLED1('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in UNTITLED1.M with the given input arguments. % UNTITLED1('Property','Value',...) creates a new UNTITLED1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before untitled1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to untitled1_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 untitled1 % Last Modified by GUIDE v2.5 27-May-2022 19:49:54 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; % Default generate by GUI gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled1_OpeningFcn, ... 'gui_OutputFcn', @untitled1_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 untitled1 is made visible. function untitled1_OpeningFcn(hObject, eventdata, handles, varargin) % Default generate by GUI % 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 untitled1 (see VARARGIN) % Choose default command line output for untitled1 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes untitled1 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = untitled1_OutputFcn(hObject, eventdata, handles) % Default generate by GUI % 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 selection change in mean. function mean_Callback(hObject, eventdata, handles) % We use this for the different required functions % hObject handle to mean (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 mean contents as cell array % contents{get(hObject,'Value')} returns selected item from mean val=get(handles.mean,'value'); switch(val) % Second case for continuous case 2 a=get(handles.edit5,'string'); % For display t=0:0.01:10; % Time interval x=0:0.01:10; axes(handles.axes3) % For Showing plot(eval(a)) % For plot axis([-5 length(t) -2 2]) % By giving x and y-axis title('continuous Time Signal') % By writing Title xlabel('t(x)') % By labeling x-axis ylabel('y(x)') % By labeling y-axis grid on % For displaying lines case 3 % Third case for discrete b=get(handles.edit5,'string'); % For display n=0:1:50; t=0:1:10; % Time interval axes(handles.axes3) % For Showing stem(eval(b)) % For plot axis([-5 length(n) -2 2]) axis([-5 length(t) -2 2]) title('Discrete Time Signal') % By writing Title xlabel('t(x)') % By labeling x-axis ylabel('y(x)') % By labeling y-axis grid on % For displaying lines case 4 % Fourth case for convolution t=0:0.5:10; y=0:0.5:10; h = get(handles.edit4,'string'); % For display n = get(handles.edit5,'string'); % For display axes(handles.axes1) % For showing plot(eval(n)); % For plot hold on axis([-5 length(t) -2 2]) % By giving x and y-axis plot(eval(h)); % For plot axis([-5 length(t) -2 2]) % By giving x and y-axis title('Original Signals') % By writing Title xlabel('t(x)') % By labeling x-axis ylabel('y(t)') % By labeling y-axis hold on grid on % For displaying lines b = conv(eval(n),eval(h)); % For convoluution n1=1:length(b); axes(handles.axes3) % For showing plot(n1,b); % For plot hold on title('Convolution Signal') % By writing Title xlabel('t(x)') % By labeling x-axis ylabel('x(t)*h(t)') % By labeling y-axis grid on % For displaying lines case 5 % Fifth case for Fourier Series a=get(handles.edit5,'string'); % For display a=str2num(a) t=-5:0.01:5; % For Time Interval axes(handles.axes1) % For showing s = square(2*pi*t,50); % Function for square wave wO = 2*pi; % Frequency plot(t,s,'b','Linewidth',2) % Plotting original square wave grid on % By showing lines on the graph title('Original Square Wave') % By writing Title axis([-5 5 -2 2]) % By specifying x and y axis K = [a]; for N = 1:length(K) % By starting from 1 and ranges to K k = 1:2:K(N); x = (4./(pi*k)) * sin(wO*k'*t); % BY Default giving function axes(handles.axes3) % For showing plot(t,s,'k','Linewidth',2) % For plot hold on % For delay axes(handles.axes3) % For showing plot(t,x,'m','Linewidth',2) % For plot hold off % For no delay axis([-1 5 -2 2]) % By specifying x and y-axis grid on % By showing lines on the graph title(['Fourier Series representation with',... %title,number num2str(K(N)),' harmonics']); end case 6 % Sixth case for Fourier Transform %Fourier Transform syms t % By initializing variable x = (cos(t)).*heaviside(t); % By default giving function x_f = fourier(x) ; % By taking fourier axes(handles.axes1) % For showing ezplot(x) % For plot title('Original Signal') % By writing Title grid on xlabel('t') % By labeling x-axis ylabel('x(t)') % By labeling y-axis axes(handles.axes3) % By showing ezplot(abs(x_f)) % For plot title('Fourier Transform') % By writing Title grid on % By showing lines on graph xlabel('\omega') % By labeling x-axis ylabel('F(\omega)') % By labeling y-axis otherwise c='option invalid' end %set(handles.edit5,'string',c) % --- Executes during object creation, after setting all properties. function mean_CreateFcn(hObject, eventdata, handles) % Default generate for different functions % hObject handle to mean (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 % --- Executes on button press in discrete. function discrete_Callback(hObject, eventdata, handles) % For Continuous Function % hObject handle to discrete (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %discrete time b=get(handles.edit5,'string'); % For display b=get(handles.edit4,'string'); % For display n=0:1:50; t=0:1:50; axes(handles.axes3) % For showing stem(eval(b)) % For plot axis([-1 length(n) -2 2]) % By specifying x and y-axis axis([-1 length(t) -2 2]) title('Discrete Time Signal') % By writing title xlabel('t(x)') % By labeling x-axis ylabel('y(x)') % By labeling y-axis grid on % By showing lines on graph % --- Executes on button press in plot. function plot_Callback(hObject, eventdata, handles) % Function for plot % hObject handle to plot (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a=get(handles.edit4,'string'); % For display t=0:0.1:10; x=0:0.1:10; axes(handles.axes1) % For showing plot(eval(a)) % For plot title('Continuous Time Signal') % By writing title xlabel('t(x)') % By labeling X-axis ylabel('y(x)') % By labeling y-axis grid on %By showing lines on graph % Hint: get(hObject,'Value') returns toggle state of plot % --- Executes on button press in clear. function clear_Callback(hObject, eventdata, handles) % hObject handle to clear (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.edit4,'string',''); % For clearing input1 set(handles.edit5,'string',''); % For clearing input2 cla(handles.axes1); % For clearing axis1 cla(handles.axes3); % For clearing axis3 clear all % For clearing all clc % Hint: get(hObject,'Value') returns toggle state of clear % --- Executes on button press in compare. function compare_Callback(~, ~, ~) % For ON/OFF Function % hObject handle to compare (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all % Hint: get(hObject,'Value') returns toggle state of compare function edit4_Callback(hObject, eventdata, handles) % For INPUT 1 FUNCTION % hObject handle to edit4 (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 edit4 as text % str2double(get(hObject,'String')) returns contents of edit4 as a double % --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles) % For INPUT 1 FUNCTION % hObject handle to edit4 (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 edit5_Callback(hObject, eventdata, handles) % For INPUT 2 FUNCTION % hObject handle to edit5 (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 edit5 as text % str2double(get(hObject,'String')) returns contents of edit5 as a double % --- Executes during object creation, after setting all properties. function edit5_CreateFcn(hObject, eventdata, handles) % For INPUT 2 FUNCTION % hObject handle to edit5 (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 continuous. function continuous_Callback(hObject, eventdata, handles) % hObject handle to continuous (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %continuous time a=get(handles.edit5,'string'); % For display a=get(handles.edit4,'string'); t=0:0.01:10; y=0:0.01:10; axes(handles.axes3) % For showing plot(eval(a)) % For plot axis([-5 length(t) -2 2]) title('Continuous Time Signal') % By writing title xlabel('t(x)') % By labeling x-axis ylabel('y(x)') % By labeling y-axis grid on % By showing lines on graph % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over text6. function text6_ButtonDownFcn(hObject, eventdata, handles) % For label 1-INPUT % hObject handle to text6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function edit6_Callback(hObject, eventdata, handles) % For left border % hObject handle to edit6 (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 edit6 as text % str2double(get(hObject,'String')) returns contents of edit6 as a double % --- Executes during object creation, after setting all properties. function edit6_CreateFcn(hObject, eventdata, handles) % For left border % hObject handle to edit6 (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 edit7_Callback(hObject, eventdata, handles) % For right border % hObject handle to edit7 (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 edit7 as text % str2double(get(hObject,'String')) returns contents of edit7 as a double % --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles) % For right border % hObject handle to edit7 (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