Precision of FFT function
Show older comments
Hi,
I have a fft function in C programming language. All inputs, window coefficients, twiddle factors and outputs are set to a precision 0f 6 digits. I wanted to make a reference output using Matlab. I used, vpa(fft(x),8) to round my output to 6 demical places, eg: 11.243127. I expected similar outputs, but there seems to be precision errors beyond my expectations. A sample is shown below:
C output: -17.119499+87.937943i
Matlab output: - 17.118454 + 87.935932i
Is there something that I missed out? The expected relative error is 0.00001
3 Comments
Dyuman Joshi
on 19 Sep 2023
Edited: Dyuman Joshi
on 19 Sep 2023
From the documentation - "When you call vpa on a numeric input, such as 1/3, 2^(-5), or sin(pi/4), the numeric expression is evaluated to a double-precision number that contains round-off errors. Then, vpa is called on that double-precision number. For accurate results, convert numeric expressions to symbolic expressions with sym. For example, to approximate exp(1), use vpa(exp(sym(1)))."
y = [123.456 98.7654321]';
compose('%0.42f',y)
vpa(y,50)
Can you attach the data and the MATLAB code you are working with?
C=-17.119499+87.937943i;
M=-17.118454 + 87.935932i;
C-M
"All inputs, window coefficients, twiddle factors and outputs are set to a precision 0f 6 digits..."
The observed differences are in 5th digit; about what I'd think best one could expect with carryover although you didn't indicate the length of the signal...
Instead of using vpa, probably better to use round if only care about the number digits after the decimal point, rather than the total number of significant figures. For example:
format long
round(100*pi,6)
In this call
vpa(fft(x),8)
what is the class of x? Is it double or single? And, is x rounded to six decimal digits? Or does is it have as many decimal digits as its class allows (I probably haven't worded that precisely, but hopefully the question is clear enough)?
Answers (0)
Categories
Find more on Fast Fourier Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!