There are 4 messages in this thread.
You are currently looking at messages 0 to 4.
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
______________________________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]);
______________________________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______________________________
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______________________________