top of page

Midterm Project

Radio.

Introduce 

 

​

There is a signal handle by Matlab, and I use Matlab to let the signal become different changing when I output the plot.

The interface I use is one of the function in Matlab which called "GUI", if we want to call it out, we can just type "guide" in the command window, and there will show up many kinds of function in GUI, Button-using is one of the measure to use.

The music I use is "A Little Story", and It is interesting become changing the signal.

​

Demo Video 

 

​

​Code

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

% Last Modified by GUIDE v2.5 16-May-2019 00:27:49

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

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

% Update handles structure
guidata(hObject, handles);

​

plot(handles.axes1,0);
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
hold on

plot(handles.axes2,0);
grid(handles.axes2,"on");
xlabel(handles.axes2,'time');
ylabel(handles.axes2,'Magnitude');
hold on

plot(handles.axes3,0);
grid(handles.axes3,"on");
xlabel(handles.axes3,'time');
ylabel(handles.axes3,'Magnitude');
hold on

​

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


% --- Outputs from this function are returned to the command line.
function varargout = untitled_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.
%Start
function pushbutton1_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)


Fs1=44100;
fs=Fs1;
T=1/fs;
        song = 'E:\A Little Story.mp3'
        [y,fs]=audioread(song, [1 795554]);    % read the song from point 1~point795554(0sec~18sec)
        sound(y,fs);
        time=(1:length(y))/fs;
        plot(handles.axes1,time, y); 
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
title(handles.axes1,'Original');
hold on


% --- Executes on button press in pushbutton2.
%Stop
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


clear sound
hold off
plot(handles.axes1,0);
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
hold on

plot(handles.axes2,0);
grid(handles.axes2,"on");
xlabel(handles.axes2,'time');
ylabel(handles.axes2,'Magnitude');
hold on

plot(handles.axes3,0);
grid(handles.axes3,"on");
xlabel(handles.axes3,'time');
ylabel(handles.axes3,'Magnitude');
hold on

​

​

% --- Executes on button press in pushbutton3.
%Volume +
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


Fs1=44100;
fs=Fs1;
T=1/fs;
        song = 'E:\A Little Story.mp3'
        [y,fs]=audioread(song, [1 795554]);    % read the song from point 1~point795554(0sec~18sec)
        a=2*y
        sound(a,fs);
        time=(1:length(a))/fs;
        plot(handles.axes1,time, a);
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
title(handles.axes1,'Volume +');
hold on

​

​

% --- Executes on button press in pushbutton4.
%Volume -
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


Fs1=44100;
fs=Fs1;
T=1/fs;
        song = 'E:\A Little Story.mp3'
        [y,fs]=audioread(song, [1 795554]);    % read the song from point 1~point795554(0sec~18sec)
        b=0.3*y
        sound(b,fs);
        time=(1:length(b))/fs;
        plot(handles.axes1,time, b); 
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
title(handles.axes1,'Volume -');
hold on

​

​

% --- Executes on button press in pushbutton5.
%Fast
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


Fs1=44100;
fs=Fs1;
T=1/fs;
        song = 'E:\A Little Story.mp3'
        [c,fs] = audioread(song);
        sound(c,2*fs);
        time=(1:length(c))/fs;
        plot(handles.axes1,time, c); 
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
title(handles.axes1,'Fast');
hold on

​


% --- Executes on button press in pushbutton6.
%Slow
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


Fs1=44100;
fs=Fs1;
T=1/fs;
        song = 'E:\A Little Story.mp3'
        [d,fs] = audioread(song);
        sound(d,0.75*fs);
        time=(1:length(d))/fs;
        plot(handles.axes1,time, d); 
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
title(handles.axes1,'Slow');
hold on

​


% --- Executes on button press in pushbutton7.
%Two channel segement
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


Fs1=44100;
fs=Fs1;
T=1/fs;
        song = 'E:\A Little Story.mp3'
        [L1,fs]=audioread(song);    % read the song 
        [R1,fs]=audioread(song);    % read the song
        L_seg=L1(1:44100*18);      % read the song from point 1~point793800(0sec~18sec)
        R_seg=R1(1:44100*18);
        comp=L_seg+R_seg;         % compare L_seg & R_seg
        
        ramp=0:1/(44100*17):1;      %L_seg setting make it different from R_seg
        N=length(ramp);
        L_seg(1:N)=L_seg(1:N).*ramp; 
        hold on
        comp=L_seg+R_seg;
        
        L_seg=transpose(L_seg);  %transpose L_seg[1  793800] into L_seg[793800 1]
        R_seg=transpose(R_seg);
        L_seg=[L_seg,L_seg];     %that the size of L_seg become [793800  2]
        R_seg=[R_seg,R_seg];
        comp=L_seg+R_seg;
        
        plot(handles.axes1,L_seg,'r');
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
title(handles.axes1,'First segement');
hold on
        plot(handles.axes2,R_seg,'b');
grid(handles.axes2,"on");
xlabel(handles.axes2,'time');
ylabel(handles.axes2,'Magnitude');
title(handles.axes2,'Second segement');
hold on
        La=audioplayer(L_seg, fs);
        Ra=audioplayer(R_seg, fs);
        playblocking(La);
        playblocking(Ra);
        hold on

 


% --- Executes on button press in pushbutton8.
%Two channel together
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


Fs1=44100;
fs=Fs1;
T=1/fs;
        song = 'E:\A Little Story.mp3'
        [L1,fs]=audioread(song);    %
read the song
        [R1,fs]=audioread(song);
 
        L_seg=L1(1:44100*18);     % 
read the song from point 1~point795554(0sec~18sec)
        R_seg=R1(1:44100*18);
        comp=L_seg+R_seg;
        
        ramp=0:1/(44100*17):1;
        N=length(ramp);
        L_seg(1:N)=L_seg(1:N).*ramp;
        hold on
        comp=L_seg+R_seg;
        
        L_seg=transpose(L_seg);
        R_seg=transpose(R_seg);
        L_seg=[L_seg,L_seg];
        R_seg=[R_seg,R_seg];
        comp=L_seg+R_seg;
        
        plot(handles.axes1,L_seg,'r');
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
title(handles.axes1,'First segement no sound');
hold on
        plot(handles.axes2,R_seg,'b');
grid(handles.axes2,"on");
xlabel(handles.axes2,'time');
ylabel(handles.axes2,'Magnitude');
title(handles.axes2,'Second segement no sound');
hold on
        plot(handles.axes3,comp,'y');
        sound(comp,44100);
grid(handles.axes3,"on");
xlabel(handles.axes3,'time');
ylabel(handles.axes3,'Magnitude');
title(handles.axes3,'Together');
hold on
        

​

% --- Executes on button press in pushbutton9.
%Reverse
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


Fs1=44100;
fs=Fs1;
T=1/fs;
        song = 'E:\A Little Story.mp3'
        [y,fs]=audioread(song, [1 795554]);    read the song from point 1~point795554(0sec~18sec)
        timep=(1:length(y))/fs;
        timeq=(1:length(-y))/fs;
        timer=(1:length(flipud(y)))/fs;
        
        plot(handles.axes1,timep, y);
grid(handles.axes1,"on");
xlabel(handles.axes1,'time');
ylabel(handles.axes1,'Magnitude');
title(handles.axes1,'Normal');
        plot(handles.axes2,timeq, -y);
grid(handles.axes2,"on");
xlabel(handles.axes2,'time');
ylabel(handles.axes2,'Magnitude');
title(handles.axes2,'Amplitude flip');
        plot(handles.axes3,timer, flipud(y));
grid(handles.axes3,"on");
xlabel(handles.axes3,'time');
ylabel(handles.axes3,'Magnitude');
title(handles.axes3,'Reverse');
        p=audioplayer(y, fs);
        q=audioplayer(-y, fs);% Playback of the up-down flipped signal 
        r=audioplayer(flipud(y), fs);% Playback of the left-right flipped signal 
        playblocking(p);
        playblocking(q);
        playblocking(r);
hold on

Commercial.
Video Games.
Film Score.
TV.
bottom of page