1

我正在使用移动的音频源和静止的观察者进行线性运动测量。此处描述:http ://www.animations.physics.unsw.edu.au/labs/Doppler/doppler_lab.html

如何编写一个MATLAB脚本来获取音频文件中功率最大的频率的样本数?

4

1 回答 1

3

您需要的是时频本地化信息。这可以使用短时傅里叶变换来获得。还有许多其他时频分析技术,STFT 是最简单的,因此是一个很好的起点。这是一个简单的代码来帮助您理解这个概念:

% Parameters
Fs = 44100; % Sample rate (44100 Hz)
t = 0:1/Fs:5; % Time instances
t1 = 5; % End time of signal, 5 secs
f0 = 440; % frequency swiped from 440 Hz
f1 = 880; % to 880 Hz

% Signal generation
audio = chirp(t,f0,t1,f1);
% wavplay(audio,Fs) % to play the audio


% Signal analysis
window = 2050; % Should be minimum twice the maximum frequency we want to analyze
noverlap = 1025; % 50% overlap
nfft = 44100;

[S,F,T,P] = spectrogram(audio,window,noverlap,nfft,Fs); % Spectrogram takes the STFT of the signal
% P matrix contains the power spectral density of each segment of the STFT

% Plotting results
imagesc(real(S)) % frequency-time Plot of the signal
ylim([0 1000])
xlabel('Time (secs)')
ylabel('Frequency (Hz)')
title('Time-Frequency plot of a Audio signal')

要获取样本数,您只需要找到您感兴趣的频率出现的时间实例,并使用采样频率来计算样本数。

P 是功率谱密度矩阵。沿 y 轴是频率,x 轴是时间,每个频率在每个瞬间贡献的功率都存储在这个矩阵中。您需要在整个矩阵中具有最高值的元素。如下代码应该可以工作:

[maxElement, maxElementTimeIndex] = max(max(P, [], 1)); % max(P, [], 1) finds maximum power for each time instance, max(max(P,[],1)) finds maximum for the entire 2D matrix.
maxPoweredSampleInAudioSignal = (maxElementTimeIndex-1) * Fs; % This calculation is made within the limitations of STFT, so approximately here the maximum power for any frequency is present
于 2013-08-28T07:00:24.377 回答