Converting Scales after FFT
6 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152326/image.jpeg)
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 个评论
采纳的回答
Star Strider
2015-11-29
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 个评论
Star Strider
2015-11-29
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!