How can I calculate the energy of an audio file (audio signal) that I imported in Matlab?

15 次查看(过去 30 天)
I'm trying to calculate the energy of an audio file in matlab. I wnat to calculate its energy before and after filtering. Here's my matlab script:
clear('all');
close('all');
[f,fs] = audioread('test.wav');
N = size(f,1); % Determine total number of samples in audio file
figure;
subplot(2,1,1);
plot(1:N, f(:,1));
title('Left Channel');
subplot(2,1,2);
plot(1:N, f(:,1));
title('Right Channel');
n = 2;
fprintf('The sum of the absoulte values (Before filtering) is: \n');
fff = fft(f);
h = sum(abs(fff));
max(f)
disp(h)
beginFreq = 700 / (fs/2);
endFreq = 1600 / (fs/2);
[b,a] = butter(n, [beginFreq, endFreq], 'bandpass');
fOut = filter(b, a, f);
% Construct audioplayer object and play
%p = audioplayer(fOut, fs);
%p.play;
fprintf('The sum of the absoulte values (After filtering) is: \n');
figure;
plot(filter(b, a, f))
ggg = fft(f);
h = sum(abs(ggg));
disp(h)
fprintf('Sampling Frequency is: \n');
disp(fs)

回答(1 个)

Frank Macias-Escriva
In your code you will start approaching to your solution just fixing the mistyping on the calculation of "ggg", I mean, almost at the end of your script you should:
ggg = fft(fOut);
instead of using "fft(f)". (in the last plot I would also use "plot(fOut)")
Anyway, you should check if you really want the energy of the discrete signal then you should look for:
sum(abs(fff).^2)/numel(f)
That Parseval's theorem states will be equal to "sum(f.^2)".
Consequently, for the filtered signal it will be:
sum(abs(ggg).^2)/numel(fOut)
again, it will be equal to sum(fOut.^2).
Hope this help.
Frank

类别

Help CenterFile Exchange 中查找有关 Measurements and Spatial Audio 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by