ubuntu2004
PHAS0029 C9: Fourier Transform - assignment
Part 1: Transforms of basic functions
Task 1: A step function
Comment briefly on the results - are they what you expected? Refer to the standard results you know from PHAS0025 (MMIII).
Hint: Note that, unlike in session 7 where we needed the wave in the form of a function, this can be done simply in a line or two of code. You just need a 1000-element array with every element = +1 for the first half and -1 for the second half.
No matter how many iterations are made when applying Fourier expansion, there will always be a curved region in the plot. This is so that the function does not abruptly jump, as it would in a real square wave. Odd integer harmonics make up the Fourier series of a square wave, and as frequency rises, the amplitude of each harmonic decreases. A succession of spikes at odd integer multiples of the fundamental frequency should therefore be seen as the magnitude of the Fourier coefficients, and this is exactly what is seen in the plot.
Task 2: A single pulse
c.real (correspondingly, the imaginary parts are c.imag)Task 3: Theory vs. result
The square pulse can be roughly approximated by the Fourier series, although there are small differences between the two signals, particularly close to the margins of the pulse. The Gibbs effect, which results in overshoots near discontinuities, is to blame for this. The sharp edges of the pulse are where the overshoot is most obvious. The overshoot persists as the Fourier series' elements count grows. Since Fourier series are better suited for describing continuous, periodic functions, this is a well-known characteristic of these series. As a result, at the discontinuities in functions where they exist, the Fourier series will always show some excess.
Part 2: Analysing audio samples
Task 4
Write a function called
load_data` that loads and analyses a short audio sample using Fourier Transform. Your function should take in a file name as an input and:
- load the data set stored in that file
- plot the first 2000 points only of the data set
- on a separate plot, plot a sub-sample of the data every 500th point
- return the loaded data as an array
Task 5
analyse which takes in a data array and uses FFT to calculate the discrete Fourier Transform of an audio sample then plot the first 10,000 coefficients. Your function should take two arguments: the data array and a label for the plot (a string) and return all FT coefficients.
Task 6
- identify the fundamental's Fourier coefficient index . (Remember - the fundamental is not necessarily the largest peak!)
- use text cells to make at least three sensible observations of the characteristics you observe in your plots.
- determine what note did the instrument play? Give your answer in Hz - musicians are encouraged to also give the name of the note!
Hint: The frequency is related to the Fourier coefficient index by where is the sampling rate and the total number of sampled data points.
General quality of plots
General quality of code comments and docstrings
General quality of text cells