Trinh @ Bath

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
vpde_lecture35 [2020/04/23 08:16]
trinh
vpde_lecture35 [2020/04/27 17:40] (current)
trinh
Line 1: Line 1:
 ====== Lecture 35: Maths of music II ====== ====== Lecture 35: Maths of music II ======
 +
 +<html>
 +<iframe width="560" height="315" src="https://www.youtube.com/embed/L0HSQ9sJB_I" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
 +</html>
  
 I don't want to dwell on the details of how the fft command works but it is enough to talk about analogies. Suppose we give you an $N$ vector $f_n$ with elements $n = 0, 1, 2, \ldots N-1$ that represents the signal we want to process. I don't want to dwell on the details of how the fft command works but it is enough to talk about analogies. Suppose we give you an $N$ vector $f_n$ with elements $n = 0, 1, 2, \ldots N-1$ that represents the signal we want to process.
Line 35: Line 39:
 This is what the above code does. It takes the Fourier transform (or Fourier series) of f, then plots the amplitudes. The funny code around it is because Matlab places the Fourier transform coefficients in a 'deranged' fashion.  This is what the above code does. It takes the Fourier transform (or Fourier series) of f, then plots the amplitudes. The funny code around it is because Matlab places the Fourier transform coefficients in a 'deranged' fashion. 
  
-===== Real sounds =====+That's a lot to take in. You do not have to understand this theory on fft beyond the basic understanding we presented in Lecture 34. 
  
-That's a lot to take in. The rest is about more fun stuff. +The rest is about more fun stuff. 
  
 +===== Pitch modification =====
 +
 +<Code:Matlab linenums:1 | Pitch>
 +% Example of pitch modification
 +Fs = 2^13; T = 5;
 +t = 0:1/Fs:T;
 +
 +% This is an A note of 440 Hz
 +fA = sin(2*pi*440*t);
 +sound(fA, Fs)
 +
 +%% This is an E note of 659.3 Hz
 +fE = sin(2*pi*659.3*t);
 +sound(fE, Fs)
 +
 +%% We can make our A note sound like an E note
 +%  by essentially changing our definition of 'time' or changing the
 +%  sampling frequency. This is a cheap way of modifying pitch.
 +sound(fA, 659.3/440*Fs)
 +</Code>
 +
 +===== Tuning an instrument =====
 +
 +<Code:Matlab linenums:1 | Tuning>
 +% Example of tuning
 +Fs = 2^13; T = 8;
 +t = 0:1/Fs:T;
 +
 +% This is how tuning works. Play a 440Hz note with an off-tune 442Hz note
 +% signal
 +f = sin(2*pi*440*t) + sin(2*pi*442*t);
 +sound(f, Fs)
 +
 +%%
 +
 +% This is easy to show mathematically. When you add two sine waves together
 +% that differ very slightly in frequency, it gives a beating pattern
 +plot(t, f)
 +</Code>