我对下面的代码有疑问,因为我不确定我是否对所有程序都进行了正确的编程,以及代码是否真的做了我想让他做的事情。
我有一个音频文件“03 Black Smoke.wav”,这个音频文件我必须下采样到 500 Hz。 之后,我必须将 Audiofile 剪切到3 min 的最大长度。
代码是否正确进行了下采样?
有人可以给我一个提示,我如何从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');