To write the FFT function without using the built-in function, we can use the Cooley-Tukey algorithm. Here's the code:
main.m446 chars20 lines
The input to this function is a time-domain signal X
, and the output is the frequency-domain signal Y
. To plot the results, we can use the following code:
main.m496 chars21 lines
This code first sets up the time-domain signal X
and the frequency-domain signal Y
, and then creates time and frequency vectors based on the sampling frequency Fs
and the length of the signal L
. The plot function is then used to plot both the time-domain signal and the frequency-domain signal on separate subplots.
You can then call myFFT
function with your own signal X
and plot the result using this code.
gistlibby LogSnag