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
답변 (1개)
Geoff Hayes
2015년 12월 4일
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
sarah
2015년 12월 5일
Walter Roberson
2015년 12월 5일
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.
카테고리
도움말 센터 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!