Sei sulla pagina 1di 1

Fourier Transform of Signal

Step-1: fs will represent the sampling frequency of the audio signal.


First, create a variable named fs that contains the value 10.............fs=10
Step-2: t will represent the times when the audio signal was sampled. Remember you can use
a semicolon (;) to suppress the output of a command to prevent cluttering the Command
Window.
Create a vector named t that starts at 0, ends at 20, and whose elements are spaced by 1/fs
t=0:1/fs:20
Step-3: y will represent the audio signal amplitude at each sampled time
Create a variable named y that contains the sum of two sine waves: sin(1.8*2πt) +
sin(2.1*2πt)
y=sin(1.8*2*pi*t)+sin(2.1*2*pi*t)
Step-4: Since the y vector contains the sum of two sine waves with similar frequencies, you
will see a 'beat' pattern.
Plot the y vector (y-axis) against the t vector (x-axis)..............plot(t,y)
Step-5: A Fourier transform returns information about the frequency content of the signal.
You can use the fft function to compute the discrete Fourier transform of a vector.
Create a variable named yfft that contains the discrete Fourier transform of y..........yfft=fft(y)
Step-6: Use the numel function to return the number of elements in an array.
Create a variable named n that contains the number of elements in y.............n=numel(y)
Step-7: The fft function in MATLAB uses only the sampled data to compute the Fourier
transform. The f variable will represent the frequencies that correspond to the values in yfft.
Create a variable named f that contains a vector which starts at 0, ends at fs*(n-1)/n, and
whose elements are spaced by fs/n.....................f=0:fs/n:fs*(n-1)/n
Step-8: The output values from fft are complex numbers. To plot their magnitude, you can
use the abs function.
Plot the expression abs(yfft) (y-axis) against f (x-axis).................plot(f,abs(yfft))
Complete! Notice the two spikes on the left side of the plot which correspond to the
frequencies of the two sine waves you created earlier. Since the spikes are close together, the
signal exhibits the beat phenomenon.

Why are there four spikes? That relates to the Nyquist frequency, which in this case
is 5 (or fs/2). When the input vector consists of real numbers, the fft function always returns
data whose magnitude is symmetric about the Nyquist frequency. That is, the second half of
the plot (after the Nyquist frequency) is just a mirror image of the first half.

Potrebbero piacerti anche