Signal and Systems
410687003
MATLAB 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 16-May-2019 02:46:20
% 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);
a=get(handles.volume,'Value');
set(handles.text1,'String',num2str(a));
handles.a=a;
guidata(hObject,handles);
b=get(handles.fre,'Value');
set(handles.text2,'String',num2str(b));
handles.b=b;
guidata(hObject,handles);
backgroundImage =importdata('s1.jpg');
axes(handles.axes6);
image(backgroundImage);
axis off
% 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 slider movement.
function volume_Callback(hObject, eventdata, handles)
% hObject handle to volume (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.volume,'Value');
set(handles.text1,'String',num2str(a));
handles.a=a;
guidata(hObject,handles);
% 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 volume_CreateFcn(hObject, eventdata, handles)
% hObject handle to volume (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 slider movement.
function fre_Callback(hObject, eventdata, handles)
% hObject handle to fre (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
b=get(handles.fre,'Value');
set(handles.text2,'String',num2str(b));
handles.b=b;
guidata(hObject,handles);
% 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 fre_CreateFcn(hObject, eventdata, handles)
% hObject handle to fre (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 play.
function play_Callback(hObject, eventdata, handles)
% hObject handle to play (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
d=get(handles.random,'Value');
if(d==1)
c=unidrnd(3);
else
c=get(handles.list,'Value');
end
switch c
case 1
[y, fs]=audioread('secret base.mp3');
volume=(handles.b)*y;
freq=(handles.a)*fs;
sound(volume, freq);
time=(1:length(y))/freq;
plot(handles.axes1,time, volume);
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'magnititude');
N=length(y);
t=(0:N-1)/fs;
win = hanning(N); K = sum(win)/N; % coherent amplification of the window
X = abs(fft(y.*win)); % fast fourier transform
Xm = X(1:N/2); % getting a first half of the spectrum without Nyquist frequency at N/2+1
Xm = Xm/(N/2); % computing of the amplitudes
Xm(1,1) = Xm(1,1)/2; % correction of the DC component
Xm = Xm/K; % correction due to coherent amplification
f = (0:N/2-1)*fs/N;
plot(handles.axes2,f, Xm)
xlabel(handles.axes2,'frequency');
ylabel(handles.axes2,'magnititude');
set(handles.random,'String','random(OFF)');
backgroundImage =importdata('f.jpg');
axes(handles.axes3);
image(backgroundImage);
axis off
if(d==1)
set(handles.random,'String','random(ON):Secret Base(Anohana)');
d=0;
end
case 2
[y, fs]=audioread('wa.mp3');
volume=(handles.b)*y;
freq=(handles.a)*fs;
sound(volume, freq);
time=(1:length(y))/freq;
plot(handles.axes1,time, volume);
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'magnititude');
N=length(y);
t=(0:N-1)/fs;
win = hanning(N); K = sum(win)/N; % coherent amplification of the window
X = abs(fft(y.*win)); % fast fourier transform
Xm = X(1:N/2); % getting a first half of the spectrum without Nyquist frequency at N/2+1
Xm = Xm/(N/2); % computing of the amplitudes
Xm(1,1) = Xm(1,1)/2; % correction of the DC component
Xm = Xm/K; % correction due to coherent amplification
f = (0:N/2-1)*fs/N;
plot(handles.axes2,f, Xm)
xlabel(handles.axes2,'frequency');
ylabel(handles.axes2,'magnititude');
set(handles.random,'String','random(OFF)');
backgroundImage =importdata('wa1998.jpg');
axes(handles.axes3);
image(backgroundImage);
axis off
if(d==1)
set(handles.random,'String','random(ON):Yasashii Uso(WA2)');
d=0;
end
case 3
[y, fs]=audioread('Clannad.mp3');
volume=(handles.b)*y;
freq=(handles.a)*fs;
sound(volume, freq);
time=(1:length(y))/freq;
plot(handles.axes1,time, volume);
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'magnititude');
N=length(y);
t=(0:N-1)/fs;
win = hanning(N); K = sum(win)/N; % coherent amplification of the window
X = abs(fft(y.*win)); % fast fourier transform
Xm = X(1:N/2); % getting a first half of the spectrum without Nyquist frequency at N/2+1
Xm = Xm/(N/2); % computing of the amplitudes
Xm(1,1) = Xm(1,1)/2; % correction of the DC component
Xm = Xm/K; % correction due to coherent amplification
f = (0:N/2-1)*fs/N;
plot(handles.axes2,f, Xm)
xlabel(handles.axes2,'frequency');
ylabel(handles.axes2,'magnititude');
set(handles.random,'String','random(OFF)');
backgroundImage =importdata('c1.jpg');
axes(handles.axes5);
image(backgroundImage);
axis off
if(d==1)
set(handles.random,'String','random(ON):Megumeru(CLANNAD)');
d=0;
end
end
% --- Executes on button press in stop.
function stop_Callback(hObject, eventdata, handles)
% hObject handle to stop (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 button press in change.
% --- Executes on selection change in list.
function list_Callback(hObject, eventdata, handles)
% hObject handle to list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
c=get(handles.list,'Value');
handles.c=c;
guidata(hObject,handles);
% Hints: contents = cellstr(get(hObject,'String')) returns list contents as cell array
% contents{get(hObject,'Value')} returns selected item from list
% --- Executes during object creation, after setting all properties.
function list_CreateFcn(hObject, eventdata, handles)
% hObject handle to list (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 random.
function random_Callback(hObject, eventdata, handles)
% hObject handle to random (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
d=get(handles.random,'Value');
handles.d=d;
guidata(hObject,handles);
% --- Executes on button press in echo.
function echo_Callback(hObject, eventdata, handles)
% hObject handle to echo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
d=get(handles.random,'Value');
if(d==1)
c=unidrnd(3);
else
c=get(handles.list,'Value');
end
switch c
case 1
[y, fs]=audioread('secret base.mp3');
volume=(handles.b)*y;
freq=(handles.a)*fs;
N2=length(volume);
x1=volume(1:N2);
x2=volume(1:N2);
x1=[x1,zeros(1,5000)];
x2=[zeros(1,4000),0.4*x2,zeros(1,1000)];
volume=x1+x2;
sound(volume, freq);
time=(1:length(volume))/freq;
plot(handles.axes1,time, volume);
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'magnititude');
N=length(y);
t=(0:N-1)/fs;
win = hanning(N); K = sum(win)/N; % coherent amplification of the window
X = abs(fft(y.*win)); % fast fourier transform
Xm = X(1:N/2); % getting a first half of the spectrum without Nyquist frequency at N/2+1
Xm = Xm/(N/2); % computing of the amplitudes
Xm(1,1) = Xm(1,1)/2; % correction of the DC component
Xm = Xm/K; % correction due to coherent amplification
f = (0:N/2-1)*fs/N;
plot(handles.axes2,f, Xm)
xlabel(handles.axes2,'frequency');
ylabel(handles.axes2,'magnititude');
set(handles.random,'String','random(OFF)');
backgroundImage =importdata('f.jpg');
axes(handles.axes3);
image(backgroundImage);
axis off
if(d==1)
set(handles.random,'String','random(ON):Secret Base(Anohana)');
d=0;
end
case 2
[y, fs]=audioread('wa.mp3');
volume=(handles.b)*y;
freq=(handles.a)*fs;
N2=length(volume);
x1=volume(1:N2);
x2=volume(1:N2);
x1=[x1,zeros(1,5000)];
x2=[zeros(1,4000),0.4*x2,zeros(1,1000)];
volume=x1+x2;
sound(volume, freq);
time=(1:length(volume))/freq;
plot(handles.axes1,time, volume);
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'magnititude');
N=length(y);
t=(0:N-1)/fs;
win = hanning(N); K = sum(win)/N; % coherent amplification of the window
X = abs(fft(y.*win)); % fast fourier transform
Xm = X(1:N/2); % getting a first half of the spectrum without Nyquist frequency at N/2+1
Xm = Xm/(N/2); % computing of the amplitudes
Xm(1,1) = Xm(1,1)/2; % correction of the DC component
Xm = Xm/K; % correction due to coherent amplification
f = (0:N/2-1)*fs/N;
plot(handles.axes2,f, Xm)
xlabel(handles.axes2,'frequency');
ylabel(handles.axes2,'magnititude');
set(handles.random,'String','random(OFF)');
backgroundImage =importdata('wa1998.jpg');
axes(handles.axes3);
image(backgroundImage);
axis off
if(d==1)
set(handles.random,'String','random(ON):Yasashii Uso(WA2)');
d=0;
end
case 3
[y, fs]=audioread('Clannad.mp3');
volume=(handles.b)*y;
freq=(handles.a)*fs;
N2=length(volume);
x1=volume(1:N2);
x2=volume(1:N2);
x1=[x1,zeros(1,5000)];
x2=[zeros(1,4000),0.4*x2,zeros(1,1000)];
volume=x1+x2;
sound(volume, freq);
time=(1:length(volume))/freq;
plot(handles.axes1,time, volume);
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'magnititude');
N=length(y);
t=(0:N-1)/fs;
win = hanning(N); K = sum(win)/N; % coherent amplification of the window
X = abs(fft(y.*win)); % fast fourier transform
Xm = X(1:N/2); % getting a first half of the spectrum without Nyquist frequency at N/2+1
Xm = Xm/(N/2); % computing of the amplitudes
Xm(1,1) = Xm(1,1)/2; % correction of the DC component
Xm = Xm/K; % correction due to coherent amplification
f = (0:N/2-1)*fs/N;
plot(handles.axes2,f, Xm)
xlabel(handles.axes2,'frequency');
ylabel(handles.axes2,'magnititude');
set(handles.random,'String','random(OFF)');
backgroundImage =importdata('c1.jpg');
axes(handles.axes3);
image(backgroundImage);
axis off
if(d==1)
set(handles.random,'String','random(ON):Megumeru(CLANNAD)');
d=0;
end
end