AIM: Study and Implementation of file handling
1. Text
files handling
2. Excel
files handling
3. Audio file handling
THEORY:
1.
Text files Handling:
Generally
we use text files and for doing various documents. We can directly read text files
in Matlab.
Syntax:
For reading text file:
Fid = fopen (‘Text file
name.txt’, ’r’);
Var = fscanf (Fid,’%c or
%d’);
Fclose (Fid)
For Writing text file:
Var = ‘Any text Matter’;
Fid = fopen (‘Text file
name.txt’, ’w’);
fprintf (Fid,’%c or %d’,var);
Fclose (Fid)
|
2. Excel files Handling:
Excel
file consist of cells we can directly access that cells for doing various
operations.
Syntax:
For reading file:
[num, txt] = xlsread(‘excel
file name.xlsx’);
For Writing file:
Var =’Text matter’;
Xlswrite(Var)
|
3. Audio files Handling
Audio file reading in Matlab is
interesting process. Generally wave file are easily readable in Matlab. So aim
of this experiments is
1. How to read audio file in Matlab?
2. How to play audio files in Matlab?
3. How to write audio files in Matlab?
1. Reading Audio file:
Syntax:
y = wavread(filename)
[y, Fs, nbits] = wavread(filename) [...] = wavread(filename, N) [...] = wavread(filename,[N1 N2]) y = wavread(filename, fmt) siz = wavread(filename,'size') [y, fs, nbits, opts] = wavread(...) |
y =
wavread(filename)
loads a WAVE file specified by filename, returning the sampled data in y. The
filename input is a string enclosed in single quotes. The .wav extension is
appended if no extension is given.
[y,
Fs, nbits]
= wavread(filename) returns the sample rate (Fs) in Hertz and the number of
bits per sample (nbits) used to encode the data in the file.
y =
wavread(filename, fmt)
specifies the data type format of y used to represent samples read from the
file. fmt can be either of the
following values.
2.
Playing Audio files:
Syntax:
wavplay(y,Fs)
wavplay(...,'mode')
wavplay(...,'mode')
wavplay(y,Fs) plays the audio signal stored in the vector y on a PC-based
audio output device. You specify the audio signal sampling rate with the
integer Fs
in samples per second. The default value for Fs is 11025 Hz (samples per
second). wavplay
supports only 1- or 2-channel (mono or stereo) audio signals.
wavplay(...,'mode') specifies how wavplay
interacts with the command line, according to the string 'mode'.
3.
Writing Audio file:
Syntax:
wavwrite(y,filename)
wavwrite(y,Fs,filename)
wavwrite(y,Fs,N,filename)
wavwrite(y,Fs,filename)
wavwrite(y,Fs,N,filename)
wavwrite(y,filename) writes the data stored in the
variable y
to a WAVE file called filename.
The filename
input is a string enclosed in single quotes. The data has a sample rate of 8000
Hz and is assumed to be 16-bit. Each column of the data represents a separate
channel. Therefore, stereo data should be specified as a matrix with two
columns.
wavwrite(y,Fs,filename) writes the data stored in the variable y to a WAVE
file called filename.
The data has a sample rate of Fs Hz and is assumed to be
16-bit.
wavwrite(y,Fs,N,filename) writes the data stored in the variable y to a WAVE
file called filename.
The data has a sample rate of Fs Hz and is N-bit, where N is 8, 16, 24,
or 32.
PROCEDURE:
1. First create one text and one excel file in current
directory.
2. Read that text and excel files in Matlab using above
syntax.
3. For writing purpose create variables which contains some
text and use that text to writing purpose using above syntax.
No comments:
Post a Comment