Performing audio energy calculation from gui.
Show older comments
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
Answers (1)
Geoff Hayes
on 4 Dec 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 Comments
sarah
on 5 Dec 2015
Walter Roberson
on 5 Dec 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.
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!