Professional Documents
Culture Documents
Lab 10: Sound Manipulation in Matlab Syntax
Lab 10: Sound Manipulation in Matlab Syntax
wavplay(sound signal,2*fs)
Description
y = wavread(filename) loads a WAVE file specified by the string filename, returning
the sampled data in y. If filename does not include an extension, wavread appends .wav.
[y, Fs] = wavread(filename) returns the sample rate (Fs) in Hertz used to encode the
data in the file.
[y, Fs, nbits] = wavread(filename) returns the number of bits per sample (nbits).
[y, Fs] = wavread(filename, N) returns only the first N samples from each channel in
the file.
[y, Fs] = wavread(filename, [N1 N2]) returns only samples N1 through N2 from
each channel in the file.
1
Signals and Systems Lab DEE, FURC
[y, Fs] = wavread(___, fmt) specifies the data format of y used to represent
samples read from the file. fmt can be either of the following values, or a partial match (case-
insensitive):
Output Scaling
The range of values in y depends on the data format fmt specified. Some examples of
output scaling based on typical bit-widths found in a WAV file are given below for both
'double' and 'native' formats.
Native Formats
Double Formats
2
Signals and Systems Lab DEE, FURC
Examples
Create a WAV file from the example file handel.mat, and read portions of the file back
into MATLAB®.
Example 1
clc
[soundsig,fs,nbits]=wavread('c:\soundlab\road.wav');
left=soundsig(:,1);
right=soundsig(:,2);
L=length(left);
reverse=flipud(left);
wavplay(soundsig,fs);
3
Signals and Systems Lab DEE, FURC
wavplay(sound signal,2*fs)
Example 2
Echo Signal
clc
attn=0.2
td=1;
[signal,fs,nbits]=wavread('c:\soundlab\road.wav');
[signal,echo,ref]=echo11(signal,fs,td,attn)
wavplay(signal,fs);
wavplay(echo,fs);
%Function file
function[sigx,echosig,reflectedsig]=echo11(sig,fs,td,attn);
zer=zeros(td*fs,2);
sigx=[sig;zer];
reflectedsig=[zer;sig*attn];
echosig=sigx+reflectedsig;
4
Signals and Systems Lab DEE, FURC
Example 3
load handel.mat
hfile = 'handel.wav';
clear y Fs
sound(y, Fs);
pause(duration + 2)
nsamples = 2 * Fs;
sound(y2, Fs);
pause(4)
tot_samples = sizeinfo(1);
startpos = tot_samples / 3;
5
Signals and Systems Lab DEE, FURC
endpos = 2 * startpos;
sound(y3, Fs);
%Example 4
load handel
Fs =8192
%sound(y,Fs)
Ts=1/Fs;
t1 = -36556*Ts:Ts:36556*Ts
6
Signals and Systems Lab DEE, FURC
y1=flipud(y);
%sound(y1)
%we need to make the previous sound command to be a command->
%sound(y,Fs)
%down sampling
m=2;
%sound(z);
%to get the result we should make the terms 'sound(y,Fs)& sound(y1)' as
%up sampling
7
Signals and Systems Lab DEE, FURC
%sound(z1)
%to get the result we should make the terms 'sound(y,Fs)& sound(y1)&
sound(z)'
%Example 5