I'm getting different results when comparing MATLAB's fft
() to Simulink's fft block. In both cases I'm doing a
1024-point FFT on 4096 points of data.
The input into each is the same. The maximum value of the
fft output is very different (43.06 for Simulink vs 165.99
for MATLAB). However, these maximum values occur in the
same bin.
Any idea as to what could be causing the difference
between the two FFTs? The documentation for the FFT block
says that the equivalent MATLAB code is fft(), so it
should give equal outputs. There are parameters within
the FFT block, but those seem to affect how the result is
computed rather than what result is computed.
Thanks for the help.
-Bryan
Subject: Difference between FFT in MATLAB & Simulink
I had make some test, to check your results. But, I verify
that Matlab FFT and Simulink FFT generate the same result.
Maybe, you are making a mistake in your code or diagram.
Check your the type of window that you are using, and the
overlaping.
Regards,
Pedro
Subject: Difference between FFT in MATLAB & Simulink
After a little more investigating, I'm still not sure what
is going on. With some frequencies (all less than Fs/2),
I am getting very similar results (max difference is 5e-
4). However, I'm still getting a significant difference
with other frequencies.
I'm outputting the data to the MATLAB workspace before and
after the FFT block. Then I am taking the FFT of the
beforeFFT data using MATLAB's function. This is what I'm
using to compare to Simulink's output. I'm using all
default settings for both the block and the MATLAB
function. I'm using a buffer to create a signal of
dimension 4096x1. I don't think that's an issue but
figured I'd mention it.
You mentioned to check my windowing and such. fft()
doesn't have any of those setting as arguments, so how do
I check the settings of these?
Subject: Difference between FFT in MATLAB & Simulink
I guess I should mention that I'm plotting the linear
fft. After using fft, I'm taking the abs() and performing
an fftshift() then plotting the result. Of course, I am
doing the same operations to each sets of data before
plotting.
Subject: Difference between FFT in MATLAB & Simulink
The difference appears to only occur when I set the FFT
size to 1024. When I check the 'Inherit FFT length from
input dimensions' box, the output is very similar (~5e-13)
to the output from MATLAB's FFT function. So what is it
about performing a 1024-sized FFT on 4096 data points that
could be causing the difference between matlab and
simulink?
Thanks!
Subject: Difference between FFT in MATLAB & Simulink
I fixed the problem by adding a 'pad' block before the fft
block. MATLAB's fft function automatically truncates the
input to the desired FFT size (if the fft size is less
than the input's length). Apparently, Simulink's block
doesn't do that, or at least doesn't do it in the same way
that MATLAB does.
Even though I've got the correct solution now, does anyone
know why Simulink doesn't automatically truncate or what
the difference between the truncation is? I would think
if the block isn't designed to do automatic truncation
that it would at least show a warning.
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Disclaimer prior to use.