Signal & System
Midterm Project
In this course , we learn what is Matlab and how to use it.
And understanding how to read sounds and transform it's wave.
For the midterm project , I choose four songs to analysis them.
Coldplay-the scientist
Earth,Wind&Fire-September
Jp Cooper-Birthday
Bruno Mars-24K Magic
Here is the music and it's wave and fourier transform.
This is my GUI panel,
Using GUI to make it easier to operate and observe the wave and frequency.
pop-up menu :Choose which music and the frequency.
Star bottom:Start the music and the wave.
Stop bottom:Stop the music
axes1:wave.
axes2:fourier wave.
Code
function varargout = MIDPANEL(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MIDPANEL_OpeningFcn, ...
'gui_OutputFcn', @MIDPANEL_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
function MIDPANEL_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = MIDPANEL_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function popupmenu1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pushbutton1_Callback(hObject, eventdata, handles)
numing = get(handles.popupmenu1,'Value') ;
switch numing
case 1
numing ='Coldplay - The Scientist';
[y, fs] = audioread('D:\Downloads\Coldplay - The Scientist.mp3'); % y會拿到音訊檔的所有點,fs為此音訊檔的sample rate
handles.time = length(y)/fs;
guidata(hObject, handles);
sound(y,fs);
time = (1:length(y))/fs;
plot(handles.axes1,time,y,'r');
[y, fs] = audioread('D:\Downloads\Coldplay - The Scientist.mp3');
s = abs(fft(y));
a = linspace(0,length(y),25);
b = linspace(0,length(s),25);
[aa,bb] = meshgrid(a,b);
cc = aa.*cos(-aa.^2-bb.^2);
plot(handles.axes2,time,y,'m');
surfl(aa,bb,cc);
axis tight;
colormap (pink);
shading interp
case 2
numing ='Coldplay - The Scientist';
[y, fs] = audioread('D:\Downloads\Coldplay - The Scientist.mp3'); % y會拿到音訊檔的所有點,fs為此音訊檔的sample rate
handles.time = length(y)/fs;
guidata(hObject, handles);
sound(y,fs*2);
time = (1:length(y))/fs;
plot(handles.axes1,time,y,'r');
[y, fs] = audioread('D:\Downloads\Coldplay - The Scientist.mp3');
s = abs(fft(y));
a = linspace(0,length(y),25);
b = linspace(0,length(s),25);
[aa,bb] = meshgrid(a,b);
cc = aa.*cos(-aa.^2-bb.^2);
plot(handles.axes2,time,y,'m');
surfl(aa,bb,cc);
axis tight;
colormap (pink);
shading interp
case 3
numing ='Earth, Wind & Fire - September';
[y, fs] = audioread('D:\Downloads\Earth, Wind & Fire - September (1).mp3'); % y會拿到音訊檔的所有點,fs為此音訊檔的sample rate
handles.time = length(y)/fs;
guidata(hObject, handles);
sound(y,fs);
time = (1:length(y))/fs;
plot(handles.axes1,time,y,'r');
[y, fs] = audioread('D:\Downloads\Earth, Wind & Fire - September (1).mp3');
s = abs(fft(y));
a = linspace(0,length(y),25);
b = linspace(0,length(s),25);
[aa,bb] = meshgrid(a,b);
cc = aa.*cos(-aa.^2-bb.^2);
plot(handles.axes2,time,y,'m');
surfl(aa,bb,cc);
axis tight;
colormap (pink);
shading interp
case 4
numing ='Earth, Wind & Fire - September';
[y, fs] = audioread('D:\Downloads\Earth, Wind & Fire - September (1).mp3'); % y會拿到音訊檔的所有點,fs為此音訊檔的sample rate
handles.time = length(y)/fs;
guidata(hObject, handles);
sound(y,fs*2);
time = (1:length(y))/fs;
plot(handles.axes1,time,y,'r');
[y, fs] = audioread('D:\Downloads\Earth, Wind & Fire - September (1).mp3');
s = abs(fft(y));
a = linspace(0,length(y),25);
b = linspace(0,length(s),25);
[aa,bb] = meshgrid(a,b);
cc = aa.*cos(-aa.^2-bb.^2);
plot(handles.axes2,time,y,'m');
surfl(aa,bb,cc);
axis tight;
colormap (pink);
shading interp
case 5
numing ='Jp Cooper - Birthday';
[y, fs] = audioread('D:\Downloads\Jp Cooper - Birthday .mp3');
handles.time = length(y)/fs;
guidata(hObject, handles);
sound(y,fs);
time = (1:length(y))/fs;
plot(handles.axes1,time,y,'r');
[y, fs] = audioread('D:\Downloads\Jp Cooper - Birthday .mp3');
s = abs(fft(y));
a = linspace(0,length(y),25);
b = linspace(0,length(s),25);
[aa,bb] = meshgrid(a,b);
cc = aa.*cos(-aa.^2-bb.^2);
plot(handles.axes2,time,y,'m');
surfl(aa,bb,cc);
axis tight;
colormap (pink);
shading interp
case 6
numing ='Jp Cooper - Birthday';
[y, fs] = audioread('D:\Downloads\Jp Cooper - Birthday .mp3');
handles.time = length(y)/fs;
guidata(hObject, handles);
sound(y,fs*2);
time = (1:length(y))/fs;
plot(handles.axes1,time,y,'r');
[y, fs] = audioread('D:\Downloads\Jp Cooper - Birthday .mp3');
s = abs(fft(y));
a = linspace(0,length(y),25);
b = linspace(0,length(s),25);
[aa,bb] = meshgrid(a,b);
cc = aa.*cos(-aa.^2-bb.^2);
plot(handles.axes2,time,y,'m');
surfl(aa,bb,cc);
axis tight;
colormap (pink);
shading interp
case 7
numing ='Bruno Mars - 24K Magic';
[y, fs] = audioread('D:\Downloads\Bruno Mars - 24K Magic.mp3');
handles.time = length(y)/fs;
guidata(hObject, handles);
sound(y,fs);
time = (1:length(y))/fs;
plot(handles.axes1,time,y,'r');
[y, fs] = audioread('D:\Downloads\Bruno Mars - 24K Magic.mp3');
s = abs(fft(y));
a = linspace(0,length(y),25);
b = linspace(0,length(s),25);
[aa,bb] = meshgrid(a,b);
cc = aa.*cos(-aa.^2-bb.^2);
plot(handles.axes2,time,y,'m');
surfl(aa,bb,cc);
axis tight;
colormap (pink);
shading interp
case 8
numing ='Bruno Mars - 24K Magic';
[y, fs] = audioread('D:\Downloads\Bruno Mars - 24K Magic.mp3');
handles.time = length(y)/fs;
guidata(hObject, handles);
sound(y,fs*2);
time = (1:length(y))/fs;
plot(handles.axes1,time,y,'r');
[y, fs] = audioread('D:\Downloads\Bruno Mars - 24K Magic.mp3');
s = abs(fft(y));
a = linspace(0,length(y),25);
b = linspace(0,length(s),25);
[aa,bb] = meshgrid(a,b);
cc = aa.*cos(-aa.^2-bb.^2);
plot(handles.axes2,time,y,'m');
surfl(aa,bb,cc);
axis tight;
colormap (pink);
shading interp;
end;
function pushbutton2_Callback(hObject, eventdata, handles)
clear sound;