Signal & System_Midterm Project

Function Introduction:
This is the Music_Controller I mad.
If you control these two sliders, you can control its volume and speed.
And if you check these two check boxes, it will change to compare mode and reverse mode.
In compare mode, you can see two or more wave view overlap together.
In reverse mode, you can find the wave view is the reverse of general type.
Final Video:

Midterm Project


Print Screen:
    -Normal Type

    -From End Mode

    -Compare Type


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

% Last Modified by GUIDE v2.5 03-May-2017 03:51:32

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = Midterm_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)
clear sound;
if get(handles.checkbox2,'value')==1
    hold on;
end
if get(handles.checkbox2,'value')==0
    cla(handles.axes1,'reset');
end
melody_matching=get(handles.popupmenu1,'Value');
switch melody_matching
    case 1
       melody_matching = '卡農';
       [y,hz]= audioread('C:\Users\user\Desktop\卡農.mp3');   % read the song's frequency
       if get(handles.checkbox,'value')==1
           y=flipud(y);
       end
       sound(y*get(handles.slider1, 'Value'), hz*get(handles.slider2, 'Value'));                            % broadcast music
       time = (1 : length(y) ) / hz;       % Setting X axis is time
       plot(handles.axes1,time/get(handles.slider2, 'Value'),y*get(handles.slider1, 'Value'),'r');  %  print wave picture with graduation 
    case 2
       melody_matching = 'Written In The Stars';
       [y,hz] = audioread('C:\Users\user\Desktop\Written In The Stars.mp3');
       if get(handles.checkbox,'value')==1
           y=flipud(y);
       end
       sound(y*get(handles.slider1, 'Value'),hz*get(handles.slider2, 'Value'));             
       time = (1 : length(y) ) / hz;
       plot(handles.axes1,time/get(handles.slider2, 'Value'),y*get(handles.slider1, 'Value'),'b');                    % print curve picture 'b' can change wave color
    case 3
       melody_matching = 'G';
       [y,hz] = audioread('C:\Users\user\Desktop\G.mp3');
       if get(handles.checkbox,'value')==1
           y=flipud(y);
       end
       time = (1 : length(y) ) / hz;
       sound(y*get(handles.slider1, 'Value'), hz*get(handles.slider2, 'Value'));  
       plot(handles.axes1,time/get(handles.slider2, 'Value'),y*get(handles.slider1, 'Value'),'m');
end
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton1.
function pushbutton2_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)
clear sound;


% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (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 listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1


% --- 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


% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes1


% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
slider_value1 = get(handles.slider1, 'Value');
set(handles.text3,'String',slider_value1);
%handles.player = audioplayer(y, 10000*get(handles.slider1, 'Value'));
% hObject    handle to slider1 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



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


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 during object creation, after setting all properties.
function text3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes on mouse press over figure background.
function figure1_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox2 (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 checkbox2


% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
slider_value2 = get(handles.slider2, 'Value');
set(handles.text8,'String',slider_value2);
% hObject    handle to slider2 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on button press in checkbox.
function checkbox_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox (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 checkbox

Ć
G.mp3
(4490k)
Yuanster Hsu,
May 3, 2017, 2:12 AM
ċ
Midterm.fig
(30k)
Yuanster Hsu,
May 3, 2017, 2:12 AM
ċ
Midterm.m
(11k)
Yuanster Hsu,
May 3, 2017, 2:12 AM
Ć
Written In The Stars.mp3
(5073k)
Yuanster Hsu,
May 3, 2017, 2:12 AM
Ć
卡農.mp3
(5553k)
Yuanster Hsu,
May 3, 2017, 2:12 AM
Comments