필터 지우기
필터 지우기

audio extraction from individual/selective data column.

조회 수: 5 (최근 30일)
whalelady
whalelady 2020년 4월 15일
답변: Peng Li 2020년 4월 15일
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 );

채택된 답변

Peng Li
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개)

카테고리

Help CenterFile 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!

Translated by