You are on page 1of 9

Synopsis

y = wavread('wavefile') [y,Fs] = wavread('wavefile') [y,Fs,format] = wavread('wavefile')

Description
y = wavread('wavefile') loads the .WAV file wavefile, returning the sampled data in y. If wavefile does not include a file extension, the function assumes .WAV. [y,Fs] = wavread('wavefile') returns the sample rate Fs. [y,Fs,format] = wavread('wavefile') returns the six-element vector format, where format(1) is the data format. This is always the string 'PCM'. format(2) is the number of channels. format(3) is the sample rate (Fs). format(4) is the average bytes per second (sampled). format(5) is the block alignment of the data. format(6) is the number of bits per sample. This function currently supports only 8-bit, single channel data.

wning Class: audio Installed With: Full Development System (Windows)

Syntax
Y = wavread(file) SIZE = wavread(file, 'size') [Y, fs, NBITS] = wavread(file) [Y, fs, NBITS] = wavread(file, n) [Y, fs, NBITS] = wavread(file, [n1 n2])

Description
Reads a Microsoft .wav file. Details Examples

Inputs
Name Description file Specifies the filename of the .wav file you want to read. You can use an absolute path or a path relative to the current working directory. LabVIEW adds a .wav extension to the filename if

you do not provide the extension. file is a string. 'size' Directs LabVIEW to return the size of the audio data in file. n Directs LabVIEW to return only the first n samples from each channel in file. Specifies the first sample in the range of samples that LabVIEW returns from each channel in n1 file. Specifies the last sample in the range of samples that LabVIEW returns from each channel in n2 file.

Outputs
Name Description Returns the sampled data with amplitude values in the range [-1, 1]. Each column of Y Y represents one channel. Y is a real matrix. Returns the size of the audio data in file. The first element in SIZE is the number of samples SIZE in file. The second element in SIZE is the number of channels in file. SIZE is a two-element vector of integers. fs Returns the sampling rate in Hz. fs is a real number. NBITS Returns the number of bits per sample used to encode the data in file. NBITS is an integer.

Examples
t = 0:0.01:10*pi; z = sin(50*t.^2); wavplay(z') wavwrite(z, 'C:\chirp'); clear z; pause(2); z = wavread('C:\chirp'); wavplay(z) plot(t, z)

Synopsis
wavwrite('wavefile',y,Fs)

Description
wavwrite('wavefile',y,Fs) writes the 8-bit sampled data y, with sample rate Fs, to the file wavefile. wavwrite creates an 8-bit, single channel file. The function truncates sample data of more than eight bits.

Syntax
wavwrite(Y, file)

wavwrite(Y, fs, file) wavwrite(Y, fs, NBITS, file)

Description
Writes data to a Microsoft .wav file. Details Examples

Inputs
Name Description Specifies the wave data you want to write to file. Each column of Y represents one channel. Y Specify two columns for stereo data. Y is a real matrix. Specifies the filename to which you want to write the wave data in Y. You can use an absolute file path or a path relative to the current working directory. file is a string. fs Specifies the sampling rate in Hz. fs is a real number. The default is 8000. Specifies the number of bits to use to encode the wave data in Y. NBITS must be 8, 16, 24, or NBITS 32. The default is 16.

Examples
t = 0:0.01:10*pi; z = sin(50*t.^2); wavplay(z') wavwrite(z, 'C:\chirp'); clear z; pause(2); z = wavread('C:\chirp'); wavplay(z) plot(t, z)

plot
Purpose
Linear 2-D plot.

Synopsis
plot(Y) plot(X,Y) plot(X,Y,'linetype') plot(X1,Y1,'linetype1',X2,Y2,'linetype2',...) h = plot(...)

Description
plot(Y) plots the columns of Y versus their index. If Y is complex, plot(Y) is equivalent to plot(real(Y),imag(Y)). In all other uses of plot, the imaginary part is ignored. plot(X,Y) plots vector X versus vector Y. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. Various line types, plot symbols and colors can be obtained with plot(X,Y,'linetype') where linetype is a 1-, 2-, or 3-character string made from the following characters:
---------------------------. point y yellow o circle m magenta x x-mark c cyan + plus r red * star g green solid line b blue : dotted line w white -. dashdot line k black - dashed line ----------------------------

For example, plot(X,Y,'c+') plots a cyan plus at each data point. plot(X1,Y1,'linetype1',X2,Y2,'linetype2',...) combines the plots defined by the (X,Y,linetype1') triples, where the X's and Y's are vectors or matrices and the linetypes are strings. For example, plot(X,Y,'-',X,Y,'go') plots the data twice, with a solid yellow line interpolating green circles at the data points. The plot command, if no color is specified, makes automatic use of the colors in the above table. The default is yellow for one line, and for multiple lines, to cycle through the first six colors in the table. h = plot(...) returns a column vector of handles to line objects, one handle per line. The line objects that plot creates are children of the current axes. The X,Y pairs, or X, Y, linetype triples, can be followed by parameter value pairs to specify additional properties of the lines. See line for more information.

fopen
Purpose
Open a file or obtain information about open files.

Synopsis
fid = fopen('filename') fid = fopen('filename', 'permission') [fid, message] = fopen('filename','permission', 'architecture') fids = fopen('all') [filename, permission, architecture] = fopen(fid)

Description
fid = fopen('filename') opens the file in filename and returns fid, the file identifier. fopen('filename','permission') opens the file filename in the mode specified by permission. Legal file permission strings are
------------------------------------------------------------'r' Open the file for reading (default). 'r+' Open the file for reading and writing. 'w' Delete the contents of an existing file or create a new file, and open it for writing. 'w+' Delete the contents of an existing file or create new file, and open it for reading and writing. 'a' Create and open a new file or open an existing file for writing, appending to the end of the file. 'a+' Create and open new file or open an existing file for reading and writing, appending to the end of the file. -------------------------------------------------------------

You can also add a 'b' to these strings, for example, 'rb', on systems that distinguish between text and binary files. Under DOS and VMS, for example, you cannot read a binary file unless you set the permission to 'rb'. If fopen successfully opens the file, it returns a file identifier fid, which is an integer greater than two, and the value of message is empty. The fid is used with other file I/O routines to identify the file on which to perform the operations. Three fids are predefined: 0 corresponds to standard input, which is always open for reading (permission set to 'r'), 1 corresponds to standard output, which is always open for appending (permission set to 'a'), and 2 corresponds to standard error, which is always open for appending (permission set to 'a'). Standard input, output and error cannot be explicitly opened or closed. If fopen does not successfully open the file, it returns a -1 value for fid. In that case, the value of message is a string that can help you determine the type of error that occurred. [fid, message] = fopen('filename','permission', 'architecture') defines the numeric format of the file, architecture, allowing you to share files between machines of different architectures. The argument can be one of these strings:
--------------------------------------------------------------'native' or 'n' The numeric format of the machine you are currently running 'ISIEEE-LE' or 'l' IEEE Little Endian formats 'ISIEEE-BE' or 'b' IEEE Big Endian formats 'vaxdv' or 'd' VAX D-float format 'vaxg' or 'gv' VAX G-float format 'crayv' or 'c' Cray numeric format ---------------------------------------------------------------

You can omit the 'architecture' argument. If you do, the numeric format of the local machine is used. Individual calls to fread or fwrite can override the numeric format specified in a call to fopen. fopen('all') returns a row vector containing the file identifiers of all open files, including 0, 1, and 2. The number of elements in the vector is equal to the number of open files.

[filename, permission, architecture] = fopen(fid) returns the filename string, the permission string, and the architecture string associated with the specified file. An invalid fid returns empty strings for all output arguments. Both permission and architecture are optional. [x,fs] = wavread('file'); t = (1:length(x))/fs; >> plot(t,real(x));

A Couple Examples
To create a simple sinusoidal signal:
fs = 44100; T = 1/fs; t = [0:T:0.25]; f1 = 50; omega1 = 2*pi*f1; phi = 2*pi*0.75; x1 = cos(omega1*t + phi); plot(t, x1); xlabel('Time (seconds)'); ylabel('x1'); title('Simple Sinusoid'); sound(0.9*x1, fs); % sampling rate % sampling period % time vector % frequency in Hertz % angular frequency in radians % arbitrary phase offset = 3/4 cycle % sinusoidal signal, amplitude = 1 % plot the signal

% play the signal

To create a more complex signal composed of many sinusoids:


phi = 2 * pi * 0.25; x1 = cos(omega1*t + phi); x2 = cos(2*pi*150*t + phi)/3; x3 = cos(2*pi*250*t + phi)/5; x4 = cos(2*pi*350*t + phi)/7; x5 = cos(2*pi*450*t + phi)/9; % % % % % % 1/4 cycle phase offset sinusoidal signal, amplitude sinusoidal signal, amplitude sinusoidal signal, amplitude sinusoidal signal, amplitude sinusoidal signal, amplitude = = = = = 1 1/3 1/5 1/7 1/9

xcomplex = x1 + x2 + x3 + x4 + x5; plot(t, xcomplex); xlabel('Time (seconds)'); ylabel('xcomplex'); title('More Complex Signal'); sound(0.9*xcomplex, fs); % play the signal

Matlab Audio I/O


Matlab provides a few built-in functions that allow one to import and export audio files. As well, AIFF file support is available

Audio files formatted with the Microsoft WAV format can be read and written to/from Matlab using the built-in wavread and wavwrite functions. Audio files formatted with the NeXT/SUN audio file format can be read and written to/from Matlab using the built-in auread and auwrite functions. Audio files formatted with the Macintosh AIFF audio file format can be read and written to/from Matlab using the external aiffread and aiffwrite functions. Signal can be played out the computer audio hardware in most versions of Matlab via the sound (unnormalized) or soundsc (normalized) functions. Example Matlab script and soundfile: wavinout.m, guitar.wav

Computing Audio Spectra in Matlab


The fft function computes the FFT of a specified signal. In general, we will want to view either the magnitude or phase values of the FFT coefficients, which in Matlab can be determined using the abs and angle functions. A variety of windows can be applied to a signal before the computation of the FFT using the functions hann, hamming, blackman. For a complete list, see the window function help. Time-domain windows can help minimize spectral artifacts related to signal truncation. The specgram function computes a time-frequency plot of a signal where color represents spectral magnitude amplitude. Example Matlab script and soundfile: wavfft.m, triangle.wav

Other Useful Functions


The clear function clears all Matlab variables. Individual variables can be cleared by specifying them as arguments to the clear function. Matlab provides a ``C-like'' fprintf function to format output data to a file or the terminal.

Writing Matlab Functions


It is relatively easy to create your own Matlab functions. An example is included below:
function y = dumbfun(x, z) % DUMBFUN An example Matlab function. % % Y = DUMBFUN(X,Z) doesn't do much. The Z parameter is optional % and should either be a scalar or equal in size to X. % % By Gary P. Scavone, McGill University, 2004. if nargin>1 & z>0, if size(z) == [1 1] | size(z) == size(x), y = 0.5.*x + z; else error('Parameter Z size error.'); return

end else y = 0.4.*x; end

Well designed Matlab functions will check argument values and sizes to avoid undefined conditions. Example Matlab function: dumbfun.m A spectrogram is a time-varying spectral representation[1] (forming an image) that shows how the spectral density of a signal varies with time. Also known as spectral waterfalls, sonograms, voiceprints, or voicegrams, spectrograms are used to identify phonetic sounds, to analyse the cries of animals; they were also used in many other fields including music, sonar/radar, speech processing,[2] seismology, etc. The instrument that generates a spectrogram is called a spectrograph and is equivalent to a sonograph

The most common format is a graph with two geometric dimensions: the horizontal axis represents time, the vertical axis is frequency; a third dimension indicating the amplitude of a particular frequency at a particular time is represented by the intensity or colour of each point in the image. There are many variations of format: sometimes the vertical and horizontal axes are switched, so time runs up and down; sometimes the amplitude is represented as the height of a 3D surface instead of color or intensity. The frequency and amplitude axes can be either linear or logarithmic, depending on what the graph is being used for. Audio would usually be represented with a logarithmic amplitude axis (probably in decibels, or dB), and frequency would be linear to emphasize harmonic relationships, or logarithmic to emphasize musical, tonal relationships

Spectrograms are usually created in one of two ways: approximated as a filterbank that results from a series of bandpass filters (this was the only way before the advent of modern digital signal processing), or calculated from the time signal using the short-time Fourier transform (STFT). These two methods actually form two different quadratic Time-Frequency Distributions, but are equivalent under some conditions. The bandpass filters method usually uses analog processing to divide the input signal into frequency bands; the magnitude of each filter's output controls a transducer that records the spectrogram as an image on paper.[3] Creating a spectrogram using the STFT is usually a digital process. Digitally sampled data, in the time domain, is broken up into chunks, which usually overlap, and Fourier transformed to calculate the magnitude of the frequency spectrum for each chunk. Each chunk then corresponds to a vertical line in the image; a measurement of magnitude versus frequency for a specific moment in time. The spectrums or time plots are then "laid side by side" to form the image or a three-dimensional surface.[4] The spectrogram of a signal s(t) can be estimated by computing the squared magnitude of the STFT of the signal s(t), as follows:[5]

By reversing the process of producing a spectrogram, it is possible to create a signal whose spectrogram is an arbitrary image. This technique can be used to hide a picture in a piece of audio and has been employed by several electronic music artists.[10] See also steganography.

Network Steganography
All information hiding techniques that may be used to exchange steganograms in telecommunication networks can be classified under the general term of network steganography. This nomenclature was originally introduced by Krzysztof Szczypiorski in 2003.[7] Contrary to the typical steganographic methods which utilize digital media (images, audio and video files) as a cover for hidden data, network steganography utilizes communication protocols' control elements and their basic intrinsic functionality. As a result, such methods are harder to detect and eliminate.[8] Typical network steganography methods involve modification of the properties of a single network protocol. Such modification can be applied to the PDU (Protocol Data Unit),[9][10][11] to the time relations between the exchanged PDUs,[12] or both (hybrid methods).[13] Moreover, it is feasible to utilize the relation between two or more different network protocols to enable secret communication. These applications fall under the term inter-protocol steganography.[14] Network steganography covers a broad spectrum of techniques, which include, among others: Steganophony - the concealment of messages in Voice-over-IP conversations, e.g. the employment of delayed or corrupted packets that would normally be ignored by the receiver (this method is called LACK - Lost Audio Packets Steganography), or, alternatively, hiding information in unused header fields.[15] WLAN Steganography the utilization of methods that may be exercised to transmit steganograms in Wireless Local Area Networks. A practical example of WLAN Steganography is the HICCUPS system (Hidden Communication System for Corrupted Networks)

You might also like