How can i calculate the individual magnitude from my band?

1 次查看(过去 30 天)
I took out 50ms from a signal and then apply a fft on it. Afterwards i separate it in 3 band. How can i calculate the individual magnitude in a band? Because i want to sum all of the magnitude into a value and then square it with 2. Therefore i would get the power from my band, which i want.
%%MATLAB
%_________________________________________
[y,fs]=audioread('Undertale - Megalovania.wav');
% audioread = Read WAV-file
% y = Vector, which contains audio signal
% fs = Sample Rate
% 'dontstopmenow' = WAV-file
%_________________________________________
%PARAMETER FOR STFT
%_________________________________________
t_seg=0.03; % Length of segment in ms
fftlen = 4096; %FFT-Points
%Definition of frequency bands
f_LOW= 1:200; %lower frequencies
f_MEDIUM= 201:600; %medium frequencies
f_HIGH= 601:1000; %higher frequencies
%__________________________________________
segl =floor(t_seg*fs);
% Length of segment, on which we use the fft
% "floor" rounds off the result
windowshift=segl/2;
% size of window which goes to the next segment
window=hann(segl);
%hann function
window=window.';
% From a row vector to a column vector
si=1;
%Start index
ei=segl;
%End index
N=floor( length(y)/windowshift - 1);
% Number of segements in audio signal
f1=figure;
% New window
f=0:1:fftlen-1;
f=f/fftlen*fs;
% frequency vector
Ya=zeros(1,fftlen);
for m= 1:1:N
y_a = y(si:ei);
y_a= y_a.*window;
Ya=fft(y_a, fftlen);
Yb=abs(Ya(1:end/2));
drawnow; %Updates graphical objects
figure(f1);
plot(f(1:end/2), 20*log10(Yb));
%STFT __Audio signal after stft every 50ms
%%L,M,H - Bands
subplot(3,1,1)
y_low = abs(Ya(f_LOW));
ya_low = sum(y_low).^2;
plot(f_LOW,y_low);
ylim([-90 50]);
title('Spektrum (LOW)');
xlabel('f(Hz)');
ylabel('dB');
grid on
subplot(3,1,2)
y_medium = Ya(f_MEDIUM);
plot(f_MEDIUM,y_medium);
ylim([-20 30]);
title('Spektrum (MEDIUM)');
xlabel('f(Hz)');
ylabel('dB');
grid on
subplot(3,1,3)
y_high = Ya(f_HIGH);
plot(f_HIGH,y_high);
ylim([-20 30]);
title('Spektrum (HIGH)');
xlabel('f(Hz)');
ylabel('dB');
grid on;
si=si+windowshift;
% start index updated
ei=ei+windowshift;
% end index updated
end
  1 个评论
Nirja Mehta
Nirja Mehta 2017-2-7
Do you mean to compute the following? Band Power
There are multiple functions in Signal Processing Blockset that helps you anaylze spectral content of a signal. Spectral Estimation
Also, do change plot(f_LOW,y_low) to plot(f_LOW,ya_low) on Line 52.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by