-
Notifications
You must be signed in to change notification settings - Fork 0
/
waveexample.m
54 lines (41 loc) · 1.9 KB
/
waveexample.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CMPE 362 Homework II-b %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fs is the frequency = number of samples per second
% y is the actual sound data
hfile = 'laughter.wav'; % This is a string, corresponding to the filename
clear y Fs % Clear unneded variables
%% PLAYING A WAVE FILE
[y, Fs] = audioread(hfile); % Read the data back into MATLAB, and listen to audio.
% nbits is number of bits per sample
%sound(y, Fs); % Play the sound & wait until it finishes
duration = numel(y) / Fs; % Calculate the duration
%pause(duration + 2) % Wait that much + 2 seconds
%% CHANGE THE PITCH
%sound(y(1:2:end), Fs); % Get rid of even numbered samples and play the file
%% EXERCISE I
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Re-arrange the data so that %
% the frequency is quadrupled and play the file %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sound(y(1:4:end), Fs);
pause(duration + 2)
%% EXERCISE II
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Re-arrange the data so that %
% the frequency is halved and play the file %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sound(y(1:(0.5):end), Fs);
pause(duration*2+1)
%% EXERCISE III
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Double Fs and play the sound %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sound(y, Fs*2);
pause(duration + 2)
%% EXERCISE IV
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Divide Fs by two and play the sound %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sound(y, Fs/2);
pause(duration + 2)