I am trying to make sense of some awful MATLAB code. The first thing it does is mirror the signal. By that I mean it doubles the array length, then puts a time-reversed signal at the newly created back half. So this would have the same amplitude spectum, but what else is going on? Possibly it increases the frequency resolution, as the time length is doubled. I wonder if the algorithm had some side effect - creating crap towards the end, and this is swept under the carpet (which is the mirror copy).

# mirroring a signal before FFT - why?

Started by ●December 14, 2019

Reply by ●December 15, 20192019-12-15

Am 15.12.19 um 03:44 schrieb hdreck@freenet.de:> I am trying to make sense of some awful MATLAB code. The first thing it does > is mirror the signal. By that I mean it doubles the array length, then puts > a time-reversed signal at the newly created back half. > So this would have the same amplitude spectum, but what else is going on? > Possibly it increases the frequency resolution, as the time length is > doubled. > I wonder if the algorithm had some side effect - creating crap towards > the end, and this is swept under the carpet (which is the mirror copy).It removes discontinuity at then end of the interval. The FFT assumes that the input signal is periodic and repeats infinitely many times. This is necessary because the Fourier transform is defined for an infinite signal, but you only give it a finite number of samples. If done in this way, and the first and last samples have different values, there is a discontinuity at the boundary which results in a strong disturbance. Mirroring the signal reduces the discontinuity, though there is still a jump in the derivative. The result is the same as the discrete cosine transform (DCT), so this code may also simply be a way to perform a DCT. Christian

Reply by ●December 15, 20192019-12-15

Christian Gollwitzer <auriocus@gmx.de> wrote:>Am 15.12.19 um 03:44 schrieb hdreck@freenet.de:>> I am trying to make sense of some awful MATLAB code. The first thing >> it does is mirror the signal. By that I mean it doubles the >> array length, then puts a time-reversed signal at the newly created back half.[...]>The result is the same as the discrete cosine >transform (DCT), so this code may also simply be a way to perform a DCT.This is alsmost certainly what is going on, as it is the easiest way to implement a DCT using the Matlab built-in fft(). Also, very often a window would be used before the fft(). Steve

Reply by ●December 15, 20192019-12-15

On Sat, 14 Dec 2019 18:44:12 -0800 (PST), hdreck@freenet.de wrote:>I am trying to make sense of some awful MATLAB code. The first thing it does >is mirror the signal. By that I mean it doubles the array length, then puts >a time-reversed signal at the newly created back half. >So this would have the same amplitude spectum, but what else is going on? >Possibly it increases the frequency resolution, as the time length is >doubled. >I wonder if the algorithm had some side effect - creating crap towards >the end, and this is swept under the carpet (which is the mirror copy).There are certain symmetries in DFTs that can be exploited if one so desires, like this one. Consider that the transform of a real-valued time-domain vector is symmetric about zero in the frequency domain. So if you load a transform with an input vector that is symmetric about zero, it will be akin to performing an inverse transform on the spectrum of a real-valued signal. As others have mentioned, it's essentially also a trick to do a DCT using an FFT, exploiting the same symmetries.

Reply by ●December 15, 20192019-12-15

On Sun, 15 Dec 2019 10:20:30 +0100, Christian Gollwitzer <auriocus@gmx.de> wrote:>Am 15.12.19 um 03:44 schrieb hdreck@freenet.de: >> I am trying to make sense of some awful MATLAB code. The first thing it does >> is mirror the signal. By that I mean it doubles the array length, then puts >> a time-reversed signal at the newly created back half. >> So this would have the same amplitude spectum, but what else is going on? >> Possibly it increases the frequency resolution, as the time length is >> doubled. >> I wonder if the algorithm had some side effect - creating crap towards >> the end, and this is swept under the carpet (which is the mirror copy). > > >It removes discontinuity at then end of the interval. The FFT assumes >that the input signal is periodic and repeats infinitely many times. >This is necessary because the Fourier transform is defined for an >infinite signal, but you only give it a finite number of samples. If >done in this way, and the first and last samples have different values, >there is a discontinuity at the boundary which results in a strong >disturbance.There have been long discussions here (and elsewhere) in the past about this. The point of view you mention is not held by all practicioners, and other points of view are just as valid. e.g., a DFT is a matrix multiply of an input to produce an output, and produces a 1:1 mapping from an input domain to an output domain. No samples outside of the input vector have any influence on the output, regardless of periodicity or lack thereof. Likewise essentially all window functions used to explain the response in the frequency domain are zero outside of the input vector. e.g., the basic rectangular window when a weighted window is not applied. The periodic/circular point of view is certainly valid, but it is not necessary and is not used by many practicioners in the field since real-world signals are essentially never periodic over the length of the input vector.

Reply by ●December 16, 20192019-12-16

On Sunday, December 15, 2019 at 1:20:36 AM UTC-8, Christian Gollwitzer wrot= e:> Am 15.12.19 um 03:44 schrieb hdreck@freenet.de: >=20 > The FFT assumes that the input signal is periodic and=20 > repeats infinitely many times.Hi. The unfortunately popular notion that "The FFT assumes its input is periodi= c" must surely be the most profound misconception in all of DSP. The FFT c= annot make assumptions. Making an assumption is a mental activity. Only a l= iving creature with a brain can make an assumption.

Reply by ●December 16, 20192019-12-16

Richard (Rick) Lyons <r.lyons@ieee.org> wrote:>On Sunday, December 15, 2019 at 1:20:36 AM UTC-8, Christian Gollwitzer wrote:>Hi. >The unfortunately popular notion that "The FFT assumes its input is >periodic" must surely be the most profound misconception in all of DSP. >The FFT cannot make assumptions. Making an assumption is a mental >activity. Only a living creature with a brain can make an assumption."The FFT evangelists assume the input is periodic.." ?? S.

Reply by ●December 17, 20192019-12-17

On Monday, December 16, 2019 at 7:58:14 PM UTC-8, Steve Pope wrote:> Richard (Rick) Lyons <r.lyons@ieee.org> wrote: > > >On Sunday, December 15, 2019 at 1:20:36 AM UTC-8, Christian Gollwitzer wrote: > > >Hi. > >The unfortunately popular notion that "The FFT assumes its input is > >periodic" must surely be the most profound misconception in all of DSP. > >The FFT cannot make assumptions. Making an assumption is a mental > >activity. Only a living creature with a brain can make an assumption. > > "The FFT evangelists assume the input is periodic.." ?? > > S.The evangelists who wish to interpret the output of the DFT as samples of the Fourier Transform must assume that the input is periodic in the DFT size. Dale B Dalrymple

Reply by ●December 17, 20192019-12-17

On Monday, December 16, 2019 at 9:13:02 PM UTC-8, dbd wrote:>=20 > The evangelists who wish to interpret the output of the DFT as samples of=the Fourier Transform must assume that the input is periodic in the DFT si= ze.>=20 > Dale B DalrympleHi Dale (and Steve Pope). The notion of periodicity is much more complicate= d than we first thought when we began to learn DSP theory. College DSP text= books say that an x(n) sequence has a period of N samples if and only if: x[n+N] =3D x[n] for all n. But that equality is ONLY true for infinite-length sequences, and infinite-= length sequences do not exist in reality. An infinite-length sequence is an= abstract idea, ...like a perfect circle or one of Euclid's lines having in= finite length and zero thickness. What this means is that, based on the abo= ve periodicity definition, we will never encounter, nor ever be able to gen= erate, a periodic sequence in our real world.

Reply by ●December 17, 20192019-12-17

On Mon, 16 Dec 2019 21:12:59 -0800 (PST), dbd <d.dalrymple@sbcglobal.net> wrote:>On Monday, December 16, 2019 at 7:58:14 PM UTC-8, Steve Pope wrote: >> Richard (Rick) Lyons <r.lyons@ieee.org> wrote: >> >> >On Sunday, December 15, 2019 at 1:20:36 AM UTC-8, Christian Gollwitzer wrote: >> >> >Hi. >> >The unfortunately popular notion that "The FFT assumes its input is >> >periodic" must surely be the most profound misconception in all of DSP. >> >The FFT cannot make assumptions. Making an assumption is a mental >> >activity. Only a living creature with a brain can make an assumption. >> >> "The FFT evangelists assume the input is periodic.." ?? >> >> S. > >The evangelists who wish to interpret the output of the DFT as samples of the Fourier Transform must assume that the input is periodic in the DFT size. > >Dale B DalrympleA limiting assumption. ;)