Converting Scales after FFT
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
James Kirk
el 29 de Nov. de 2015
Comentada: Star Strider
el 29 de Nov. de 2015
I was hoping someone could help me understand exactly how Matlab's FFT function deals with scaling axes. I am developing some Diffraction code that will simulate Fourier optics but I am hoping to understand how to interpret my results better with a simple example first.
Analytically the Fourier Transform of a f(x) = cos(bx) wave goes to F(k) = dirac(k-b)+dirac(k+b). My code to test this in Matlab is:
steps = 2^8; lim = 4*pi;
x=linspace(-lim, lim,steps);
b = 1;
func = cos(b*x);
Func = fftshift(fft(func));
which when plotted looks like this:
What I am trying to understand is how to rescale my k (spatial frequency) axis so the locations of the delta functions match the analytic result, which in this case should b at k = +/- 1.
This is my first time posting to these forums. Please inform and forgive me if I break any conventions. Any advice you could offer would be greatly appreciated!
0 comentarios
Respuesta aceptada
Star Strider
el 29 de Nov. de 2015
The current R2015b documentation for fft is confusing (at least in my opinion). The R2015a documentation is clearer: fft, but still contains a scaling error w.r.t. plotting a one-sided fft, leaving out the 2 factor.
Calculating the fft as:
Func = fft(func)*2/length(func);
will produce the correct magnitudes.
2 comentarios
Star Strider
el 29 de Nov. de 2015
There is actually only one peak. The frequency axis is imaginary and so the plot of the full fft plots the complex conjugate frequencies, ±jω. For clarity, and since the -jω plot is the mirror-image of the +jω plot, usually the +jω section is the only one plotted.
The full code to do that would be:
steps = 2^8; lim = 4*pi;
x=linspace(-lim, lim,steps);
b = 1;
func = cos(b*x);
Ts = mean(diff(x)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Func = fft(func)*2/steps; % Normalised FFT
Fv = linspace(0, 1, fix(steps/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector (For Plotting)
figure(1)
plot(Fv, abs(Func(Iv)))
grid
axis([0 1 ylim]) % Limit Axis Displayed
xlabel('Frequency (Hz)')
ylabel('Amplitude')
Más respuestas (0)
Ver también
Categorías
Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!