audio extraction from individual/selective data column.
1 次查看(过去 30 天)
显示 更早的评论
Would be glad if someone could help me with this question.
In my 'data', there are two columns. I am trying to run the code below on only the second column and extract it's data to replace with the original data (with both coloumns).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284627/image.png)
If I just purely run the below code, the script will run on the first column,
how do I choose the second column, or insert data (:,end) to this working code?
[data,samp_rate] = audioread(Audio_files(p).name);
%% equations worked on the audio file and get s, the new starting point of the audio
startSample = s;
endSample = length(data);
extractedData = data(startSample:endSample);
extractedData(1:2*samp_rate ) = [];
audiowrite(Audio_files(p).name '.m4a', extractedData,samp_rate );
I tried inserting data(:,end) like how it is written below, but it aint working.
[data,samp_rate] = audioread(Audio_files(p).name);
%% equations worked on the audio file and get s, the new starting point of the audio
xdata = data(:,end) %choose the second column and save into xdata
startSample = s;
endSample = length(xdata);
extractedData = xdata(startSample:endSample);
extractedData(1:2*samp_rate ) = [];
audiowrite(Audio_files(p).name '.m4a', extractedData,samp_rate );
0 个评论
采纳的回答
Peng Li
2020-4-15
% it seems from the screenshot that your data is n by 2 matrix
% thus length(data) only gives you n
% endSample = length(data);
% better:
endSample = size(data, 1);
% again your data is n by 2, this way, you end up with extracting only the
% first column
% extractedData = data(startSample:endSample);
% do this way if you want to work on the second column
extractedData = data(startSample:endSample, 2);
what error was shown for your second part of the code?
audioread gives you option to select samples to read. You don't need to read them all and extract what you want from there like you've done. see https://www.mathworks.com/help/matlab/ref/audioread.html#btiabil-1-samples
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!