-
Notifications
You must be signed in to change notification settings - Fork 1
/
vibrato.m
57 lines (43 loc) · 1.22 KB
/
vibrato.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
55
56
57
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%vibrato.m
%Program author: Akihiro Inui
%Program details: Read audio file and apply simple vibrate
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
close all; clear all; clc;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% 1. Preamble and variable declaration
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Read audio file
[x,Fs] = audioread('filename');
% Sample rate
Ts = 1/Fs;
% Frequency for sine wave
f0 = 2;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% 2. Apply Vibrato to y
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Length of signal in smaples
n = 0:length(x);
% Create sine wave for vibrato
vib = exp(-2*pi*f0*n/Fs).*sin(2*pi*f0*n/Fs);
% Initialise output
y = zeros(1,length(x));
% Multiple the sinusoid to y
for i = 1:length(x)
y(i)= x(i)*vib(i);
end
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% 3. Listen and visualise the output signal
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Normalise output
MaxAmp = max(abs(y));
y = y/MaxAmp;
% Listen to the output signal
soundsc(y,Fs)
% Create a time vector
t = (0:Ts:max(size(x))/Fs - Ts)';
% Plot output signal in frequency domain
plot(t,y)
title('Vibrato output')
xlabel('Time (s)')
ylabel('Amplitude')