Experiment IV
Experiment IV
PREPARED BY:
1
Part II: Signal Addition
Signal addition example is simply by adding music to a voice file.
Let 𝑥𝑥1 (𝑛𝑛) is a recorded voice and 𝑥𝑥2 (𝑛𝑛) is simply is the music record. We can do the
following: 𝑥𝑥𝑚𝑚𝑚𝑚𝑚𝑚 (𝑛𝑛) = 𝑥𝑥1 (𝑛𝑛) + 𝛼𝛼𝛼𝛼2 (𝑛𝑛), where 𝛼𝛼 is attenuation factor so the music does not
cover the voice signal.
Another way can be adopted by making the music loud when there is no voice and weak
when the voice is loud: 𝑥𝑥𝑚𝑚𝑚𝑚𝑚𝑚 (𝑛𝑛) = 𝑥𝑥1 (𝑛𝑛) + (𝑥𝑥1𝑚𝑚𝑚𝑚𝑚𝑚 − 𝑎𝑎𝑎𝑎𝑎𝑎(𝑥𝑥1 (𝑛𝑛)))𝑥𝑥2 (𝑛𝑛), where 𝑥𝑥1𝑚𝑚𝑚𝑚𝑚𝑚 is
the maximum value of 𝑥𝑥1 (𝑛𝑛).
Follow the following code. Note that the sampling time should be unified for both files.
[y1,fs1]=audioread('preamble10.wav');
[y2,fs2]=audioread('plumclip.wav');
[P,Q] = rat(fs1/fs2);
y2_new = resample(y2,P,Q);
a = max(y1);
for k=1:length(y1)
ysum(k)=y1(k)+0.25*(a-abs(y1(k)))*y2_new(k);
end
sound(ysum,fs1);
[y,fs]=audioread('preamble10.wav');
delay = 0.1; % Delay in seconds
index = round(delay*fs); % Delay in samples
y1 = [zeros(1,index) y]; % Zero pad the beginning to add
delay
y1 = y1(1:length(y)); % Cut vector to correct length
y1 = y1+y; % Add original sound to echo
sound(y1,fs); % Now, lest listen to your reverse audio.
2
Part IV: Music Notations
Musical symbols are marks and symbols in musical notation that indicate various aspects
of how a piece of music is to be performed. There are symbols to communicate information
about many musical elements, including pitch, duration, dynamics, or articulation of
musical notes; tempo, meter, form (e.g., whether sections are repeated), and details about
specific playing techniques (e.g., which fingers, keys, or pedals are to be used, whether a
string instrument should be bowed or plucked, or whether the bow of a string instrument
should move up or down).
Figure 1: An example of music notes using English letters and solfège and their
symbolic and Arabic representations. The figure shows a sample of simple melody where
letters A, B, C, D or Re, Mi, Fa represents the music notes.
Table I: the frequencies and notes for 7 octaves in the piano scale.
Index Note Frequency Index Note Frequency
1 A0 27.50000 45 F4 349.2282
2 A♯0/B♭0 29.13524 46 F♯4/G♭4 369.9944
3 B0 30.86771 47 G4 391.9954
4 C1 32.70320 48 G♯4/A♭4 415.3047
5 C♯1/D♭1 34.64783 49 A4 440
6 D1 36.70810 50 A♯4/B♭4 466.1638
7 D♯1/E♭1 38.89087 51 B4 493.8833
3
8 E1 41.20344 52 C5 523.2511
9 F1 43.65353 53 C♯5/D♭5 554.3653
10 F♯1/G♭1 46.24930 54 D5 587.3295
11 G1 48.9994 55 D♯5/E♭5 622.254
12 G♯1/A♭1 51.9131 56 E5 659.2551
13 A1 55 57 F5 698.4565
14 A♯1/B♭1 58.2705 58 F♯5/G♭5 739.9888
15 B1 61.7354 59 G5 783.991
16 C2 65.40639 60 G♯5/A♭5 830.609
17 C♯2/D♭2 69.29566 61 A5 880
18 D2 73.41619 62 A♯5/B♭5 932.328
19 D♯2/E♭2 77.78175 63 B5 987.767
20 E2 82.40689 64 C6 1046.5
21 F2 87.30706 65 C♯6/D♭6 1108.73
22 F♯2/G♭2 92.49861 66 D6 1174.66
23 G2 97.99886 67 D♯6/E♭6 1244.51
24 G♯2/A♭2 103.8262 68 E6 1318.51
25 A2 110 69 F6 1396.91
26 A♯2/B♭2 116.5409 70 F♯6/G♭6 1479.98
27 B2 123.4708 71 G6 1567.98
28 C3 130.8128 72 G♯6/A♭6 1661.22
29 C♯3/D♭3 138.5913 73 A6 1760
30 D3 146.8324 74 A♯6/B♭6 1864.66
31 D♯3/E♭3 155.5635 75 B6 1975.53
32 E3 164.8138 76 C7 2093.01
33 F3 174.6141 77 C♯7/D♭7 2217.46
34 F♯3/G♭3 184.9972 78 D7 2349.32
35 G3 195.9977 79 D♯7/E♭7 2489.02
36 G♯3/A♭3 207.6523 80 E7 2637.02
37 A3 220 81 F7 2793.83
38 A♯3/B♭3 233.0819 82 F♯7/G♭7 2959.96
39 B3 246.9417 83 G7 3135.96
40 C4 261.6256 84 G♯7/A♭7 3322.44
41 C♯4/D♭4 277.1826 85 A7 3520
42 D4 293.6648 86 A♯7/B♭7 3729.31
43 D♯4/E♭4 311.127 87 B7 3951.07
44 E4 329.6276 88 C8 4186.009
4
Table I represents the first 88 keys of the piano where a sharp (♯) sign means to raises a
note by a semitone and a flat (♭) sign means to lower it by a semitone. Fortunately, there
12 𝑛𝑛−49
exists a formula that maps note index n to frequencies: 𝑓𝑓(𝑛𝑛) = � √2� ∗ 440 Hz.
Exercise 1:
1. What is the difference between A0, A1, A2, …., A7?
2. Would your finding apply for other notes?
Consider adding linear damp: A = exp(0.5.* samples). Or you can add triangular window.
M = length(samples);
5
Exercise 4: Create a polyphonic song
The synthesizer from the previous activities was monophonic, i.e., you could only play a
single note at a time. Make your synthesizer polyphonic, which means that you can play
two tones or more at a time. This allows you to play actual chords. As it turns out, you
can simply add two signals if you want to hear them at the same time, but you have to be
careful that the resulting signal does not exceed values in the range [-1,+1]. Create a
polyphonic tune and save it as a wav-file. Consider the following example:
TMF technology works by having the handset generate tones at specific frequencies and
playing them over the phone line when a button is pressed on the keypad. Equipment at
the other end of the phone line listens to the specific sounds and decodes them into
commands.
These commands are typically used to dial a phone number to call but can also be used to
signal phone control commands or control remote equipment, since the control tones are
played on the same channel as the voice signal [3].
DTMF specifies eight different tones. They are divided into a high group and a low group.
Each key press corresponds to two tones -- hence the name dual tone -- one from the high
group and one from the low group. This allows for 16 total keys [3].
6
Consider the following code [2]:
close all; clear all; clc;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; % Low frequency group
hfg = [1209 1336 1477]; % High frequency group
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];
end
end
Fs = 8000; % Sampling frequency 8 kHz
N = 800; % Tones of 100 ms
t = (0:N-1)/Fs; % 800 samples at Fs
pit = 2*pi*t;
tones = zeros(N,size(f,2));
for toneChoice=1:12,
% Generate tone
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
% Plot tone
subplot(4,3,toneChoice),plot(t*1e3,tones(:,toneChoice));
title(['Symbol "', symbol{toneChoice},'":
[',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'Xlim', [0 25]);
ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
end
set(gcf, 'Color', [1 1 1], 'Position', [1 1 1280 1024])
annotation(gcf,'textbox', 'Position',[0.38 0.96 0.45 0.026],...
'EdgeColor',[1 1 1],...
'String', '\bf Time response of each tone of the telephone
pad', ...
'FitBoxToText','on');
keypad = tones(:,7),Fs,16; % For a Single Tone Output!
Consider: The number 7
sound(keypad)
for i = [1 2 11 1 7 11 4 6 2] % For a Multi Tone Output!
Consider your IUG Student's ID (Mine is: 120170462)
p = audioplayer(tones(:,i),Fs,16);
play(p)
pause(0.5)
end
References:
[1] Christoph Studer, “Module 6: Generating Music with MATLAB” ,2009.
[2] https://www.mathworks.com/matlabcentral/answers/305491-dtmf-tone-using-matlab
[3]
https://www.techtarget.com/searchnetworking/definition/DTMF#:~:text=Dual%20tone%20multi%2Dfrequ
ency%20(DTMF)%20is%20the%20sounds%20or,two%20tones%20at%20specific%20frequencies.