存储最大频率
Store maximum frequency
我正在编写一个脚本,该脚本循环执行给定短音频文件的 FFT。我也想存储峰值频率,但我不知道该怎么做。
代码看起来类似于:
n = ...
Frequencies = zeros(1,n); % Allocating memory for the peak frequencies
for k = 1:n
str(k)
textFileName = [num2str(k) '.m4a'];
[data,fs] = audioread(textFileName);
%...
% Fast Fourier transform and plotting part works ok
%...
[peaks,frequencies] = findpeaks(abs(cutP2),cutf,'MinPeakHeight',10e-3);
% Here starts the problem
maximum_Peak = max(peaks);
Frequencies(k) = ... % I need to store the frequency which is coupled
% with the maximum amplitude but I do not know how
end
close(figure(n)) %The loop opens one redundant blank plot, I could not
%find out any other way to close it
我不想存储峰值频率的振幅,而是存储峰值振幅的频率。如果你能帮我解决多余的数字,我会很高兴。我尝试执行 if
语句但没有成功。
max
包含第二个输出,其中 returns 是最大值的索引。使用第二个值来存储感兴趣的值。
[maximum_Peak,I] = max(peaks); %Note I Use 'I' for index - personal habit
Frequencies(k) = frequencies(I);
此外,如果您的目标只是找到最大值,findpeaks 可能有点矫枉过正,您可能会使用:
[maximum_Peak,I] = max(abs(cutP2));
%Might want to check that max is high enough
Frequencies(k) = cutf(I);
请注意,虽然代码相似但并不相同,具体取决于您要执行的操作。
最后,一些不请自来的建议,您对 frequencies
和 Frequencies
的使用有点危险。通常基于大小写的差异不是一个好主意。考虑将后者重命名为 freq_of_max_amp
我正在编写一个脚本,该脚本循环执行给定短音频文件的 FFT。我也想存储峰值频率,但我不知道该怎么做。
代码看起来类似于:
n = ...
Frequencies = zeros(1,n); % Allocating memory for the peak frequencies
for k = 1:n
str(k)
textFileName = [num2str(k) '.m4a'];
[data,fs] = audioread(textFileName);
%...
% Fast Fourier transform and plotting part works ok
%...
[peaks,frequencies] = findpeaks(abs(cutP2),cutf,'MinPeakHeight',10e-3);
% Here starts the problem
maximum_Peak = max(peaks);
Frequencies(k) = ... % I need to store the frequency which is coupled
% with the maximum amplitude but I do not know how
end
close(figure(n)) %The loop opens one redundant blank plot, I could not
%find out any other way to close it
我不想存储峰值频率的振幅,而是存储峰值振幅的频率。如果你能帮我解决多余的数字,我会很高兴。我尝试执行 if
语句但没有成功。
max
包含第二个输出,其中 returns 是最大值的索引。使用第二个值来存储感兴趣的值。
[maximum_Peak,I] = max(peaks); %Note I Use 'I' for index - personal habit
Frequencies(k) = frequencies(I);
此外,如果您的目标只是找到最大值,findpeaks 可能有点矫枉过正,您可能会使用:
[maximum_Peak,I] = max(abs(cutP2));
%Might want to check that max is high enough
Frequencies(k) = cutf(I);
请注意,虽然代码相似但并不相同,具体取决于您要执行的操作。
最后,一些不请自来的建议,您对 frequencies
和 Frequencies
的使用有点危险。通常基于大小写的差异不是一个好主意。考虑将后者重命名为 freq_of_max_amp