Borrar filtros
Borrar filtros

How do i define the frequency band?

6 visualizaciones (últimos 30 días)
Jack Walker
Jack Walker el 23 de Nov. de 2016
Editada: Jack Walker el 24 de Nov. de 2016
Here in this code i am doing a stft on my wav-file. There is no problem with that. At the beginning, i am defining my parameter, afterwards using my wav file and then applying the stft. Basically what i am doing is a real-time spectral analysis. Anyway my question is, how do i a frequency band? I want my signal to be separated in LOW/MEDIUM/HIGH. I want my vector to be saved, from 0-250 Hz in the LOW-Band, 250-5000 Hz in the MEDIUM-Band, 5000-22.05k Hz in the HIGH-Band. I advise you, to try my code in Matlab, if you don't understand it. Just take any wav-file. Btw my signal is plotted in the variable "Yres". Any solution is appreciated!
NFA=2; %Every second picture is being plotted
t_seg=0.03; %length of my segment in ms
fftlen = 4096;
% Number of fft points
[y,fs]=audioread('UnchainMyHeart.wav');
t=linspace(0,length(y)/fs,length(y));
plot(t,y)
segl =floor(t_seg*fs);
windowshift=segl/2;
window=hann(segl);
window=window.';
si=1;
%Start index
ei=segl;
%End index
AOS= length(y)/windowshift - 1;
% Number of segments in my audio signal
f1=figure;
f=0:1:fftlen-1;
f=f/(fftlen-1)*fs;
Ya=zeros(1,fftlen);
plot(f,Ya),axis([0 fs -90 50])
grid on
n=0;
for m= 1:1:AOS
y_a = y(si:ei);
y_a= y_a.*window;
Ya=fft(y_a, fftlen);
n=n+1;
if n==1
Yres=abs(Ya);
else
Yres=Yres+abs(Ya);
end
if n==NFA
Yres=Yres/NFA;
n=0;
drawnow;
figure(f1);
plot(f(1:end/2), 20*log10(abs(Yres(1:end/2))));
a= (Yres);
ylim([-90 50]);
title('Spectrum of audio signal');
xlabel('f(Hz)');
ylabel('dB');
grid on;
end
si=si+windowshift;
%Updating start index
ei=ei+windowshift;
%Updating end index
end
  1 comentario
Daniel kiracofe
Daniel kiracofe el 24 de Nov. de 2016
What do you want the data type to be within the frequency band? You want a vector of the time history? You want a vector that contains a sub-set of the FFT? You want a scalar that is the peak amplitude within the band for that slice?
If the first one, the easiest way is to not use FFT at all. Just use a few bandpass filters. e.g.
[b_lowf, a_lowf] = butter(2, [0, 250] / (fs/2) );
[b_midf, a_midf] = butter(2, [250, 5000] / (fs/2) );
low = filter( b_lowf, a_lowf, y);
etc.
If you want something other than that, could you be more specific about exactly what data type you are looking for?

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by