Extracting a segment from sound file

Hi,
I have a wave file of 100 seconds. And I have a excel file where I marked some areas of that file with start and stop times. like first segment: 2.5 to 3.4 seconds, second segment: 4.6 to 5.2 seconds and so on.
Now, I want to do the following things:
1. I first read the wav file, 2. then read the excel file for start and stop times, 3. then cut the segments from the wave file according to the excel file.
I know the 1st and 2nd part. but stuck in the 3rd one. Please let me know, how to do the 3rd part for this.

3 commentaires

Image Analyst
Image Analyst le 31 Oct 2014
It would make it easier for people to develop some simple code for you if you attached the wav and xlsx files.
Odrisso
Odrisso le 31 Oct 2014
Hi Analyst,
Here is the code: Here tt is the file with two columns which I extracted from excel.
  • [x,fs] = audioread('15.wav');
  • [M,N] = size(x);
  • L = size(tt,1);
  • for k = 1:L
  • a = x(tt(k,1)*fs+1:tt(k,2)*fs);
  • end
By a, I can find the amplitude values for all marked areas.
But, when I want to see separately each individual area, it shows error of dimensional mismatch. I know this error come because the dimension is not same for each marked file. Now, I can't zero pad them because if I do so the average value will be changed.
So, please let me know, how can I extract every segment and store in different variables.
Image Analyst
Image Analyst le 31 Oct 2014
I think this was maybe a reply for Rick. I didn't ask for this. I suggested you attach the two files . You can still do that. Click paperclip, then "Choose file" then "Attach file". You have to do each one at a time, you can't multi-select files.

Connectez-vous pour commenter.

Réponses (1)

Rick Rosson
Rick Rosson le 31 Oct 2014
Modifié(e) : Rick Rosson le 1 Nov 2014
Here are a few pages from the documentation that will help:
And here is a possible solution that should get you started:
[x,Fs] = audioread('myaudiofile.wav');
[M,N] = size(x);
dt = 1/Fs;
t = dt*(0:M-1)';
figure;
plot(t,x);
segments = xlsread('mydatafile.xlsx','C15:D24');
L = size(segments,1);
for k = 1:L
idx = ( segments(k,1) < t ) & ( t < segments(k,2) ) ;
figure;
plot(t(idx),x(idx));
end

3 commentaires

Odrisso
Odrisso le 31 Oct 2014
HI Rosson,
thanks for your answer.
But, the excel file in the seconds(start and stop time). I need to segment the wave file according to this seconds. I mean, I want to extract the sampled data for only those seconds.
Rick Rosson
Rick Rosson le 31 Oct 2014
I had not finished my answer yet. Please check it now.
Odrisso
Odrisso le 31 Oct 2014
Hi ,
Thanks a lot. But, I don't want to plot them. I just want to save them in a variable. So from your code I develop this:
Here is the code: Here tt is the file with two columns which I extracted from excel.
  • [x,fs] = audioread('15.wav');
  • [M,N] = size(x);
  • L = size(tt,1);
  • for k = 1:L
  • a = x(tt(k,1)*fs+1:tt(k,2)*fs);
  • endBy a, I can find the amplitude values for all marked areas.
But, when I want to see separately each individual area, it shows error of dimensional mismatch. I know this error come because the dimension is not same for each marked file. Now, I can't zero pad them because if I do so the average value will be changed.
So, please let me know, how can I extract every segment and store in different variables.

Connectez-vous pour commenter.

Question posée :

le 31 Oct 2014

Modifié(e) :

le 1 Nov 2014

Community Treasure Hunt

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

Start Hunting!

Translated by