Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

SOUND

MATLAB CODE
clc
[soundsig,fs]=audioread('C:\Users\Awais\Documents\MATLAB\road.wa
v');
left=soundsig(:,1);
right=soundsig(:,2);
L=length(left);
reverse=flipud(left);
sound(soundsig,fs);
% Plot the waveform.
subplot(211)
plot(soundsig),grid;
xlabel('time','fontsize',16)
ylabel('amplitude','fontsize',16)
title('sound signal')
subplot(212)
plot(reverse),grid;
xlabel('time','fontsize',16)
ylabel('amplitude','fontsize',16)
title('sound signal in reverse')

SOUND

GRAPH

Down Sampling
MATLAB CODE
clc
[soundsig,fs]=audioread('C:\Users\Awais\Documents\MATLAB\road.wa
v');
left=soundsig(:,1);
right=soundsig(:,2);
L=length(left);
reverse=flipud(left);
sound(soundsig,0.5*fs);

SOUND

Up Sampling
MATLAB CODE
clc
[soundsig,fs]=audioread('C:\Users\Awais\Documents\MATLAB\road.wa
v');
left=soundsig(:,1);
right=soundsig(:,2);
L=length(left);
reverse=flipud(left);
sound(soundsig,2*fs);

Echo
MATLAB CODE
clc
attn=0.9;
td=1;
[signal,fs]=audioread('C:\Users\Awais\Documents\MATLAB\road.wav'
);
[signal,echo,ref]=echo11(signal,fs,td,attn);
sound(signal,fs);
sound(echo,fs);
% Plot the waveform.
subplot(211)
plot(signal),grid;
xlabel('time','fontsize',16)
ylabel('amplitude','fontsize',16)
title('sound signal')
subplot(212)
plot(echo),grid;
xlabel('time','fontsize',16)
ylabel('amplitude','fontsize',16)
title('echo sound')
%Function file
function[sigx,echosig,reflectedsig]=echo11(sig,fs,td,attn)
zer=zeros(td*fs,2);
sigx=[sig;zer];
3

SOUND

reflectedsig=[zer;sig*attn];
echosig=sigx+reflectedsig;

GRAPH

SOUND

MATLAB CODE
clc
% Create WAV file in current folder.
load handel.mat
hfile = 'handel.wav';
wavwrite(y, Fs, hfile)
clear y Fs
% Read the data back into MATLAB, and listen to audio.
[y, Fs, nbits, readinfo] = wavread(hfile);
sound(y, Fs);
% Pause before next read and playback operation.
duration = numel(y) / Fs;
pause(duration + 2)
% Read and play only the first 2 seconds.
nsamples = 2 * Fs;
[y2, Fs] = wavread(hfile, nsamples);
sound(y2, Fs);
pause(4)
% Read and play the middle third of the file.
sizeinfo = wavread(hfile, 'size');
tot_samples = sizeinfo(1);
startpos = tot_samples / 3;
endpos = 2 * startpos;
[y3, Fs] = wavread(hfile, [startpos endpos]);
sound(y3, Fs);

You might also like