From: rudy blabla on
Hi,

I have a problem with writing .wav files. I have this code:

function [] = recwav(t, filename)

Fs=8000;
n=Fs*t;
sample = wavrecord(n,Fs,'int16');
wavwrite(sample, filename);
wavplay(sample,Fs);

plot(sample);
title(filename);

end

but somehow when i playback the written .wav files they are very distorted. I plotted the array of the written file and it looks like the whole array is clipping (the amplitude is much lower!)
what can be wrong?

thank you in advance
From: Jan Simon on
Dear Rudy!

> sample = wavrecord(n,Fs,'int16');
> wavwrite(sample, filename);
> but somehow when i playback the written .wav files they are very distorted.

Did you try to specify FS and NBITS in WAVWRITE as specified in:
help wavwrite
?
Kind regards, Jan
From: Jackie Caplan-Auerbach on
"rudy blabla" <r_schuitema(a)hotmail.com> wrote in message <hi4mh9$i45$1(a)fred.mathworks.com>...
> Hi,
>
> I have a problem with writing .wav files. I have this code:
>
> function [] = recwav(t, filename)
>
> Fs=8000;
> n=Fs*t;
> sample = wavrecord(n,Fs,'int16');
> wavwrite(sample, filename);
> wavplay(sample,Fs);
>
> plot(sample);
> title(filename);
>
> end
>
> but somehow when i playback the written .wav files they are very distorted. I plotted the array of the written file and it looks like the whole array is clipping (the amplitude is much lower!)
> what can be wrong?
>
> thank you in advance

If your data are floating point MATLAB will clip anything over 1. You can either normalize your data to 1 or change the number of bits to 32:

wavwrite(y, Fs, 32, filename)