DSPRelated.com
Forums

FFT real input and output

Started by dcl July 24, 2003
Hello,
I am trying to find the answer to the following:

If I generate a test file to test a FFT program is the following true:

Do I have to generate samples that only represent cosines or if I only
generated sines would that be a real signal? I know it sounds like a
stupid question. But I have read in DSP books that a signal from an
A/D converter is considered Real. So I was wondering does that mean a
all sine based sampled signal is Real?

Secondly, if I only input Real samples, do I have to abs() the complex
FFT outputs to detect whether the frequency exists and it's amplitude.
I am trying to use the FFT to determine if the frequency is there or
not and it's amplitude.

Thanks for any help!
"dcl" <dlang@prodigy.net> wrote in message
news:dbca8e25.0307241619.12f649cc@posting.google.com...
> Hello, > I am trying to find the answer to the following: > > If I generate a test file to test a FFT program is the following true: > > Do I have to generate samples that only represent cosines or if I only > generated sines would that be a real signal? I know it sounds like a > stupid question. But I have read in DSP books that a signal from an > A/D converter is considered Real. So I was wondering does that mean a > all sine based sampled signal is Real? > > Secondly, if I only input Real samples, do I have to abs() the complex > FFT outputs to detect whether the frequency exists and it's amplitude. > I am trying to use the FFT to determine if the frequency is there or > not and it's amplitude.
The input can be fairly arbitrary as long as the *result* is bandlimited. If you sample a signal bandlimited to under fs/2, that works. Also, a short sequence of a pure computer-generated sine or cosine function would not be bandlimited because it's a short sequence (time-limited). In order for the latter to be bandlimited, it has to be lowpass filtered first - the edges have to be tapered appropriately. If you select test signals such that there is an integral number of cycles in the temporal epoch, then there will be no spectral leakage and you should get one kind of good test. If the signal components are all real cosines from -T to +T then the result will be an even function of time. That will result in an all real even Fourier Transform. If there's an integral number of cycles from -T to +T, then there will be no spectral spreading as above. If the signal components are all real sines from -T to +T then the result will be an odd function of time. That will result in an all imaginary odd Fourier Transform. If there's an integral number of cycles from -T to +T, then there will be no spectral spreading as above. Because superposition applies, these rules tell you what happens if the input is a sum of sines and cosines. A symmetrical epoch centered at t=0 will have those properties for the cosine and sine components. Every function can be split into even and odd parts - thus cosine and sine parts. Perhaps not with integral numbers of cosine or sine periods though... This means that every Fourier Transform of a real function will have an even real part based on the time even part and an odd, imaginary part based on the time odd part. This applies no matter where time zero is relative to the time epoch. A short pulse centered at t=100 will have an even part that is 1/2 the pulse at -100 and +100 and an odd part of the pulse that is -1/2 at -100 and 1/2 at +100. It also means that if the real part of the transform is even and the odd part of the transform is imaginary, then the time domain inverse transform will be real. Yes, you have to look at the magnitude in frequency to figure out what's there. For your application you might want to look at topics on spectral estimation or spectral analysis. I hope this helps. Fred
"Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in message news:<NJiUa.3465$Jk5.2539054@feed2.centurytel.net>...
> "dcl" <dlang@prodigy.net> wrote in message > news:dbca8e25.0307241619.12f649cc@posting.google.com... > > Hello, > > I am trying to find the answer to the following: > > > > If I generate a test file to test a FFT program is the following true: > > > > Do I have to generate samples that only represent cosines or if I only > > generated sines would that be a real signal? I know it sounds like a > > stupid question. But I have read in DSP books that a signal from an > > A/D converter is considered Real. So I was wondering does that mean a > > all sine based sampled signal is Real? > > > > Secondly, if I only input Real samples, do I have to abs() the complex > > FFT outputs to detect whether the frequency exists and it's amplitude. > > I am trying to use the FFT to determine if the frequency is there or > > not and it's amplitude. > > The input can be fairly arbitrary as long as the *result* is bandlimited. > If you sample a signal bandlimited to under fs/2, that works. Also, a short > sequence of a pure computer-generated sine or cosine function would not be > bandlimited because it's a short sequence (time-limited). In order for the > latter to be bandlimited, it has to be lowpass filtered first - the edges > have to be tapered appropriately. > > If you select test signals such that there is an integral number of cycles > in the temporal epoch, then there will be no spectral leakage and you should > get one kind of good test. > > If the signal components are all real cosines from -T to +T then the result > will be an even function of time. That will result in an all real even > Fourier Transform. > If there's an integral number of cycles from -T to +T, then there will be no > spectral spreading as above. > > If the signal components are all real sines from -T to +T then the result > will be an odd function of time. That will result in an all imaginary odd > Fourier Transform. > If there's an integral number of cycles from -T to +T, then there will be no > spectral spreading as above. > > Because superposition applies, these rules tell you what happens if the > input is a sum of sines and cosines. A symmetrical epoch centered at t=0 > will have those properties for the cosine and sine components. Every > function can be split into even and odd parts - thus cosine and sine parts. > Perhaps not with integral numbers of cosine or sine periods though... > > This means that every Fourier Transform of a real function will have an even > real part based on the time even part and an odd, imaginary part based on > the time odd part. This applies no matter where time zero is relative to > the time epoch. A short pulse centered at t=100 will have an even part that > is 1/2 the pulse at -100 and +100 and an odd part of the pulse that is -1/2 > at -100 and 1/2 at +100. > > It also means that if the real part of the transform is even and the odd > part of the transform is imaginary, then the time domain inverse transform > will be real. > > Yes, you have to look at the magnitude in frequency to figure out what's > there. For your application you might want to look at topics on spectral > estimation or spectral analysis. > > I hope this helps. > > Fred
Thank you! That answers a lot of questions for me. I do have another question though, if the test file containing multiple cosine frequencies with integral number of cycles has N samples. N that is equal to the sample rate / the lowest or minimum frequency, would I have to zero pad to get the FFT frequency resolution to equal the spacing between the cosine frequencies in the test file? Does zero padding from N to L give correct results for FFT bin resolution based on center freq. of the mth bin =m(fs)/L where fs =sample rate L = N + number of zero padded
"dcl" <dlang@prodigy.net> wrote in message > Thank you! That answers a lot
of questions for me. I do have another
> question though, if the test file containing multiple cosine > frequencies with integral number of cycles has N samples. N that is > equal to the sample rate / the lowest or minimum frequency, would I > have to zero pad to get the FFT frequency resolution to equal the > spacing between the cosine frequencies in the test file? Does zero > padding from N to L give correct results for FFT bin resolution based > on > center freq. of the mth bin =m(fs)/L where > fs =sample rate > L = N + number of zero padded
N samples? N sample rate? Well.... let's see. If all of the cosines have an integral number of cycles in the epoch, then all of the cosines are harmonically related. The lowest frequency / largest period would be one cycle in the epoch. Let's assume 1 second sample interval / 1Hz sample rate and N samples. The frequency sample interval is 1/N Hz. So after the zero frequency term, the lowest frequency sample is at 1/N Hz and 2/N, 3/N, .... thereafter until you get to N/N which has the same value as at f=0. In this case, you don't need to zero pad nor would you want to presumably. The frequency sample points are identical to the frequencies of the cosines you started with. Of course, you may not have frequencies as high or higher than fs/2 = 1/2Hz due to the sampling theorem. There are N frequency intervals. - If N is even, then N/2 is an integer and there is a sample at fs/2. This must be zero so the highest frequency would be (1/N)*(N/2-1) = 1/2 - 1/N. - If N is odd, then N/2 isn't an integer and there is no sample at fs/2. In this case the highest frequency would be 1/2-(1/2N). Zero padding might show different results because you'd be introducing sharp discontinuities at the edges of the original epoch - which introduce additional frequency components beyond the analytical description of harmonically related cosines. Fred
"Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in message news:<iecVa.3562$Jk5.2699147@feed2.centurytel.net>...
> "dcl" <dlang@prodigy.net> wrote in message > Thank you! That answers a lot > of questions for me. I do have another > > question though, if the test file containing multiple cosine > > frequencies with integral number of cycles has N samples. N that is > > equal to the sample rate / the lowest or minimum frequency, would I > > have to zero pad to get the FFT frequency resolution to equal the > > spacing between the cosine frequencies in the test file? Does zero > > padding from N to L give correct results for FFT bin resolution based > > on > > center freq. of the mth bin =m(fs)/L where > > fs =sample rate > > L = N + number of zero padded > > N samples? > N sample rate? > > Well.... let's see. If all of the cosines have an integral number of cycles > in the epoch, then all of the cosines are harmonically related. The lowest > frequency / largest period would be one cycle in the epoch. > > Let's assume 1 second sample interval / 1Hz sample rate and N samples. > The frequency sample interval is 1/N Hz. So after the zero frequency term, > the lowest frequency sample is at 1/N Hz and 2/N, 3/N, .... thereafter until > you get to N/N which has the same value as at f=0. > > In this case, you don't need to zero pad nor would you want to presumably. > The frequency sample points are identical to the frequencies of the cosines > you started with. Of course, you may not have frequencies as high or higher > than fs/2 = 1/2Hz due to the sampling theorem. There are N frequency > intervals. > - If N is even, then N/2 is an integer and there is a sample at fs/2. This > must be zero so the highest frequency would be (1/N)*(N/2-1) = 1/2 - 1/N. > - If N is odd, then N/2 isn't an integer and there is no sample at fs/2. In > this case the highest frequency would be 1/2-(1/2N). > > Zero padding might show different results because you'd be introducing sharp > discontinuities at the edges of the original epoch - which introduce > additional frequency components beyond the analytical description of > harmonically related cosines. > > Fred
Thanks again! I really appreciate you taking the time to reply. This is why I was asking about zero stuffing: If the test file only had cosine freq. that have integral cycles that cover the range < fs/2 and the freq_min or lowest freq, which lets say is >= fs/4 would I need to window and bandpass filter the test file? Or would it be bandpassed filter and windowed to zero per se by the fact that those are the frequencies generated with integral cycles. I think you have answered this in your post above: Are you trying to tell me that unless I filter the test file it will appear to have discontinuities because the end of the epoch needs to be the filtered or windowed to complete the epoch to zero? I can do that if needed. I am concerned about getting the bins to line up with the spacing between the test freq.. Frequency sampling I guess I could call it.I hope I not confusing this too much. Dan