audio extraction from individual/selective data column.

3 views (last 30 days)
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).
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 );

Accepted Answer

Peng Li
Peng Li on 15 Apr 2020
% 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

More Answers (0)

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!