My signal is a static 1D pattern detected by the linear photodiode array with N pixels and pitch p.
What units will I get along the X-axis after FFT to spectrum?
If you have a signal f(x) with unit U depending on variable x with unit V. Then
the continuous Fourier transform of f has unit UV and depends on a variable with unit 1/V.
Example 1: f(x) is a Voltage with x being time. then the Fourier transform has unit Vs (or V/Hz) versus variable 1/s (or Hz).
Example 2: f(x) is a power with x being space. Then the FT has unit Wm and the x axis (which is then a wavenumber) unit 1/m (this is probably your case).
the Discrete Fourier transform (or FFT) has unit U (same as original) and depends on a discrete variable, (which has with unit 1 by definition because it is just a counter).
So the units of the X-Axis of a FFT are 1 (because it is a counter).
I included the continuous Fourier transform, because I suspect that you just confused the FFT (which is just the name of an algorithm for the discrete Fourier transform by the way) with the ordinary (continuous) Fourier transform.
Let me clarify my above question because of the shortage of initial meaningful data.
The question was related with inverse FT of a spatial interferogram (a.k.a. fringe pattern) formed from the optical radiation by a static Fourier-transform spectrometer and detected with a linear photo diode array to reconstruct finally the optical spectrum.
Therefore, the mathematically formal answer "So the units of the X-Axis of a FFT are 1 (because it is a counter)" is absolutely right.
Related
I am trying to plot an amplitude spectrum of a signal.
Here is the code:
%My signal: y = 0.001*cos(0.005*pi*t+pi/4);
A = 0.001;
T = 400;
f = 0.0025;
pi = 3.14;
syms m
m=-1:1;
wm=(1/T)*(int((0.001*cos(0.005*pi*t + pi/4))*exp(-j*m*0.005*pi*t),t,0,T));
ww=double(wm);
Amp=abs(ww);
fi=angle(ww);
w=m*2*pi/T;
f=w/(2*pi);
figure('Name','Amplitude spectrum');
stem(f,Amp,'linewidth',2,'color','r'),grid on;
title('Amplitude spectrum'), xlabel('?[rad/s]'), ylabel('|wm|');
But it's plotted with a wrong amplitude. 5x10^-4 instead of 5x10^-3.
Where did I do the mistake?
The magnitude of your plot is correct.
The magnitudes of the impulses located at the fundamental frequency come from the scale of the cosine wave and get divided by 2: 0.001 / 2 = 5e-4. This is because the cos function can be expressed using Euler's formula such that it is a combination of two complex exponentials that are both scaled by half.
Source: Wikipedia
As such, the Fourier Transform of a complex exponential at the desired frequency is a unit-length impulse (i.e. the magnitude is 1). The cosine wave can be expressed as two complex exponentials centered at the positive and negative versions of the fundamental frequency. We further scale by 1/2 due to Euler's formula and with the property of linearity for the Fourier Transform, the impulses additionally get scaled by 1/2. You further have an additional scaling factor for your cosine wave, which scales the impulses yet again. The combination of scales: (1)(1/2)(0.001) thus gives 5e-4.
There's nothing wrong with that output. Also, your scale should be in Hertz, not rad/s. This is because of the formulation of your exponential has pi in it.
I can understand why you'd want to use the symbolic toobox here, but I highly recommend using fft instead. There's no need to get a slow symbolic calculator to compute the frequency representation of a signal when the fft is a faster algorithm to do so. If you are doing this purely to verify what the theoretical magnitude response is for your signal, then that's fine but do not do this when calculating the frequency response in practice.
While trying to understand Fast Fourier Transform I encountered a problem with the phase. I have broken it down to the simple code below. Calculating one period of a 50Hz sinewave, and applying an fft algorithm:
fs = 1600;
dt = 1/fs;
L = 32;
t=(0:L-1)*dt;
signal = sin(t/0.02*2*pi);
Y = fft(signal);
myAmplitude = abs(Y)/L *2 ;
myAngle = angle(Y);
Amplitude_at_50Hz = myAmplitude(2);
Phase_at_50Hz = myAngle(2);
While the amplitude is ok, I don't understand the phase result. Why do I get -pi/2 ? As there is only one pure sinewave, I expected the phase to be 0. Either my math is wrong, or my use of Matlab, or both of them... (A homemade fft gives me the same result. So I guess I am stumbling over my math.)
There is a similar post here: MATLAB FFT Phase plot. However, the suggested 'unwrap' command doesn't solve my problem.
Thanks and best regards,
DanK
The default waveform for an FFT phase angle of zero is a cosine wave which starts and ends in the FFT window at 1.0 (not a sinewave which starts and ends in the FFT window at 0.0, or at its zero crossings.) This is because the common nomenclature is to call the cosine function components of the FFT basis vectors (the complex exponentials) the "real" components. The sine function basis components are called "imaginary", and thus infer a non-zero complex phase.
That is what it should be. If you used cosine, you would have found a phase of zero.
Ignoring numerical Fourier transforms for a moment and taking a good old Fourier transform of sin(x), which I am too lazy to walk through, we get a pair of purely imaginary deltas.
As for an intuitive reason, recall that a discrete Fourier transform is averaging a bunch of points along a curve in the complex plane while turning at the angular frequency of the bin you're computing and using the amplitude corresponding to the sample. If you sample a sine curve while turning at its own frequency, the shape you get is a circle centered on the imaginary axis (see below). The average of that is of course going to be right on the imaginary axis.
Plot made with wolfram alpha.
Fourier transform of a sine function such as A*sin((2*pi*f)*t) where f is the frequency will yield 2 impulses of magnitude A/2 in the frequency domain at +f and -f where the associated phases are -pi/2 and pi/2 respectively.
You can take a look at its proof here:
http://mathworld.wolfram.com/FourierTransformSine.html
So the code is working fine.
I have a time varying signal (a), which I take the fft of. I need to multiply a frequency dependent weighting factor by the fft's y axis value; however if I do:
xdft = fft(a);
xdft = xdft(1:length(x)/2+1); % only retaining the positive frequencies
freq = Fs*(0:(L/2))/L;
And plot(freq,xdft) I get a peak fft value (y axis)of ~2000 at the correct frequency of the signal. But original signal peak value (amplitude) was ~46. I need to know how the numbers relate so I can weight the fft values.
You forgot to divide by the DFT length. Take a look at this example.
Consider that the output of fft is complex. So if you want to plot the real power spectral density you should multiply the output by its complex conjugate like this:
Pyy = xdft.*conj(xdft)/L;
Edit:
For the amplitude spectrum you should do something like this:
xdft=abs(xdft/L); % same as sqrt(xdft.*conj(xdft))/L
Y=xdft(1:L/2+1); % copy half of data since the other half is redundant
Y(2:end-1) = 2*Y(2:end-1); % correct the amplitudes
Edit 2:
Just wanted to point to a really great book (the best in my opinion) which explains how fourier series work (and much more) in a really easy and understandable way.
Alan V. Oppenheim, Alan S. Willsky, and S. Hamid Nawab. 1996. Signals & Systems (2nd Ed.). Prentice-Hall, Inc., Upper Saddle River, NJ, USA.
I am not doing signal processing. But in my area, I will use the spectral density of a matrix of data. I get quite confused at a very detailed level.
%matrix H is given.
corr=xcorr2(H); %get the correlation
spec=fft2(corr); % Wiener-Khinchin Theorem
In matlab, xcorr2 will calculate the correlation function of this matrix. The lag will range from -N+1 to N-1. So if size of matrix H is N by N, then size of corr will be 2N-1 by 2N-1. For discretized data, I should use corr or half of corr?
Another problem is I think Wiener-Khinchin Theorem is basically for continuous function. I have always thought that Discretized FT is an approximation to Continuous FT, or you can say it is a tool to calculate Continuous FT. If you use matlab build in function 'fft', you should divide the final result by \delta x.
Any kind soul who knows this area well there to share some matlab code with me?
Basically, approximating a continuous FT by a Discretized FT is the same as approximating an integral by a finite sum.
We will first discuss the 1D case, then we'll discuss the 2D case.
Let's look at the Wiener-Kinchin theorem (for example here).
It states that :
"For the discrete-time case, the power spectral density of the function with discrete values x[n], is :
where
Is the autocorrelation function of x[n]."
1) You can see already that the sum is taken from -infty to +infty in the calculation of S(f)
2) Now considering the Matlab fft - You can see (command 'edit fft' in Matlab), that it is defined as :
X(k) = sum_{n=1}^N x(n)*exp(-j*2*pi*(k-1)*(n-1)/N), 1 <= k <= N.
which is exactly what you want to be done in order to calculate the power spectral density for a frequency f.
Note that, for continuous functions, S(f) will be a continuous function. For Discretized function, S(f) will be discrete.
Now that we know all that, it can easily be extended to the 2D case. Indeed, the structure of fft2 matches the structure of the right hand side of the Wiener-Kinchin Theorem for the 2D case.
Though, it will be necessary to divide your result by NxM, where N is the number of sample points in x and M is the number of sample points in y.
I have a time series which is a linear combination of damped waves. The data is real.
Y(t) =SUM_w exp(- gamma t) sin(omega t)
There is no analytic form but this is a closest guess. I want to fourier analyze (FFT) such data and get the real frequencies and damping rates.
I am using matlab but any tool would be fine
Thanks!
Your question would be a better fit for http://math.stackexchange.com, where LaTeX rendering is available for formula. Instead, you have to use e.g. this bookmarklet for proper display:
javascript:(function(){function%20a(a){var%20b=a.createElement('script'),c;b.src='https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML.js',b.type='text/javascript',c='MathJax.Hub.Config({tex2jax:{inlineMath:[[\'$\',\'$\']],displayMath:[[\'\\\\[\',\'\\\\]\']],processEscapes:true}});MathJax.Hub.Startup.onload();',window.opera?b.innerHTML=c:b.text=c,a.getElementsByTagName('head')[0].appendChild(b)}function%20b(b){b.MathJax===undefined?a(b.document):b.MathJax.Hub.Queue(new%20b.Array('Typeset',b.MathJax.Hub))}var%20c=document.getElementsByTagName('iframe'),d,e;b(window);for(d=0;d<c.length;d++)e=c[d].contentWindow||c[d].contentDocument,e.document||(e=e.parentNode),b(e)})()
First of all, I assume your function is more precisely of the kind
$\sum\limits_k e^{-\gamma_k t}\sin(\omega_k t)$ for $t>0$ and $0$ for $t<0$ (otherwise the function would tend to infinity for $t\to-\infty$). Since a damped function is not periodic, you cannot use Fourier analysis but have to use the Fourier transform, which yields an amplitude for continuous frequencies instead of discrete ones. Using the complex representation $\sin(x) = \frac{e^{ix}-e^{-ix}}{2i}$, each term in the sum can be Fourier transformed individually, yielding
$\frac1{2\pi}\int_0^\infty e^{-\gamma_k t}\sin(\omega_k t)e^{-i\omega t}\,dt = \frac{\omega_k}{2\pi[(\gamma+i\omega)^2+\omega_k^2]} = \frac{\omega_k}{2\pi}\frac{(\gamma^2-\omega^2+\omega_k^2) + 2i\gamma\omega\omega_k}{[\gamma^2-\omega^2+\omega_k^2]^2+4\gamma^2\omega^2}$
Since you state the damped sine is only a guess, you have to discretize this unlimited integral somehow, though due to the damping a cutoff at some sufficiently large time $t$ should be in order. If the damping $\gamma_k$ is actually the same for all summands, your life becomes easier: Multiply the data by $e^{+\gamma t}$ to obtain a periodic signal which you can now really FFT on.
First digitize your function:
t=0:dt:T; % define sampling interval dt and duration T according to your needs
Y=sum(exp(-gamma*t).*sin(omega*t));
Then do fft and plot:
Y_f=fft(Y);
plot(abs(Y_f));