How can I calculate the energy of an audio file (audio signal) that I imported in Matlab?
조회 수: 11 (최근 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
2017년 2월 22일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!