MATLAB Answers

Frequency scale in fft after zero filling (odd/even number of data)

29 views (last 30 days)
FW
FW on 21 Apr 2019
Commented: Star Strider on 21 Apr 2019
Product: Matlab 2017b
If we have data set "A" which consists of time versus light absorbance.There is another set of data "B". Both data are sampled at the same rate Fs.
The two sets are to be divided in the frequency domain. C= fft(A)/fft(B). Prior to division, in order to make the length of A and B equal, zero filling in done or one can use the fft(X, n). Sometimes there are odd number of data points and sometimes, even in A and B after zero filling.
In such a case, how do we make a frequency axis for C in MATLAB? The number of original data points have changed after zero filling in either A or B.
Example: The key question is, assume we had initially 1000 data points in A, and 800 data points in B. Let us use C= fft (A, 1024) ./ fft(B, 1024). We get a new vector C. How should we make a frequency scale for C now given that the number of data points were changed.
Thanks.

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 21 Apr 2019
I am not certain what you are doing. One way to make the frequencies equal would be to use the second argument, ‘n’, in the fft function, to be the same for all of them (and preferably relatively large, so that all your data have the same frequency vector). This has the effect of ‘zero-padding’ the argument vector, increasing the frequency resolution and equalising the frequencies of the various signals.
The only way to determine if this approach is appropriate to your data is to try it with them.

  6 Comments

Show 3 older comments
Star Strider
Star Strider on 21 Apr 2019
As always, my pleasure.
Longer time-domain record lengths will be best to detect low-frequency signals, particularly if your data are noisy.
With a 250 Hz sampling frequency, a record of 1000 samples would be 4 seconds in length. A signal that would complete 1 cycle in 4 seconds would have a frequency of 0.25 Hz. For a record of 800 samples, that frequency would be about 0.3125 Hz. The lowest frequency signal that would complete 1 cycle in a given record length would then be:
at least as I calculate it.
FW
FW on 21 Apr 2019
Thanks. Just a final confirmation, whenever we do zero padding of the original data by using fft( X, n) option, our frequency axis should be made as per our chosen "n" rather than original length of t.
So let say original data A had 1000 points sampled at 250 Hz. We did FFT (A, 1024). This essentially means that we sampled for a longer time. Should our t be changed in the equation below to accomodate the zero padding. This is exactly causing confusion about zero padding and making a frequency axis now.
Fv = linspace(0, 1, fix(numel(t)/2)+1)*Fn
e.g. in your code
length (t) = 1000
however length(FFTy1) is 1024.
How does the frequency axis take care of the new number of data points?
Thanks.
Star Strider
Star Strider on 21 Apr 2019
As always, my pleasure.
... whenever we do zero padding of the original data by using fft( X, n) option, our frequency axis should be made as per our chosen "n" rather than original length of t.
Yes.
The ‘Fv’ vector should be:
Fv = linspace(0, 1, fix(numel(FTy1)/2)+1)*Fn;
My apologies for the error. (Since ‘FTy1’ and ‘FTy2’ are the same lengths here, there is no need to compute the ‘Fv’ vector separately for each one.) This also assumes the two are vectors. If not, use the length function instead of numel to calculate the correct length of ‘Fv’.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!