gpt4 book ai didi

matlab - 从wav文件进行Matlab下采样和包络提取

转载 作者:行者123 更新时间:2023-12-03 01:46:50 26 4
gpt4 key购买 nike

我对下面的代码有疑问,因为我不确定我是否对所有程序进行了正确的编程,并且代码是否确实可以执行我希望他执行的操作。

我有一个音频文件“03 Black Smoke.wav”,我必须将该音频文件下采样到500 Hz。
在那之后,我必须将Audiofile剪切为最长3分钟的

代码正确地进行了下采样吗?

有人可以给我一个提示,我如何从每个采样点的 input_cut.wav 文件中提取信封?

% Downsampling of the audio file to ensure compatibility with EEG-Data
% Extracts musical features (envelope) of a song.
% Input: Audio File
% Author: A. B.
% Date: 06.02.2017

clc;
clear;

% get infos (e.g. sample rate)
info = audioinfo('03 Black Smoke.wav');
[input,Fs] = audioread('03 Black Smoke.wav');
plot(input)

% plot in frequency domain
n = length(input)-1;
f = 0:Fs/n:Fs;
wavefft = abs(fft(input));
figure (2);
plot(f,wavefft);

% downsampling audio file
[P,Q] = rat(500/Fs);
abs(P/Q*Fs-500);
xnew = resample(input,P,Q);
figure (3);
plot(xnew);

% plot in frequency domain downsamplet
n = length(xnew)-1;
f2 = 0:Fs/n:Fs;
wavefft2 = abs(fft(xnew));
figure (4);
plot(f2,wavefft2);

% save downsampled audio file
audiowrite('xnew.wav',xnew,500);
info_ds = audioinfo('xnew.wav');

[input_ds,Fs_ds] = audioread('xnew.wav');
figure (5);
plot(input_ds);

% cut the file to 3 min length and save
samples = [1,180*500];
[input_cut, Fs_cut] = audioread('xnew.wav', samples);

audiowrite('input_cut.wav',input_cut,500);
info_cut = audioinfo('input_cut.wav');

% % play audio with different sample rates (control)
% P_orig = audioplayer(input,44100);
% P_new = audioplayer(input_ds,500);
% play(P_orig);
% stop(P_orig);
% play(P_new);
% stop(P_new);

% extract musical features - envelope
[wa,fs]=wavread('input_cut.wav');

最佳答案

有几种计算包络的方法。您可以使用希尔伯特(Hilbert)变换,或更简单些,仅获取每个样本的绝对值。

对于Hilbert转换选项,您将找到更多信息here

关于matlab - 从wav文件进行Matlab下采样和包络提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42949765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com