Performing audio energy calculation from gui.

Hi all. What i want is after i select an audio file from gui, i will click a pushbutton called 'Calculate energy' to calculate the energy of the selected audio, then the energy value will be print out on the gui. I already have the energy formula, but i dont know where to put the formula in the gui. Do i have to paste it in the pushbutton callback? can someone please guide me with this. below is the formula to extract audio energy feature. thank you in advance.
frameWidth = 441; %# 10 msec
numSamples = length(y); %# Number of samples in y
numFrames = floor(numSamples/frameWidth); %# Number of full frames in y
energy = zeros(1,numFrames); %# Initialize energy
startSample = zeros(1,numFrames); %# Initialize start indices of frame
endSample = zeros(1,numFrames); %# Initialize end indices of frame
for frame = 1:numFrames %# Loop over frames
startSample(frame) = (frame-1)*frameWidth+1; %# Starting index of frame
endSample(frame) = frame*frameWidth; %# Ending index of frame
frameIndex = startSample(frame):endSample(frame); %# Indices of frame samples
energy(frame) = sum(y(frameIndex).^2); %# Calculate frame energy
end

Respuestas (1)

Geoff Hayes
Geoff Hayes el 4 de Dic. de 2015
Sarah - it looks like your code for the energy calculation is in a script. Is that the case? If so, you could just convert it to a function that takes as input the audio data y and returns the energy output
function [energy] = energyCalc(y)
% etc. (code you have shown above)
The above assumes that y is the only needed input into this calculation. Then, in your GUI, you can call this function from within the 'Calculate Energy' pushbutton callback.

2 comentarios

sarah
sarah el 5 de Dic. de 2015
Mr Geoff, so i have to paste the function above into my pushbutton callback, is that right? and where exactly do i have to put the formula? please bare with me as i'm really clueless about this.
Walter Roberson
Walter Roberson el 5 de Dic. de 2015
Yes you can paste it into the callback of the pushbutton that you use to active the calculation, after having defined any variables it needs.

Iniciar sesión para comentar.

Preguntada:

el 4 de Dic. de 2015

Comentada:

el 5 de Dic. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by