LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fourier transform of step function

I am about to check out for the night, but a few points to keep you going.

 

When you sample a signal, you have a sampling frequency and a sampling interval (# samples).  The Nyquist limit tells you that the highest frequency you can resolve without aliasing is one-half the sampling frequency.  The resolution (bin width) is given by the reciprocal of the sampling interval.  Better resolution means sample longer, higher frequencies means sample faster.  I think you've got that.  Let's think about windowing.

 

In your imagination, you have a continuous signal which extends for infinite time (for simplicity we will assume a sine).   You are only observing for a finite time, so in your imagination you multiply the infinite signal by a window function, say 1 for the time you are measuring, 0 otherwise.  Now imagine taking the FT, this will be the convolution of the infinite signal with the FT of the window (Sinc).  The FT of the sine is just a pair of impulses, and the convolution is relatively simple, two copies of the Sinc.  The Sinc, as you know, has a main lobe and then a bunch of ripples with periodic zeros.  I won't work out the numbers, but basically your FFT samples this Sinc function at discrete points.  If your sample time is commensurate with the signal frequency, it works out that you sample the Sinc function at its maximum followed by its zeros.  You get one peak (ie. power in one bin) and no contribution in the other bins.  If the sample time is not commensurate, then you are sampling somewhere in the ripples, and all bins have some small component (leakage).  This is likely what you are seeing (but don't worry, 10^-15 is almost always considered zero when dealing with floating point math).  The magnitude of the peak is affected by the length of the array since you are changing the sampling interval.

 

A way to picture this is that the FFT assumes your truncated signal continues periodically.  This means is that if your sample ends at the end of the period of the sine, everything is ok.  But, say you miss, there is now a jump which means higher frequencies are introduced.  If you miss by a quarter of a period there can be quite a jump!  There are a variety of window functions that try to smooth these edges while preserving the ability to resolve two nearby frequencies. 

 

What's the simple solution to all this?  It really depends on what you are looking for.

 

Clear as mud, isn't it? 

 

 

0 Kudos
Message 11 of 21
(1,292 Views)

Some of the mud is rinsing away.  I successfully plotted the spectrum such that the magnitudes & peak locations do not change when I change the sampling freq & the sample size.  This was a relatively straight forward operation by simply dividing the output of the FFT by the size of the array & sending that to a BUILD WAVEFORM VI with my dt input terminal wired to the df output which = sampling freq/# samples.  I get the best results whenever the # samples = sampling freq which yields a df = 1 Hz which in hindsight makes some sense.

 

Why is this not already built into the VI?  I guess there other vagaries to discrete signal processing I still need to grasp.  I will now introduce the step function again & see what I get.

0 Kudos
Message 12 of 21
(1,272 Views)

First of all, I am glad that you are getting up the curve, be careful, it is very easy to slide back down.  Personally, I hate memorizing formulas, so I don't like to remember where to put N in the DFT.  I could then argue that the sensible choice is to put sqrt(N) in both the DFT and inverse DFT.  NI made a different choice, but since I understand what they have done, I can write my own VI that takes what they give me and change it to what I am used to seeing.  I am totally fine with that, LV gives me something that (1) works and (2) is clearly documented and I can make it suit my needs.  Now that you have a grasp of what is going on, I suggest making your own VI that performs the scaling that makes you comfortable (just remember it is outside the definition of the DFT).  They do a lot of the work, but I guess they left you a little. Smiley Wink  

  

0 Kudos
Message 13 of 21
(1,264 Views)
OK, I am a bit miffed again.  I input the unit step function again & I see the impulse @ f = 0 which is the REAL component of the transform.  I see absolutely ZERO imaginary components @ all freq's.  Whether continuous or discrete the step function has an imaginary component inversely proportional to freq?
0 Kudos
Message 14 of 21
(1,263 Views)

1. Remember that the DFT starts at t=0, what happens at t<0 is assumed to be periodic continuation of your input signal.

2. The signal you describe, 0,1,1,1,... essentially means that you are summing something very close to what is referred to as the Nth roots of unity.  (If you put in 1,1,1,1,1.. it would be the Nth roots).  As you increase N, think about where the points in the sum lie on the unit circle.  If N is even, you have 2 real points (1,-1) and N-2 complex conjugate pairs.  If N is odd, you have 1 and N-1 complex conjugate pairs.  Either way, the sum gives you ZERO for the imaginary part.  You have a single 0 in there, so it is slightly different.

3.  Want to see some imaginary components, try a signal that is 0,0,0,0,...0,1,1,...1.   

0 Kudos
Message 15 of 21
(1,255 Views)

OK, I do see that + the magnitude is falling off with freqency.  So if I am analyzing data from a servo-motor that represents its response to a step input I should apply a delay to the beginning of the data set to get an accurate freq. response spectrum?  If this is the case is there a general rule of thumb to apply the delay based on the size of the data set & sampling rate?

 

Also, I found on the web some lectures from Brad Osgood @ Stanford U on "Applications of the Fourier Transform".  His lectures 19 - 21 discuss DFT which I think I will view tonight.  Maybe that will give me more insight.

0 Kudos
Message 16 of 21
(1,246 Views)
It would appear by experimentation that a delay 1/2 the length of the data set seems appropriate?  I'll review the lectures & hopefully this topic surfaces.
0 Kudos
Message 17 of 21
(1,243 Views)

Darin, posted is my latest output & the modified VI I obtained from the FFT & Power Spectrum VI I obtained from the EXAMPLE FINDER.  I went through 4 hours of lecture material from Prof. Osgood @ Stanford & @ the end of his 4 lectures on DFT he mentions that the DFT can present problems when attempting to sample functions that are not necessarily periodic & discontinuous in the time domain.  He mentioned there are various strategies to handle such cases but he said that is a matter addressed in another course. 

 

Anyway, the best results I could obtain for the DFT vs continuous for a step input is to be sure that the sampling freq & # of samples are = such that df = 1.0 & the self-imposed delay be 1/2 the length of the array size for the DFT.

 

Do you concur or is there a better strategy or should I avoid DFT altogether when attempting to model non-periodic functions?

0 Kudos
Message 18 of 21
(1,202 Views)
Whoops I forgot the results attachment & the VI
Download All
0 Kudos
Message 19 of 21
(1,201 Views)

OK, I found a very rudimentary tutorial within signal processing on NI's website on DFT which you cannot find if you search for Fourier Transform since that pulls up nearly an infinite selection menu.  In that tutorial is a minimal discussion on WINDOWING.  This seems appropriate for singnals that may have some irregularities but overall they are somewhat periodic in nature.  Unfortunately, the step functions is not.  So I presume this is the aggravation I experienced.  However, the step function does have frequency structural behavior.  How should this be addressed via an FFT VI?

 

 

ANYONE??????

0 Kudos
Message 20 of 21
(1,191 Views)