Beruflich Dokumente
Kultur Dokumente
SUBMITTED BY
DIVYANSHU CHHABRA
AYUSH DEVAL (17105049)
Objective/Aim
The aim/objective of this project is to create a Piano Keyboard App that can produce musical
notes in three different waveforms i.e., Sine waveform, Square waveform and Sawtooth
waveform. The app should be able to record the previously played musical notes or a
musical pattern and should also be able to set the tempo of the notes. The app must have
several options for 1/8th note, 1/4th note, 1/2th note and 1 note for user comfortability of
producing a melody.
Theory
MATLAB: MATLAB (matrix laboratory) is a multi-paradigm numerical computing
environment and proprietary programming language developed by MathWorks. MATLAB
allows matrix manipulations, plotting of functions and data, implementation of algorithms,
creation of user interfaces, and interfacing with programs written in other languages,
including C, C++, C#, Java, Fortran and Python.
Although MATLAB is intended primarily for numerical computing, an optional toolbox uses
the MuPAD symbolic engine, allowing access to symbolic computing abilities. An additional
package, Simulink, adds graphical multi-domain simulation and model-based design for
dynamic and embedded systems.
GUIs: GUIs (also known as graphical user interfaces or UIs) provide point-and-click control of
software applications, eliminating the need to learn a language or type commands in order
to run the application.
MATLAB® apps are self-contained MATLAB programs with GUI front ends that automate a
task or calculation. The GUI typically contains controls such as menus, toolbars, buttons, and
sliders. Many MATLAB products, such as Curve Fitting Toolbox™, Signal Processing Toolbox™,
and Control System Toolbox™ include apps with custom user interfaces. You can also create
your own custom apps, including their corresponding UIs, for others to use.
DIGITAL PIANO: Digital pianos are also non-acoustic and do not have strings or hammers.
They use digital sampling technology to reproduce the acoustic sound of each piano note
accurately. They also must be connected to a power amplifier and speaker to produce sound
(however, most digital pianos have a built-in amp and speaker). Alternatively, a person can
practice with headphones to avoid disturbing others. Digital pianos can include sustain
pedals, weighted or semi-weighted keys, multiple voice options (e.g., sampled or synthesized
imitations of electric piano, Hammond organ, violin, etc.), and MIDI interfaces.
MUSICAL SOUNDS: Musical sounds are vibrations which are strongly regular. When you
hear a regular vibration, your ear detects the frequency, and you perceive this as the pitch of
a musical tone.
There are two main properties of a regular
vibration - the amplitude and the frequency - which
affect the way it sounds.
Amplitude is the size of the vibration, and this
determines how loud the sound is. We have already seen that larger vibrations make a
louder sound.
Amplitude is important when balancing and controlling the loudness of sounds, such as with
the volume control on your CD player. It is also the origin of the word amplifier, a device
which increases the amplitude of a waveform.
Frequency is the speed of the vibration, and this determines the pitch of the sound. It is only
useful or meaningful for musical sounds, where there is a strongly regular waveform.
Frequency is measured as the number of wave cycles that occur in one second. The unit of
frequency measurement is Hertz (Hz for short).
A frequency of 1 Hz means one wave cycle per second. A frequency of 10 Hz means ten
wave cycles per second, where the cycles are much shorter and closer together.
The note A which is above Middle C (more on this later) has a frequency of 440 Hz. It is often
used as a reference frequency for tuning musical instruments. Frequency of the musical
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Outputs from this function are returned to the command line.
function varargout = piano2_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)
freq = 207.65;
PlayNote(handles,freq);
freq = 233.08;
PlayNote(handles,freq);
freq = 739.99;
PlayNote(handles,freq);
freq = 185.00;
PlayNote(handles,freq);
freq = 466.16;
PlayNote(handles,freq);
freq = 622.25;
PlayNote(handles,freq);
freq = 554.37;
PlayNote(handles,freq);
freq = 415.3;
PlayNote(handles,freq);
freq = 277.18;
PlayNote(handles,freq);
freq = 196;
PlayNote(handles,freq);
freq = 220;
PlayNote(handles,freq);
freq = 246.94;
PlayNote(handles,freq);
freq = 261.625;
PlayNote(handles,freq);
freq = 293.66;
PlayNote(handles,freq);
freq = 329.63;
PlayNote(handles,freq);
freq = 349.23;
PlayNote(handles,freq);
freq = 392;
PlayNote(handles,freq);
freq = 440;
PlayNote(handles,freq);
freq = 493.88;
PlayNote(handles,freq);
freq = 523.25;
PlayNote(handles,freq);
% --- Executes on button press in D5.
function D5_Callback(hObject, eventdata, handles)
% hObject handle to D5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 587.33;
PlayNote(handles,freq);
freq = 659.26;
PlayNote(handles,freq);
freq = 698.46;
PlayNote(handles,freq);
freq = 369.99;
PlayNote(handles,freq);
freq = 311.13;
PlayNote(handles,freq);
freq = 783.99;
PlayNote(handles,freq);
freq = 164.81;
PlayNote(handles,freq);
freq = 146.83;
PlayNote(handles,freq);
freq = 880;
PlayNote(handles,freq);
freq = 130.81;
PlayNote(handles,freq);
freq = 987.77;
PlayNote(handles,freq);
freq = 830.61;
PlayNote(handles,freq);
freq = 932.33;
PlayNote(handles,freq);
freq = 155.56;
PlayNote(handles,freq);
freq = 138.59;
PlayNote(handles,freq);
function PlayNote(handles,freq)
% plays the note that was pressed for 1 second
% also sets the frequency value on GUI for last played note.
strFreq = num2str(freq);
set(handles.STFreqValue, 'String', strFreq);
SampleRate = handles.SampleRate;
TimeValue = handles.TimeValue;
Samples = 0:SampleRate:TimeValue;
SinOn = get(handles.SinWave, 'Value');
SquareOn = get(handles.SquareWave, 'Value');
SawtoothOn = get(handles.SawtoothWave, 'Value');
if SinOn == 1
soundVector = sin(2*pi*freq*Samples);
elseif SquareOn == 1
soundVector = square(2*pi*freq*Samples);
elseif SawtoothOn == 1
soundVector = sawtooth(2*pi*freq*Samples);
end
sound(soundVector, 1/SampleRate)
if RecordOn == 1
SoundVectorLong = handles.SoundVector;
if SoundVectorLong == 0
SoundVectorLong = soundVector;
else
SoundVectorLong = cat(2, SoundVectorLong, soundVector);
end
handles.SoundVector = SoundVectorLong;
guidata(handles.figure1, handles);
end
SoundVector = handles.SoundVector;
SampleRate = handles.SampleRate;
sound(SoundVector, 1/SampleRate)
handles.SoundVector = 0;
guidata(handles.figure1, handles);
if half == 1
TimeValue = TimeValue * 2;
elseif Whole == 1
TimeValue = TimeValue * 4;
elseif Eighth == 1
TimeValue = TimeValue / 2;
end
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
% --- Executes on button press in HalfNote.
function HalfNote_Callback(hObject, eventdata, handles)
% hObject handle to HalfNote (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
% --- Executes on key press with focus on F3 and none of its controls.
function F3_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to F3 (see GCBO)
% eventdata structure with the following fields (see
MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)