Matlab 下采样和从 wav 文件中提取包络
Matlab downsampling and Envelope extraction from wav File
我对下面的代码有疑问,因为我不确定我的程序是否正确以及代码是否确实按照我的要求执行。
我有一个音频文件“03 Black Smoke.wav”,这个音频文件我必须下采样到 500 Hz。
之后,我必须将音频文件剪切到 最大长度 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');
有几种计算包络的方法。您可以使用希尔伯特变换,或者更简单,只取每个样本的绝对值。
对于希尔伯特变换选项,您会找到更多信息 here。
我对下面的代码有疑问,因为我不确定我的程序是否正确以及代码是否确实按照我的要求执行。
我有一个音频文件“03 Black Smoke.wav”,这个音频文件我必须下采样到 500 Hz。 之后,我必须将音频文件剪切到 最大长度 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');
有几种计算包络的方法。您可以使用希尔伯特变换,或者更简单,只取每个样本的绝对值。
对于希尔伯特变换选项,您会找到更多信息 here。