Trinh @ Bath

Differences

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

Link to this comparison view

Next revision
Previous revision
vpde_lecture34 [2020/04/21 08:38]
trinh created
vpde_lecture34 [2020/04/23 08:16] (current)
trinh
Line 1: Line 1:
 ====== Lecture 34: The maths of music I ====== ====== Lecture 34: The maths of music I ======
 +
 +<html>
 +<iframe width="560" height="315" src="https://www.youtube.com/embed/iedsP762EmE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
 +</html>
  
 ===== The Fourier spectra ===== ===== The Fourier spectra =====
Line 46: Line 50:
  
 The last thing I want to show you today is how a computer stores the information of a signal in terms of a Fourier series. Rather than store information about sines and cosines separately, it is more compact to work with complex-valued functions and store the information together.  The last thing I want to show you today is how a computer stores the information of a signal in terms of a Fourier series. Rather than store information about sines and cosines separately, it is more compact to work with complex-valued functions and store the information together. 
 +
 +Matlab uses the fft command to calculate the Fourier series of a signal (technically the discrete Fourier transform). I will not explain it in detail at this point. What you have to understand is that you can put a vector into fft, but to plot the Fourier amplitudes, you need to rearrange the output in a funny way. 
 +
 +<Code:Matlab linenums:1 | Make a sound>
 +N = length(f);
 +yhat = fft(f);
 +A = abs(yhat)/N;
 +K = (Fs/2)*(1:ceil(N/2))/ceil(N/2);
 +A = A(1:ceil(N/2));
 +plot(K, A)
 +</Code>
 +
 +(We noticed during the lecture that the above code is flawed by 1 element, as it indicates a peak frequency of 441Hz instead of 440Hz! I believe this is because you have to 'dump' one of the vector components).