I'm now learning to use MATLAB to modify and analyze sounds
for experiments. I'd like to know how to edit sound waves
and then save them in a separate folder.
I have 500 wave files, each varies at different time
lengths. For each sound, I just want the first 500ms
segment, and then save them for further analysis in a
different folder (it is okay to discard the leftover).
Except extracting the 1st 500ms segment for each sound,
there is no need to change any other acoustic parameters.
How could I write the m-file, so that I can process them all
at once (e.g. in a loop format).
The signal GUI toolbox only allows me to do one at a time
and it is a very tedious process.
> Hey all,
>
> I'm now learning to use MATLAB to modify and analyze sounds
> for experiments. I'd like to know how to edit sound waves
> and then save them in a separate folder.
>
> I have 500 wave files, each varies at different time
> lengths. For each sound, I just want the first 500ms
> segment, and then save them for further analysis in a
> different folder (it is okay to discard the leftover).
> Except extracting the 1st 500ms segment for each sound,
> there is no need to change any other acoustic parameters.
>
> How could I write the m-file, so that I can process them all
> at once (e.g. in a loop format).
>
> The signal GUI toolbox only allows me to do one at a time
> and it is a very tedious process.
>
> Thanks for reading my inquiry
Lothar Schmidt <vapooroop@gmx.net> wrote in message <g4tr82
$8vh$1@online.de>...
> Damon Ng wrote:
>
> > Hey all,
> >
> > I'm now learning to use MATLAB to modify and analyze
sounds
> > for experiments. I'd like to know how to edit sound
waves
> > and then save them in a separate folder.
> >
> > I have 500 wave files, each varies at different time
> > lengths. For each sound, I just want the first 500ms
> > segment, and then save them for further analysis in a
> > different folder (it is okay to discard the leftover).
> > Except extracting the 1st 500ms segment for each sound,
> > there is no need to change any other acoustic
parameters.
> >
> > How could I write the m-file, so that I can process
them all
> > at once (e.g. in a loop format).
> >
> > The signal GUI toolbox only allows me to do one at a
time
> > and it is a very tedious process.
> >
> > Thanks for reading my inquiry
>
> help wavread
> help wavwrite
>
> you won't need much more.
Except perhaps a detailed read of ML's <dir> function. It
can return the list of files you want to loop through.
On Jul 8, 3:36=A0am, Lothar Schmidt <vapoor...@gmx.net> wrote:
> Damon Ng wrote:
> > Hey all,
>
> > I'm now learning to use MATLAB to modify and analyze sounds
> > for experiments. I'd like to know how to edit sound waves
> > and then save them in a separate folder.
>
> > I have 500 wave files, each varies at different time
> > lengths. For each sound, I just want the first 500ms
> > segment, and then save them for further analysis in a
> > different folder (it is okay to discard the leftover).
> > Except extracting the 1st 500ms segment for each sound,
> > there is no need to change any other acoustic parameters.
>
> > How could I write the m-file, so that I can process them all
> > at once (e.g. in a loop format).
>
> > The signal GUI toolbox only allows me to do one at a time
> > and it is a very tedious process.
>
> > Thanks for reading my inquiry
>
> help wavread
> help wavwrite
>
> you won't need much more.
>
> Lothar
As Lothar wrote, wavread to read the data in, wavwrite to write it
out:
directory =3D 'PUT HERE WHERE YOUR WAVE FILES ARE';
contents =3D dir(directory);
for i =3D 1:length(contents)
in_file =3D contents(i).name;
if (strfind(in_file, '.wav'))
fprintf(1, 'Trimming %s\n', in_file);
On Jul 8, 3:36=A0am, Lothar Schmidt <vapoor...@gmx.net> wrote:
> Damon Ng wrote:
> > Hey all,
>
> > I'm now learning to use MATLAB to modify and analyze sounds
> > for experiments. I'd like to know how to edit sound waves
> > and then save them in a separate folder.
>
> > I have 500 wave files, each varies at different time
> > lengths. For each sound, I just want the first 500ms
> > segment, and then save them for further analysis in a
> > different folder (it is okay to discard the leftover).
> > Except extracting the 1st 500ms segment for each sound,
> > there is no need to change any other acoustic parameters.
>
> > How could I write the m-file, so that I can process them all
> > at once (e.g. in a loop format).
>
> > The signal GUI toolbox only allows me to do one at a time
> > and it is a very tedious process.
>
> > Thanks for reading my inquiry
>
> help wavread
> help wavwrite
>
> you won't need much more.
>
> Lothar
Hmmm this might be a double post, apologies if it is (content is
slightly different anyway):
in_dir =3D 'DIRECTORY CONTAINING WAV FILES';
contents =3D dir(in_dir);
for i =3D 1:length(contents)
in_file =3D contents(i).name;
if (strfind(in_file, '.wav))
fprintf(1, Trimming '%s\n', in_file);
% Read data
[y Fs n_bits] =3D wavread(fullfile(in_dir, in_file));
% Work out how many samples in 0.5 seconds
n_samples =3D round(0.5*Fs);
% Write back out to dile, with TRIMMED_ pre-pended
wavwrite(y(1:n_samples), Fs, n_bits, fullfile(in_dir,
sprintf('TRIMMED_%s', in_file)));
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.