CODE

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

classdef cep < matlab.apps.

AppBase

% Properties that correspond to app components


properties (Access = public)
UIFigure matlab.ui.Figure
GenderEditField matlab.ui.control.EditField
GenderEditFieldLabel matlab.ui.control.Label
RESETButton matlab.ui.control.Button
FilepathEditField matlab.ui.control.EditField
FilepathLabel matlab.ui.control.Label
BrowseButton matlab.ui.control.Button
LiveAudioButton matlab.ui.control.Button
UIAxes_2 matlab.ui.control.UIAxes
UIAxes matlab.ui.control.UIAxes
end

% Callbacks that handle component events


methods (Access = private)

% Button pushed function: LiveAudioButton


function LiveAudioButtonPushed(app, event)
inputter = audiorecorder(8000, 8, 1);
recDuration = 5;
disp("Begin speaking.")
recordblocking(inputter,recDuration);
disp("End of recording.")
y = getaudiodata(inputter);
plot (app.UIAxes_2, y);
%yf = bandpass(y, [1 340], 8000, ImpulseResponse="iir",Steepness=0.95)
ymfilt = bandpass(y,[80
160],8000,ImpulseResponse="iir",Steepness=0.95);
yffilt = bandpass(y, [180, 260],
8000,ImpulseResponse="iir",Steepness=0.95);
female = rms(yffilt);
male = rms(ymfilt);
if(male>female)
app.GenderEditField.Value = "male";
plot(app.UIAxes, ymfilt);
else
app.GenderEditField.Value = "female";
plot(app.UIAxes, yffilt);
end
end

% Button pushed function: BrowseButton


function BrowseButtonPushed(app, event)
[Filename, Pathname]=uigetfile(".wav")
name=strcat(Pathname,Filename);
app.FilepathEditField.Value=name;
[y,Fs] = audioread(name)
plot (app.UIAxes_2, y);
ymfilt = bandpass(y,[80 160],Fs,ImpulseResponse="iir",Steepness=0.95);
yffilt = bandpass(y, [180, 260],
Fs,ImpulseResponse="iir",Steepness=0.95);
female = rms(yffilt);
male = rms(ymfilt);
if(male>female)
app.GenderEditField.Value = "male";
plot(app.UIAxes, ymfilt);
else
app.GenderEditField.Value = "female";
plot(app.UIAxes, yffilt);
end
end

% Button pushed function: RESETButton


function RESETButtonPushed(app, event)
app.UIFigure.Visible = 'off';
cep();
close(app.UIFigure)
end
end

% Component initialization
methods (Access = private)

% Create UIFigure and components


function createComponents(app)

% Create UIFigure and hide until all components are created


app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';

% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Filtered Graph')
xlabel(app.UIAxes, 'Time')
ylabel(app.UIAxes, 'Magnitude')
zlabel(app.UIAxes, 'Z')
app.UIAxes.Position = [353 174 192 135];

% Create UIAxes_2
app.UIAxes_2 = uiaxes(app.UIFigure);
title(app.UIAxes_2, 'Unfiltered Graph')
xlabel(app.UIAxes_2, 'Time')
ylabel(app.UIAxes_2, 'Magnitude ')
zlabel(app.UIAxes_2, 'Z')
app.UIAxes_2.Position = [353 313 192 135];

% Create LiveAudioButton
app.LiveAudioButton = uibutton(app.UIFigure, 'push');
app.LiveAudioButton.ButtonPushedFcn = createCallbackFcn(app,
@LiveAudioButtonPushed, true);
app.LiveAudioButton.Position = [150 300 98 42];
app.LiveAudioButton.Text = 'Live Audio';

% Create BrowseButton
app.BrowseButton = uibutton(app.UIFigure, 'push');
app.BrowseButton.ButtonPushedFcn = createCallbackFcn(app,
@BrowseButtonPushed, true);
app.BrowseButton.Position = [150 237 98 42];
app.BrowseButton.Text = 'Browse';

% Create FilepathLabel
app.FilepathLabel = uilabel(app.UIFigure);
app.FilepathLabel.HorizontalAlignment = 'right';
app.FilepathLabel.Position = [172 195 54 22];
app.FilepathLabel.Text = 'Filepath ';

% Create FilepathEditField
app.FilepathEditField = uieditfield(app.UIFigure, 'text');
app.FilepathEditField.Position = [68 158 262 22];

% Create RESETButton
app.RESETButton = uibutton(app.UIFigure, 'push');
app.RESETButton.ButtonPushedFcn = createCallbackFcn(app,
@RESETButtonPushed, true);
app.RESETButton.Position = [150 371 98 42];
app.RESETButton.Text = 'RESET';

% Create GenderEditFieldLabel
app.GenderEditFieldLabel = uilabel(app.UIFigure);
app.GenderEditFieldLabel.HorizontalAlignment = 'right';
app.GenderEditFieldLabel.Position = [356 139 52 22];
app.GenderEditFieldLabel.Text = 'Gender ';

% Create GenderEditField
app.GenderEditField = uieditfield(app.UIFigure, 'text');
app.GenderEditField.Position = [423 135 122 30];

% Show the figure after all components are created


app.UIFigure.Visible = 'on';
end
end

% App creation and deletion


methods (Access = public)

% Construct app
function app = cep

% Create UIFigure and components


createComponents(app)

% Register the app with App Designer


registerApp(app, app.UIFigure)

if nargout == 0
clear app
end
end

% Code that executes before app deletion


function delete(app)

% Delete UIFigure when app is deleted


delete(app.UIFigure)
end
end
end

You might also like