Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 怎样做一个频带?_Matlab_Audio_Frequency - Fatal编程技术网

Matlab 怎样做一个频带?

Matlab 怎样做一个频带?,matlab,audio,frequency,Matlab,Audio,Frequency,在这段代码中,我正在对wav文件执行stft。这没有问题。首先,我定义参数,然后使用wav文件,然后应用stft。基本上我所做的是实时光谱分析。不管怎样,我的问题是,我怎样才能获得一个频带?我希望我的信号以低/中/高分开。我希望我的向量被保存,从0-250赫兹在低频段,250-5000赫兹在中频段,5-22.05k赫兹在高频段。我建议你,如果你不懂的话,试试我的Matlab代码。只需使用任何wav文件。顺便说一句,我的信号绘制在变量“Yres”中。任何解决方案都将不胜感激 NFA=2; % Nu

在这段代码中,我正在对wav文件执行stft。这没有问题。首先,我定义参数,然后使用wav文件,然后应用stft。基本上我所做的是实时光谱分析。不管怎样,我的问题是,我怎样才能获得一个频带?我希望我的信号以低/中/高分开。我希望我的向量被保存,从0-250赫兹在低频段,250-5000赫兹在中频段,5-22.05k赫兹在高频段。我建议你,如果你不懂的话,试试我的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)。i、 e.46.875。所以你的频率分量是0,46.875,46.875*2,…,46.875*512。根据奈奎斯特标准,最大值为24 kHz

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


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

我的fs是44.1k。我想我明白你的意思。(英语不是我的母语)。我知道stft已经有一个内置功能。但我应该提到的是,这是一个项目,我需要自己编写代码,而不使用内置函数。如果你能给我演示/解释一下,是否可能指定范围?我有点困惑,如何应用它。这是频率分辨率的常见情况(适用于fft和stft)。如果fs=44.1 kHz,则捕获的最大频率为22050。如果fs=44.1 kHz,则捕获的最大频率为22050。频率分辨率为4096时,STFT中的频率间隔为44.1e3/4096=10.7666和2049。所以频率向量是:0,10.7666,21.5332,32.2998,…22050。在您的情况下,STFT(1:24)将用于低频段,STFT(25:465)将用于中频段,其余用于高频段。我希望你能得到它。STFT是您保存结果值的变量。现在我得到了它,并感谢您非常精确地解释:)我非常感谢您的帮助!