"Ron N." <rhnlogic@yahoo.com> wrote in message news:7a7b3869-8b24-40fa-9f57-9de8a2b0ca6a@a39g2000pre.googlegroups.com...> On Nov 29, 8:47 am, suren <suren.r...@gmail.com> wrote: >> Hello Folks, >> I convert a sine wave to a square wave using a zero crossing detector >> function, i.e output = 1 if input >0 else output =-1. >> If I plot the FFT of the resulting square wave, I see lots of tones >> that are not harmonics of the fundamental frequency of the sine wave. >> Can anyone explain this. > > Are you doing your FFT using a vector/aperture length > that is an exact multiple of the period of your sine > wave and thus square wave? If not, you could be looking > at rectangular windowing artifacts. >My thought exactly. It's one simple explanation for what you're doing if the window isn't matched to an integral number of cycles of the "square wave". Also, if the sine wave is already sampled there will also be "modulation" of the apparent frequency of the "square wave" because the axis crossings will dither unless the sampling frequency is an integer multiple of the signal frequency. This effect may even be stronger than grabbing a sub-period in the window interval as mentioned above. Many folks have mentioned what happens if there is a nonlinear operation on a sequence of samples. Think of it like this: 1) Take a continuous signal and hard clip it. Then lowpass filter it. Then sample it. 2) Take a sampled signal and hard clip it. Compare the resulting samples. They won't be the same because of the lowpass filter on the hard-clipped continuous signal. Without the filter there will be aliasing. 3) Let's assume that the sample rate is high enough and/or the sample frequency is matched to the underlying signal such that the samples resulting from (2) are the same as the samples resulting from (1) if the lowpass filter had not been applied. The comparison in (3) clearly shows that the resulting samples in (2) must have aliasing included. Now, it is true that the samples in (2) might represent a perfectly bandlimited signal. But *that* bandlimited signal isn't one that you'd started with / expected. And, there are even some anomalous cases where the samples in (2) would not be amenable to reconstruction to a continuous signal using a sinc. The result can blow up when there are signal components that are *equal to* fs/2. The sample rate must be <fs/2 to prevent this situation. Fred
fourier anlysis of square wave...
Started by ●November 29, 2007
Reply by ●November 29, 20072007-11-29
Reply by ●November 29, 20072007-11-29
"Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in news:NqKdnQQu6dSz3NLanZ2dnUVZ_o6knZ2d@centurytel.net:> Now, it is true that the samples in (2) might represent a perfectly > bandlimited signal.I'm still not getting it Let's try this... I(n)=1 0 0 0 0 0 0 0 0 0...... The FFT of that has zip to do with aliasing. same for I(n-1), and thus I(n)+I(n-1) But for some reason, the FFT of 1 1 0 0 1 1 0 0 1 1 0 0 ...... has something to do with aliasing, simply because you can get to the same signal from a clipped sine wave? Once you're in the digital domain, you can create any signal you want, and aliasing doesn't enter the picture. The A to D is where aliasing comes in. No A to D, no aliasing--- or, are we just defining the results of a circular convolution in the frequency domain to be aliased by definition?? -- Scott Reverse name to reply
Reply by ●November 29, 20072007-11-29
Scott Seidman wrote:> Once you're in the digital domain, you can create any signal you want, and > aliasing doesn't enter the picture.Suppose you have an analog sinewave of 400Hz, the ADC/DAC operating at the sample rate of 1kHz with the perfect filtering at Nyquist 500Hz at the input and at the output and the nonlinearity y = x^2. Consider two cases: 1. The analog sinewave is processed by x^2 nonlinearity, then lowpassed at Nyquist, digitized and then restored back to analog. Result: pure DC. 2. The analog sinewave is digitized, then the digital signal is processed by x^2 nonlinearity, then restored to analog. Result: DC + folded alias at 200 Hz. Do you see the difference now? Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ●November 29, 20072007-11-29
Vladimir Vassilevsky wrote:> > > Scott Seidman wrote: > >> Once you're in the digital domain, you can create any signal you want, >> and aliasing doesn't enter the picture. > > Suppose you have an analog sinewave of 400Hz, the ADC/DAC operating at > the sample rate of 1kHz with the perfect filtering at Nyquist 500Hz at > the input and at the output and the nonlinearity y = x^2. > > Consider two cases: > > 1. The analog sinewave is processed by x^2 nonlinearity, then lowpassed > at Nyquist, digitized and then restored back to analog. Result: pure DC. > > 2. The analog sinewave is digitized, then the digital signal is > processed by x^2 nonlinearity, then restored to analog. Result: DC + > folded alias at 200 Hz. > > Do you see the difference now?This "once you are digitised you are safe" idea is often used like a mantra, for some reason. I'm puzzled where the idea even comes from. Has some popular book pushed the idea? Steve
Reply by ●November 29, 20072007-11-29
Scott Seidman wrote:> "Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in > news:NqKdnQQu6dSz3NLanZ2dnUVZ_o6knZ2d@centurytel.net: > >> Now, it is true that the samples in (2) might represent a perfectly >> bandlimited signal. > > > I'm still not getting it > > Let's try this... > > I(n)=1 0 0 0 0 0 0 0 0 0...... > > The FFT of that has zip to do with aliasing. > > same for I(n-1), and thus I(n)+I(n-1) > > But for some reason, the FFT of > > 1 1 0 0 1 1 0 0 1 1 0 0 ...... > > has something to do with aliasing, simply because you can get to the same > signal from a clipped sine wave? > > Once you're in the digital domain, you can create any signal you want, and > aliasing doesn't enter the picture. The A to D is where aliasing comes in. > No A to D, no aliasing--- or, are we just defining the results of a > circular convolution in the frequency domain to be aliased by definition??Let's stick to the original question instead of becoming language lawyers. Of course every set of samples that has a Fourier transform that doesn't blow up represents a bandlimited function and only a bandlimited function, but a set of alternating equal-length groups of positive and negative samples does not represent a sampled bandlimited square wave. I think it's pretty clear that Suren thought it did, FFTed one, and was confused by what he saw. You reject my explanation of what he saw. What do you offer in its place? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●November 29, 20072007-11-29
On Nov 29, 6:31 pm, Jerry Avins <j...@ieee.org> wrote:> Scott Seidman wrote: > > "Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in > >news:NqKdnQQu6dSz3NLanZ2dnUVZ_o6knZ2d@centurytel.net: > > >> Now, it is true that the samples in (2) might represent a perfectly > >> bandlimited signal. > > > I'm still not getting it > > > Let's try this... > > > I(n)=1 0 0 0 0 0 0 0 0 0...... > > > The FFT of that has zip to do with aliasing. > > > same for I(n-1), and thus I(n)+I(n-1) > > > But for some reason, the FFT of > > > 1 1 0 0 1 1 0 0 1 1 0 0 ...... > > > has something to do with aliasing, simply because you can get to the same > > signal from a clipped sine wave? > > > Once you're in the digital domain, you can create any signal you want, and > > aliasing doesn't enter the picture. The A to D is where aliasing comes in. > > No A to D, no aliasing--- or, are we just defining the results of a > > circular convolution in the frequency domain to be aliased by definition?? > > Let's stick to the original question instead of becoming language > lawyers. Of course every set of samples that has a Fourier transform > that doesn't blow up represents a bandlimited function and only a > bandlimited function, but a set of alternating equal-length groups of > positive and negative samples does not represent a sampled bandlimited > square wave. I think it's pretty clear that Suren thought it did, FFTed > one, and was confused by what he saw. You reject my explanation of what > he saw. What do you offer in its place?I suggest a simple experiment, take a vector and fill it with square waves (-1,1 at a 50% duty cycle) with a wavelength or repeat cycle exactly periodic in the vector length, and perform an fft on that vector. I just tried this with 64 cycles of square waves inside a vector of length 1024 and only saw odd multiples of 16 bins in the fft magnitude results. The aliasing showed up by altering the magnitude of the existing high frequency odd multiples of the fundamental, not by adding any new non-harmonic frequencies (as per the OP's observation). The easiest way to get "bin splatter" was to change the square wave frequency so that it was no longer periodic in the fft aperture. Another way was to change the periodic 1,-1 waveform so that it no longer had a 50% duty cycle. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M http://www.nicholson.com/rhn/dsp.html
Reply by ●November 30, 20072007-11-30
On Nov 29, 10:39 pm, Jerry Avins <j...@ieee.org> wrote:> suren wrote: > > Hello Folks, > > I convert a sine wave to a square wave using a zero crossing detector > > function, i.e output = 1 if input >0 else output =-1. > > If I plot the FFT of the resulting square wave, I see lots of tones > > that are not harmonics of the fundamental frequency of the sine wave. > > Can anyone explain this. > > The non-harmonic tones are aliases. Do you understand about aliasing in > sampled signals? > > Jerry > -- > Engineering is the art of making what you want from things you can get. > �����������������������������������������������������������������������Hello All, Thanks for the valuable suggestions. I now understand that the non harmonic components is due to aliasing. Since, in a square wave the amplitude of the harmonic terms goes as 1/n, where n is odd, it looks like we need to sample at a very high rate, may be at the 1000th harmonic rate to see accurate behvaior. However, in my application, I need to analyse signals in the GHz range and using sampling rates which are very high is becoming an issue. Are there better methods to analyse such cases? Regards suren
Reply by ●November 30, 20072007-11-30
Jerry Avins wrote:> suren wrote:(snip)>> If I plot the FFT of the resulting square wave, I see lots of tones >> that are not harmonics of the fundamental frequency of the sine wave. >> Can anyone explain this.> The non-harmonic tones are aliases. Do you understand > about aliasing in sampled signals?I suppose so. But if the FFT is one period of the original function long, or one period of the square wave, then all the components are multiples of the fundamental. It would seem, then, that it is not one period long. If it is not an integer number of cycles long then you will get non-harmonic components out. I suppose that is pretty much the same as aliasing, but the real cause is not meeting the periodic boundary condition of the FFT. -- glen
Reply by ●November 30, 20072007-11-30
Ron N. wrote:> On Nov 29, 6:31 pm, Jerry Avins <j...@ieee.org> wrote: >> Scott Seidman wrote: >>> "Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in >>> news:NqKdnQQu6dSz3NLanZ2dnUVZ_o6knZ2d@centurytel.net: >>>> Now, it is true that the samples in (2) might represent a perfectly >>>> bandlimited signal. >>> I'm still not getting it >>> Let's try this... >>> I(n)=1 0 0 0 0 0 0 0 0 0...... >>> The FFT of that has zip to do with aliasing. >>> same for I(n-1), and thus I(n)+I(n-1) >>> But for some reason, the FFT of >>> 1 1 0 0 1 1 0 0 1 1 0 0 ...... >>> has something to do with aliasing, simply because you can get to the same >>> signal from a clipped sine wave? >>> Once you're in the digital domain, you can create any signal you want, and >>> aliasing doesn't enter the picture. The A to D is where aliasing comes in. >>> No A to D, no aliasing--- or, are we just defining the results of a >>> circular convolution in the frequency domain to be aliased by definition?? >> Let's stick to the original question instead of becoming language >> lawyers. Of course every set of samples that has a Fourier transform >> that doesn't blow up represents a bandlimited function and only a >> bandlimited function, but a set of alternating equal-length groups of >> positive and negative samples does not represent a sampled bandlimited >> square wave. I think it's pretty clear that Suren thought it did, FFTed >> one, and was confused by what he saw. You reject my explanation of what >> he saw. What do you offer in its place? > > I suggest a simple experiment, take a vector and fill > it with square waves (-1,1 at a 50% duty cycle) with a > wavelength or repeat cycle exactly periodic in the vector > length, and perform an fft on that vector. I just tried > this with 64 cycles of square waves inside a vector of > length 1024 and only saw odd multiples of 16 bins in the > fft magnitude results. The aliasing showed up by altering > the magnitude of the existing high frequency odd multiples > of the fundamental, not by adding any new non-harmonic > frequencies (as per the OP's observation). > > The easiest way to get "bin splatter" was to change the > square wave frequency so that it was no longer periodic > in the fft aperture. Another way was to change the > periodic 1,-1 waveform so that it no longer had a 50% > duty cycle.Was that really 1, -1, 1, -1 .... or with longer blocks? 1, -1, 1, -1 .... represents a square wave sampled at two samples per period, or f = fs/2. The first harmonic is at 3fs/2; it must alias. The next harmonic is at 5fs/2; it also aliases. When the number of cycles is an integer, all these aliases lie atop one another and appear harmonic. Don't be fooled. That's an artifact of the test conditions. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●November 30, 20072007-11-30
On Nov 30, 9:45 am, Jerry Avins <j...@ieee.org> wrote:> Ron N. wrote: > > On Nov 29, 6:31 pm, Jerry Avins <j...@ieee.org> wrote: > >> Scott Seidman wrote: > >>> "Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in > >>>news:NqKdnQQu6dSz3NLanZ2dnUVZ_o6knZ2d@centurytel.net: > >>>> Now, it is true that the samples in (2) might represent a perfectly > >>>> bandlimited signal. > >>> I'm still not getting it > >>> Let's try this... > >>> I(n)=1 0 0 0 0 0 0 0 0 0...... > >>> The FFT of that has zip to do with aliasing. > >>> same for I(n-1), and thus I(n)+I(n-1) > >>> But for some reason, the FFT of > >>> 1 1 0 0 1 1 0 0 1 1 0 0 ...... > >>> has something to do with aliasing, simply because you can get to the same > >>> signal from a clipped sine wave? > >>> Once you're in the digital domain, you can create any signal you want, and > >>> aliasing doesn't enter the picture. The A to D is where aliasing comes in. > >>> No A to D, no aliasing--- or, are we just defining the results of a > >>> circular convolution in the frequency domain to be aliased by definition?? > >> Let's stick to the original question instead of becoming language > >> lawyers. Of course every set of samples that has a Fourier transform > >> that doesn't blow up represents a bandlimited function and only a > >> bandlimited function, but a set of alternating equal-length groups of > >> positive and negative samples does not represent a sampled bandlimited > >> square wave. I think it's pretty clear that Suren thought it did, FFTed > >> one, and was confused by what he saw. You reject my explanation of what > >> he saw. What do you offer in its place? > > > I suggest a simple experiment, take a vector and fill > > it with square waves (-1,1 at a 50% duty cycle) with a > > wavelength or repeat cycle exactly periodic in the vector > > length, and perform an fft on that vector. I just tried > > this with 64 cycles of square waves inside a vector of > > length 1024 and only saw odd multiples of 16 bins in the > > fft magnitude results. The aliasing showed up by altering > > the magnitude of the existing high frequency odd multiples > > of the fundamental, not by adding any new non-harmonic > > frequencies (as per the OP's observation). > > > The easiest way to get "bin splatter" was to change the > > square wave frequency so that it was no longer periodic > > in the fft aperture. Another way was to change the > > periodic 1,-1 waveform so that it no longer had a 50% > > duty cycle. > > Was that really 1, -1, 1, -1 .... or with longer blocks?64 cycles of period 16 (8 ones, 8 minus ones) fills 1024 samples (the clue was the fft result filling only odd multiples of 16 bins).






