Thread Subject: Difference between FFT in MATLAB & Simulink

Subject: Difference between FFT in MATLAB & Simulink

From: Bryan

Date: 19 Jun, 2008 20:21:02

Message: 1 of 6

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

From: Pedro Villena

Date: 19 Jun, 2008 23:02:01

Message: 2 of 6

Bryan,

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

From: Bryan

Date: 23 Jun, 2008 13:38:02

Message: 3 of 6

Thanks for the reply.

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

From: Bryan

Date: 23 Jun, 2008 14:04:03

Message: 4 of 6

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

From: Bryan

Date: 23 Jun, 2008 15:37:02

Message: 5 of 6

Just to add some additional information:

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

From: Bryan

Date: 23 Jun, 2008 16:14:02

Message: 6 of 6

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.

Tags for this Thread

Everyone's Tags:

fft

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
fft Pedro Villena 19 Jun, 2008 19:05:07
rssFeed for this Thread

Public Submission Policy

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.

Contact us at files@mathworks.com