How To Clip Wav Files?

  • Follow


Hi everybody,

I'm rather new to Matlab and I have a question as to how to proceed on cutting out several clips of certain time and duration from an original wav file into a new wav file with the original timestamps preserved. I've done some searching around online and the common consensus seems to be the Matlab functions wavread and wavwrite. I've looked on help for Matlab but I am still rather confused as to how to go about in doing this task. Can anybody provide advice as to what I should do?

Thank you,

-Lok
0
Reply Lok 2/11/2011 9:33:05 PM

"Lok" wrote in message <ij49uh$36e$1@fred.mathworks.com>...
> Hi everybody,
> 
> I'm rather new to Matlab and I have a question as to how to proceed on cutting out several clips of certain time and duration from an original wav file into a new wav file with the original timestamps preserved. I've done some searching around online and the common consensus seems to be the Matlab functions wavread and wavwrite. I've looked on help for Matlab but I am still rather confused as to how to go about in doing this task. Can anybody provide advice as to what I should do?
> 
> Thank you,
> 
> -Lok

Hi Lok, Once you use wavread to import the data into MATLAB, it is a vector (If it is a two-channel recording, it will be a Nx2 matrix, but you can just work on one of the columns). You have to use the sampling frequency, which is an optional output of wavread() to create a time vector to serve as your "time stamps". 

Once you know the sampling interval in seconds (fractions thereof..) between the elements of your vector, you can extract whatever portions you need. At that point it's MATLAB indexing.

For example:

Assume the sampling frequency of test.wav is 44.1 kHz

[data,Fs] = wavread('test.wav');
% Fs is 44100
% assuming data is a single-channel recording
N = length(data);
% total duration
totaldur = N/Fs;
% create a time vector
t = linspace(0,totaldur,N);
% I'm using logical indexing here
seg1 = data(t>0.2 & t<0.4);  % get the data between 0.2 and 0.4 seconds


Wayne
0
Reply Wayne 2/12/2011 11:51:04 AM


Lok :
If you just want to clip wav files manually, and don't care how it's
done (by MATLAB or some other program), then you should use Audacity.
It's probably the most-used free audio waveform editor out there:

http://en.wikipedia.org/wiki/Audacity
http://audacity.sourceforge.net/


0
Reply ImageAnalyst 2/12/2011 2:41:46 PM

Hi ImageAnalyst,

Thank you for the suggestion. Can Audacity clip the wav file systematically into sections if given specific timestamps to clip? Any suggestions or pointers on this would be great as well.

Thanks,
Lok

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <03e44b45-dbbc-481c-9da6-5164464e9b19@b8g2000vbi.googlegroups.com>...
> Lok :
> If you just want to clip wav files manually, and don't care how it's
> done (by MATLAB or some other program), then you should use Audacity.
> It's probably the most-used free audio waveform editor out there:
> 
> http://en.wikipedia.org/wiki/Audacity
> http://audacity.sourceforge.net/
> 
0
Reply channlh 2/16/2011 6:34:04 PM

On Feb 16, 1:34=A0pm, "Lok " <chan...@umich.edu> wrote:
> Hi ImageAnalyst,
>
> Thank you for the suggestion. Can Audacity clip the wav file systematical=
ly into sections if given specific timestamps to clip? Any suggestions or p=
ointers on this would be great as well.
>
> Thanks,
> Lok
>
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <03e44b45-dbb=
c-481c-9da6-5164464e9...@b8g2000vbi.googlegroups.com>...
> > Lok :
> > If you just want to clip wav files manually, and don't care how it's
> > done (by MATLAB or some other program), then you should use Audacity.
> > It's probably the most-used free audio waveform editor out there:
>
> >http://en.wikipedia.org/wiki/Audacity
> >http://audacity.sourceforge.net/
---------------------------------------------------------------------------=
---------------
Try it and see, but I don't think so because I don't think it has a
programming environment that can read in a file with start and stop
times.  I think you have to clip/extract the waveform segment manually
by setting their locations in its GUI.
0
Reply imageanalyst (7590) 2/16/2011 6:39:54 PM

Hi Wayne,

Thank you for your help. 
If I have a vector indicating multiple timestamps of where I want to cut, is there a way that I can avoid using 'for loop' and directly index the matrix segments that I want through the data array. Then later save it into a wav file thus cutting out the unwanted portion similar to what you did. 

Thanks again,
Lok

"Wayne King" <wmkingty@gmail.com> wrote in message <ij5s78$ku2$1@fred.mathworks.com>...
> "Lok" wrote in message <ij49uh$36e$1@fred.mathworks.com>...
> > Hi everybody,
> > 
> > I'm rather new to Matlab and I have a question as to how to proceed on cutting out several clips of certain time and duration from an original wav file into a new wav file with the original timestamps preserved. I've done some searching around online and the common consensus seems to be the Matlab functions wavread and wavwrite. I've looked on help for Matlab but I am still rather confused as to how to go about in doing this task. Can anybody provide advice as to what I should do?
> > 
> > Thank you,
> > 
> > -Lok
> 
> Hi Lok, Once you use wavread to import the data into MATLAB, it is a vector (If it is a two-channel recording, it will be a Nx2 matrix, but you can just work on one of the columns). You have to use the sampling frequency, which is an optional output of wavread() to create a time vector to serve as your "time stamps". 
> 
> Once you know the sampling interval in seconds (fractions thereof..) between the elements of your vector, you can extract whatever portions you need. At that point it's MATLAB indexing.
> 
> For example:
> 
> Assume the sampling frequency of test.wav is 44.1 kHz
> 
> [data,Fs] = wavread('test.wav');
> % Fs is 44100
> % assuming data is a single-channel recording
> N = length(data);
> % total duration
> totaldur = N/Fs;
> % create a time vector
> t = linspace(0,totaldur,N);
> % I'm using logical indexing here
> seg1 = data(t>0.2 & t<0.4);  % get the data between 0.2 and 0.4 seconds
> 
> 
> Wayne
0
Reply channlh 2/16/2011 6:48:04 PM

Hi Wayne,

Thank you for your help.
If I have a vector indicating multiple timestamps of where I want to cut, is there a way that I can avoid using 'for loop' and directly index the matrix segments that I want through the data array, then later save it into a wav file thus cutting out the unwanted portion similar to what you did?

Thanks again,
Lok

"Wayne King" <wmkingty@gmail.com> wrote in message <ij5s78$ku2$1@fred.mathworks.com>...
> "Lok" wrote in message <ij49uh$36e$1@fred.mathworks.com>...
> > Hi everybody,
> > 
> > I'm rather new to Matlab and I have a question as to how to proceed on cutting out several clips of certain time and duration from an original wav file into a new wav file with the original timestamps preserved. I've done some searching around online and the common consensus seems to be the Matlab functions wavread and wavwrite. I've looked on help for Matlab but I am still rather confused as to how to go about in doing this task. Can anybody provide advice as to what I should do?
> > 
> > Thank you,
> > 
> > -Lok
> 
> Hi Lok, Once you use wavread to import the data into MATLAB, it is a vector (If it is a two-channel recording, it will be a Nx2 matrix, but you can just work on one of the columns). You have to use the sampling frequency, which is an optional output of wavread() to create a time vector to serve as your "time stamps". 
> 
> Once you know the sampling interval in seconds (fractions thereof..) between the elements of your vector, you can extract whatever portions you need. At that point it's MATLAB indexing.
> 
> For example:
> 
> Assume the sampling frequency of test.wav is 44.1 kHz
> 
> [data,Fs] = wavread('test.wav');
> % Fs is 44100
> % assuming data is a single-channel recording
> N = length(data);
> % total duration
> totaldur = N/Fs;
> % create a time vector
> t = linspace(0,totaldur,N);
> % I'm using logical indexing here
> seg1 = data(t>0.2 & t<0.4);  % get the data between 0.2 and 0.4 seconds
> 
> 
> Wayne
0
Reply channlh 2/21/2011 6:38:04 PM

"Lok" wrote in message <ijubec$n15$1@fred.mathworks.com>...
> Hi Wayne,
> 
> Thank you for your help.
> If I have a vector indicating multiple timestamps of where I want to cut, is there a way that I can avoid using 'for loop' and directly index the matrix segments that I want through the data array, then later save it into a wav file thus cutting out the unwanted portion similar to what you did?
> 
> Thanks again,
> Lok
> 
> "Wayne King" <wmkingty@gmail.com> wrote in message <ij5s78$ku2$1@fred.mathworks.com>...
> > "Lok" wrote in message <ij49uh$36e$1@fred.mathworks.com>...
> > > Hi everybody,
> > > 
> > > I'm rather new to Matlab and I have a question as to how to proceed on cutting out several clips of certain time and duration from an original wav file into a new wav file with the original timestamps preserved. I've done some searching around online and the common consensus seems to be the Matlab functions wavread and wavwrite. I've looked on help for Matlab but I am still rather confused as to how to go about in doing this task. Can anybody provide advice as to what I should do?
> > > 
> > > Thank you,
> > > 
> > > -Lok
> > 
> > Hi Lok, Once you use wavread to import the data into MATLAB, it is a vector (If it is a two-channel recording, it will be a Nx2 matrix, but you can just work on one of the columns). You have to use the sampling frequency, which is an optional output of wavread() to create a time vector to serve as your "time stamps". 
> > 
> > Once you know the sampling interval in seconds (fractions thereof..) between the elements of your vector, you can extract whatever portions you need. At that point it's MATLAB indexing.
> > 
> > For example:
> > 
> > Assume the sampling frequency of test.wav is 44.1 kHz
> > 
> > [data,Fs] = wavread('test.wav');
> > % Fs is 44100
> > % assuming data is a single-channel recording
> > N = length(data);
> > % total duration
> > totaldur = N/Fs;
> > % create a time vector
> > t = linspace(0,totaldur,N);
> > % I'm using logical indexing here
> > seg1 = data(t>0.2 & t<0.4);  % get the data between 0.2 and 0.4 seconds
> > 
> > 
> > Wayne

Hi Lok, In general MATLAB is efficient at indexing an array or vector, but it's hard for me to say for sure in the abstract. Perhaps you can give us a concrete example of what you mean.

Wayne
0
Reply wmkingty (1429) 2/21/2011 7:52:04 PM

Hi Wayne,

Instead of running a "for loop" through the vector of multiple timestamps, is there a way such that I can directly index the matrix elements? So more concretely, my question has to do with "seg1 = data(t>0.2 & t<0.4);". You are manually referencing the part of the vector between 0.2 and 0.4 but is there a way to continually change these parameters without running a for loop?

Thanks,
Lok

"Wayne King" <wmkingty@gmail.com> wrote in message <ijufp4$kdn$1@fred.mathworks.com>...
> "Lok" wrote in message <ijubec$n15$1@fred.mathworks.com>...
> > Hi Wayne,
> > 
> > Thank you for your help.
> > If I have a vector indicating multiple timestamps of where I want to cut, is there a way that I can avoid using 'for loop' and directly index the matrix segments that I want through the data array, then later save it into a wav file thus cutting out the unwanted portion similar to what you did?
> > 
> > Thanks again,
> > Lok
> > 
> > "Wayne King" <wmkingty@gmail.com> wrote in message <ij5s78$ku2$1@fred.mathworks.com>...
> > > "Lok" wrote in message <ij49uh$36e$1@fred.mathworks.com>...
> > > > Hi everybody,
> > > > 
> > > > I'm rather new to Matlab and I have a question as to how to proceed on cutting out several clips of certain time and duration from an original wav file into a new wav file with the original timestamps preserved. I've done some searching around online and the common consensus seems to be the Matlab functions wavread and wavwrite. I've looked on help for Matlab but I am still rather confused as to how to go about in doing this task. Can anybody provide advice as to what I should do?
> > > > 
> > > > Thank you,
> > > > 
> > > > -Lok
> > > 
> > > Hi Lok, Once you use wavread to import the data into MATLAB, it is a vector (If it is a two-channel recording, it will be a Nx2 matrix, but you can just work on one of the columns). You have to use the sampling frequency, which is an optional output of wavread() to create a time vector to serve as your "time stamps". 
> > > 
> > > Once you know the sampling interval in seconds (fractions thereof..) between the elements of your vector, you can extract whatever portions you need. At that point it's MATLAB indexing.
> > > 
> > > For example:
> > > 
> > > Assume the sampling frequency of test.wav is 44.1 kHz
> > > 
> > > [data,Fs] = wavread('test.wav');
> > > % Fs is 44100
> > > % assuming data is a single-channel recording
> > > N = length(data);
> > > % total duration
> > > totaldur = N/Fs;
> > > % create a time vector
> > > t = linspace(0,totaldur,N);
> > > % I'm using logical indexing here
> > > seg1 = data(t>0.2 & t<0.4);  % get the data between 0.2 and 0.4 seconds
> > > 
> > > 
> > > Wayne
> 
> Hi Lok, In general MATLAB is efficient at indexing an array or vector, but it's hard for me to say for sure in the abstract. Perhaps you can give us a concrete example of what you mean.
> 
> Wayne
0
Reply Lok 2/24/2011 12:58:05 AM

8 Replies
209 Views

(page loaded in 2.719 seconds)

Similiar Articles:













7/25/2012 6:30:04 AM


Reply: