如何做一个频段?

How to do a frequency band?

在此代码中,我正在对我的 wav 文件执行 stft。这没有问题。一开始,我定义我的参数,然后使用我的 wav 文件,然后应用 stft.基本上我正在做的是实时频谱分析。无论如何,我的问题是,我如何使用频段?我希望我的信号在 LOW/MEDIUM/HIGH 中分离。我希望我的矢量被保存,从低频段的 0-250 Hz,中频段的 250-5000 Hz,高频段的 5-22.05k Hz。如果您不理解,我建议您在 Matlab 中尝试我的代码。只需使用任何 wav 文件。顺便说一句,我的信号绘制在变量 "Yres" 中。任何解决方案表示赞赏!

NFA=2; % Number is used for plotting every 2nd picture
t_seg=0.05; % Length of segment in ms

fftlen = 4096; 
% Lenght of "fft",because our segment contains 2205 points

[y,fs]=audioread('UnchainMyHeart.wav');
% audioread = functions reads WAV-file
% y = A vector which contains my audio signal
% fs = sample frequency (44100)
% 'UnchainMyHeart' = WAV-file

t=linspace(0,length(y)/fs,length(y));
% linspace = Creating time vector
% 0 = Start time
% length(y)/fs = End time
% length(y) = Number of samples in y

plot(t,y)
% plotting signal in the time domain


segl =floor(t_seg*fs); 
% Applying fft function on the variable "segl"

windowshift=segl/2; 
% Defining the size of the window, which goes to the next "segl"


window=hann(segl); 
% hann function

window=window.'; 

si=1; 
%Start index

ei=segl; 
%End index

AOS= length(y)/windowshift - 1;
% AOS is the number of "segl" we use (About 433)

f1=figure;
% Opening new window

f=0:1:fftlen-1;
f=f/(fftlen-1)*fs;
% Defining frequency vector

Ya=zeros(1,fftlen);

plot(f,Ya),axis([0 fs -90 50])

grid on 

n=0;
%start variable

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; 
  %Tut die Grafikobjekte immer auf den neuesten Stand updaten

figure(f1);
plot(f(1:end/2), 20*log10(abs(Yres(1:end/2))));


ylim([-90 50]);
title('Spektrum eines Audiosignal');    
xlabel('f(Hz)');
ylabel('dB');

grid on;

end


si=si+windowshift; 
% Updating start index

ei=ei+windowshift; 
% Updating end index

end

这可能不是最佳答案!但这可能会帮助您开始做某事。您可以使用 MATLAB 信号处理工具箱中的 spectrogram() 函数。

假设您有一个名为''UnchainMyHeart.wav'(在您的例子中)的音频文件,只有一个频道。代码如下:

% Reading the audio file
[y1,fs] = audioread('UnchainMyHeart.wav');

% Parameters for STFT (or spectrogram)
windowDuration = 30e-3; overlapDuration = 15e-3;
windowLength = round(windowDuration*fs);   % window length
overlapLength = round(overlapDuration*fs); % overlapping of windows
nfft = 1024;

% Executing STFT for the signal
[S1,F1,T1,P1] = spectrogram(x1,hanning(windowLength), ...
overlapLength, nfft, fs, 'yaxis');

S1 和 P1 包含信号的 STFT 和功率谱密度 (PSD) 对于每个部分的时间间隔,其估计包含在 T1 中。

对于您的问题,您正在寻找 F1,它是一个以采样频率 fs 表示的循环频率向量。例如:如果您的采样频率为 48 kHz (fs),nfft 为 1024,那么您将有 513 [(1024/2) +1)] 个频率值,间隔为 (fs/nfft)。即 46.875。因此,您的频率分量将为 0、46.875、46.875*2、...、46.875*512。由于奈奎斯特准则,您将拥有的最大值为 24 kHz。

现在,您可以轻松编写一个简单的例程来指定您所说的范围。同样的技术可以用在你的代码中,它是 stft 的一个实现。我建议使用 MATLAB 的内置函数,除非您的问题需要实现。希望这可以帮助!

如果需要,我可以回答为什么选择 STFT 的参数包含在代码中。