Click to See Complete Forum and Search --> : matlab help needed


sathiapriya
March 28th, 2006, 01:19 PM
how to read wave file in matlab. which coding to use?
my project is about reading signal from wave file such as word 'hi'with duration less then 2.0 sec then use sampling frequency of 11.025kHz to sample it . then must plot the graph for the input signal. amplitude,V-number of samples,n.
any one can help me out with the codes.
with this project i can go on with my final year project or else i need to repeat the subject.
thank you very much

yiannakop
March 29th, 2006, 01:45 AM
I will not provide you full code, since this is for a homework.
---------------------------------------------
To read a wav file you must use function wavread. Suppose you want to read the file test1.wav:

[X,fs,N] = wavread('test1.wav');


(.wav extensions is not necessary...).
The above function returns
X: the signal
fs: sampling frequency
N: number of bits per sample (sample resolution).

Something for the X array (signal): if the audio you read is mono (single channel) the dimensionality of X is 1 (single array). If on the other hand it is stereo (2-channels) the size of X is numOfSamples x 2 (one column for each channel). If you want to do signal processing for signle channel and your file contains stereo sound then you must average the 2 channels into one.

Do help wavread for more info.

---------------------------------------------

To resample your signal to the desired frequency try resample() function of Matlab. This function uses a FIR anti-aliasing filter for this purpose. Do "help resample" for more info.

---------------------------------------------

Then plot the signal you simply have to use function plot(). If only one argument is given in that function, the x-axis is labelled with the number of samples (by default), so nothing special is needed for your case. If, for some reason you want to plot X as a function of time (in seconds), then you must create an array for time as follows:

t = 0:1/fs:(length(X)-1)/fs;


And then do plot(t,X);

Finally, if you want to writ text on the figure (plot) see functions xlabel, ylabel, title, text etc...

Hope I helped you.....

Regards,
Theodore