Sign in

username:

password:



Not a member?

Search compdsp



Search tips

comp.dsp by Keywords

Adaptive Filter | ADPCM | ADSP | ADSP-2181 | Aliasing | AMR | Anti-Aliasing | ARMA | Autocorrelation | AutoCovariance | Beamforming | Bessel | Blackfin | Butterworth | C6713 | CCS | Chebyshev | CIC Filter | Circular Convolution | Code Composer Studio | Comb Filter | Compression | Convolution | Cross Correlation | DCT | Decimation | Deconvolution | Demodulation | DM642 | DSP Boards | DSP/BIOS | DTMF | Echo Cancellation | Equalization | Equalizer | ETSI | EZLITE (Ez-kit Lite) | FFT | FFTW | FIR Filter | Fixed Point | FSK | G.711 | G.723 | G.729 | Gaussian Noise | Goertzel | GPIO | Hilbert Transform | IFFT | IIR Filter | Interpolation | Invariance | JTAG | Kalman | Laplace Transform | Levinson | LPC | McBSP | MIPS | Modulation | MPEG | Multirate | Notch Filter | Nyquist | OFDM | Oversampling | Pink Noise | Pitch | PLL | Polyphase | QAM | QDMA | Quantization | Quantizer | Radar | Random Noise | Reed Solomon | Remez | Resampling | RTDX | Sampling | Sharc | TI C6711 | Undersampling | Viterbi | Wavelets | White Noise | Wiener Filter | Windowing | XDS510PP | Z Transform

Sponsor

DM6467T DaVinci video processor enables H.264 1080p decoding up to 60 fps/eight D1 channel encoding.
Details Here!

Discussion Groups

Free Online Books

See Also

Embedded SystemsFPGAElectronics

Discussion Groups | Comp.DSP | wavread function in MATLAB.

There are 4 messages in this thread.

You are currently looking at messages 0 to 4.


wavread function in MATLAB. - ZikO - 2007-03-14 11:40:00

Hi.

Could anyone help pls. Im trying to read/import wav file into MATLAB by 
using wavread() function.

IM trying to do this:

y = wavread('fm.wav')

or

y = wavread('fm.wav', 1024)

The program shows always the same:

??? Error using ==> wavread
Index exceeds matrix dimensions.

What am i doing it cant be read into the program? if any1 knows what's going 
on, please give me a clue. Regards.


-- 
ZikO
GG 5557876
______________________________
DSPRelated.com's 50,000th member announced! Details Here.

Re: wavread function in MATLAB. - robert bristow-johnson - 2007-03-15 14:00:00



On Mar 14, 11:40 am, "ZikO" <z...@op.pl> wrote:
> Hi.
>
> Could anyone help pls. Im trying to read/import wav file into MATLAB by
> using wavread() function.
>
> IM trying to do this:
>
> y = wavread('fm.wav')
>
> or
>
> y = wavread('fm.wav', 1024)
>
> The program shows always the same:
>
> ??? Error using ==> wavread
> Index exceeds matrix dimensions.
>
> What am i doing it cant be read into the program? if any1 knows what's going
> on, please give me a clue. Regards.

here is a test file that i always use to start out with.  (just delete
the crap after the second wavread() call.  also, you'll need to unwrap
the text because i'm using Google to post and cannot turn off the line
wrap-around.)  anyway, this is a good template file for getting
started reading in wav files and doing stuff (like examining the
spectrum) to it.

FILE: testwav.m

if ~exist('inputFile')

	inputFile = 'sine.wav';

end



fileSize = wavread(inputFile, 'size');



numSamples = 2.^(ceil(log2(fileSize(1))));	% round up to nearest power
of 2



x = zeros(numSamples, 1);		% zero pad if necessary



[inputBuffer, Fs] = wavread(inputFile);



x(1:fileSize(1)) = inputBuffer(:,1);	% if multi-channel, use left
channel only



clear inputBuffer;	% free this memory

clear fileSize;



Ts = 1/Fs;		% Fs is sampling frequency, Ts is sampling period



t = linspace(0, (numSamples-1)*Ts, numSamples)';

f = linspace(-Fs/2, Fs/2 - Fs/numSamples, numSamples)';



X = fft(x);



plot(t, x);

xlabel('time (seconds)');

ylabel('amplitude');

title(['time-domain plot of ' inputFile]);

sound(x, Fs);											% play the sound

pause;









% display both positive and negative frequency spectrum



plot(f, real(fftshift(X)));

xlabel('frequency (Hz)');

ylabel('real part');

title(['real part frequency-domain plot of ' inputFile]);

pause;



plot(f, imag(fftshift(X)));

xlabel('frequency (Hz)');

ylabel('imag part');

title(['imag part frequency-domain plot of ' inputFile]);

pause;



plot(f, abs(fftshift(X)));	% linear amplitude by linear freq plot

xlabel('frequency (Hz)');

ylabel('amplitude');

title(['abs frequency-domain plot of ' inputFile]);

pause;



plot(f, 20*log10(abs(fftshift(X))+1.0e-10));	% dB by linear freq plot

xlabel('frequency (Hz)');

ylabel('amplitude (dB)');

title(['dB frequency-domain plot of ' inputFile]);

pause;






% display only positive frequency spectrum for log frequency scale



semilogx(f(numSamples/2+2:numSamples), 20*log10(abs(X(2:numSamples/
2))));	% dB by log freq plot

xlabel('frequency (Hz), log scale');

ylabel('amplitude (dB)');

title(['dB vs. log freq, frequency-domain plot of ' inputFile]);

pause;



semilogx(f(numSamples/2+2:numSamples), (180/pi)*angle(X(2:numSamples/
2)));	% phase by log freq plot

xlabel('frequency (Hz), log scale');

ylabel('phase (degrees)');

title(['phase vs. log freq, frequency-domain plot of ' inputFile]);

pause;



%

%	this is an alternate method of unwrapping phase

%

%	phase = cumsum([angle(X(1)); angle( X(2:numSamples/2) ./
X(1:numSamples/2-1) ) ]);

%	semilogx(f(numSamples/2+2:numSamples), phase(2:numSamples/2));					%
unwrapped phase by log freq plot

%



semilogx(f(numSamples/2+2:numSamples), unwrap(angle(X(2:numSamples/
2))));	% unwrapped phase by log freq plot

xlabel('frequency (Hz), log scale');

ylabel('unwrapped phase (radians)');

title(['unwrapped phase vs. log freq, frequency-domain plot of '
inputFile]);





______________________________
DSPRelated.com's 50,000th member announced! Details Here.

Re: wavread function in MATLAB. - Fabien Petitgrand - 2007-03-18 11:00:00

Hi,

There is a bug in the Matlab code for wavread.

Your WAVE file is likely to have a FLIST chunk embedded.

If you open the wavread function (open wavread) you will find:

function [opt_ck,msg] = read_listck(fid,ck, orig_opt_ck)

In this function you sohuld just put a 'return' after the line:

listdata = setstr(fread(fid,total_bytes,'uchar')');

Otherwise if there are less than 4bytes in the chunk (which happened to me 
with an Adobe Audition 2.0 created file), the function will raise the error 
you mention on the next line:

listtype = lower(listdata(1:4)); % Get LIST type

Regards,

Fabien


"ZikO" <z...@op.pl> a écrit dans le message de news: 
et9517$t01$1...@news.onet.pl...
> Hi.
>
> Could anyone help pls. Im trying to read/import wav file into MATLAB by 
> using wavread() function.
>
> IM trying to do this:
>
> y = wavread('fm.wav')
>
> or
>
> y = wavread('fm.wav', 1024)
>
> The program shows always the same:
>
> ??? Error using ==> wavread
> Index exceeds matrix dimensions.
>
> What am i doing it cant be read into the program? if any1 knows what's 
> going on, please give me a clue. Regards.
>
>
> -- 
> ZikO
> GG 5557876 


______________________________
DSPRelated.com's 50,000th member announced! Details Here.

Re: wavread function in MATLAB. - Fabien Petitgrand - 2007-03-18 11:02:00

Hi,

There is a bug in the Matlab code for wavread.

Your WAVE file is likely to have a FLIST chunk embedded.

If you open the wavread function (open wavread) you will find:

function [opt_ck,msg] = read_listck(fid,ck, orig_opt_ck)

In this function you sohuld just put a 'return' after the line:

listdata = setstr(fread(fid,total_bytes,'uchar')');

Otherwise if there are less than 4bytes in the chunk (which happened to me
with an Adobe Audition 2.0 created file), the function will raise the error
you mention on the next line:

listtype = lower(listdata(1:4)); % Get LIST type

Regards,

Fabien

"ZikO" <z...@op.pl> a écrit dans le message de news: 
et9517$t01$1...@news.onet.pl...
> Hi.
>
> Could anyone help pls. Im trying to read/import wav file into MATLAB by 
> using wavread() function.
>
> IM trying to do this:
>
> y = wavread('fm.wav')
>
> or
>
> y = wavread('fm.wav', 1024)
>
> The program shows always the same:
>
> ??? Error using ==> wavread
> Index exceeds matrix dimensions.
>
> What am i doing it cant be read into the program? if any1 knows what's 
> going on, please give me a clue. Regards.
>
>
> -- 
> ZikO
> GG 5557876 


______________________________
DSPRelated.com's 50,000th member announced! Details Here.