The Fourier series of a square wave contains only odd harmonics http://mathworld.wolfram.com/FourierSeriesSquareWave.html The amplitude of the odd harmonics is 4/(k*pi) for k = 1, 3, 5, ... If I try to see this in Matlab, I see the amplitude as only 2/(k*pi). Is there something wrong in my Matlab code (below)? N = 32768; fc = 100e3; fs = 16*fc; % sampling frequency fm = fs/256; % modulating frequency x = square(2*pi*fm*(0:N-1)/fs); % square wave varying between +1 and -1 freq = (fs/N)*(-N/2:1:(N-1)/2); plot(freq/1e3, (fftshift(X));
Fourier series of a square wave
Started by ●March 4, 2008
Reply by ●March 4, 20082008-03-04
>The Fourier series of a square wave contains only odd harmonics > >http://mathworld.wolfram.com/FourierSeriesSquareWave.html > >The amplitude of the odd harmonics is 4/(k*pi) for k = 1, 3, 5, ... > >If I try to see this in Matlab, I see the amplitude as only 2/(k*pi). Is >there something wrong in my Matlab code (below)? > >N = 32768; >fc = 100e3; >fs = 16*fc; % sampling frequency >fm = fs/256; % modulating frequency > >x = square(2*pi*fm*(0:N-1)/fs); % square wave varying between +1 and -1X = fft(x)/N;>freq = (fs/N)*(-N/2:1:(N-1)/2); >plot(freq/1e3, (fftshift(X));Is this the power is split equally in +ve and -ve frequencies?
Reply by ●March 4, 20082008-03-04
"sumeer" <sumeerbhatara@yahoo.com> wrote in message news:Df2dnQZKJ-qse1DanZ2dnUVZ_uCinZ2d@giganews.com...> The Fourier series of a square wave contains only odd harmonics > > http://mathworld.wolfram.com/FourierSeriesSquareWave.html > > The amplitude of the odd harmonics is 4/(k*pi) for k = 1, 3, 5, ... > > If I try to see this in Matlab, I see the amplitude as only 2/(k*pi). Is > there something wrong in my Matlab code (below)? > > N = 32768; > fc = 100e3; > fs = 16*fc; % sampling frequency > fm = fs/256; % modulating frequency > > x = square(2*pi*fm*(0:N-1)/fs); % square wave varying between +1 and -1 > > freq = (fs/N)*(-N/2:1:(N-1)/2); > plot(freq/1e3, (fftshift(X));As far as the code goes, I don't get the plot scaling at all. I note that you're computing an FFT of a finite sequence. The Fourier Series is taken from -inf to +inf. So, I'm not surprised they aren't exactly the same - but there may be a reason why they would be; I just don't know. The time sequence clearly introduces aliasing. Also, you have an uneven function of time so that the FFT isn't conveniently purely real - actually it's purely odd. Why do that when it might be easier to deal with a little bit by making the square wave even in time - and then the FFT should be purely real. Fred
Reply by ●March 5, 20082008-03-05
On Mar 4, 4:22 pm, "sumeer" <sumeerbhat...@yahoo.com> wrote:> >The Fourier series of a square wave contains only odd harmonics > > >http://mathworld.wolfram.com/FourierSeriesSquareWave.html > > >The amplitude of the odd harmonics is 4/(k*pi) for k = 1, 3, 5, ... > > >If I try to see this in Matlab, I see the amplitude as only 2/(k*pi). Is > >there something wrong in my Matlab code (below)? > > >N = 32768; > >fc = 100e3; > >fs = 16*fc; % sampling frequency > >fm = fs/256; % modulating frequency > > >x = square(2*pi*fm*(0:N-1)/fs); % square wave varying between +1 and -1 > X = fft(x)/N; > >freq = (fs/N)*(-N/2:1:(N-1)/2); > >plot(freq/1e3, (fftshift(X)); > > Is this the power is split equally in +ve and -ve frequencies?Real valued signals are represented by complex conjugate pairs split between the +f and -f bins. Complex valued signals are not constrained to split evenly between positive and negative frequencies in the FT or FFT.
Reply by ●March 5, 20082008-03-05
Well, the problem is that you are trying to bypass too many conceptual steps, and i explain: the link to MathWorld that you give, examines the "Fourier Series" of a "continuous-time pulse". However, via the MATLAB code that you provide, you create a "discrete-time pulse" and in the sequel you take it's "Discrete Fourier Transform". So, if you want to gain insight on what happens you will have to examine the discrete-time exactly equivalent analysis of the link, and then try to simulate it. It is quite possible that the coefficients of the discrete-time Fourier series are slightly different. Manolis
Reply by ●March 5, 20082008-03-05
If we talk about the complex Fourier series, Matlab FFT matches with what it should be http://cnx.org/content/m0065/latest/ Anyone has any comments?
Reply by ●March 5, 20082008-03-05
"sumeer" <sumeerbhatara@yahoo.com> wrote in message news:Lt2dnXbcy4FIV1PanZ2dnUVZ_qqgnZ2d@giganews.com...> If we talk about the complex Fourier series, Matlab FFT matches with what > it should be > > http://cnx.org/content/m0065/latest/ > > Anyone has any comments?I don't readily see how you reach that conclusion... Perhaps you can illuminate. ---------------- To extend the comments about FFT vs. Fourier Series: Some identities: ***time <> frequency ... Fourier Transform or as specified - a transform pair ***Continuous time, periodic <> Discrete frequency and infinite extent A Fourier Transform of the continuous, periodic time function will end up with discrete frequencies and lends itself to using the Fourier Series formulation to get the same thing. ***Discrete time, periodic <> Discrete frequency, periodic A Fourier Transform of a discrete, periodic time function will end up with discrete frequencies AND will be periodic. This differs from a Fourier Series of a continuous, periodic time function in that the former is periodic while the latter is of infinite extent. A key difference, no matter how you want to formulate or describe it, goes something like this: 1) Start with a square wave with infinitely sharp transitions. 2) Compute the Fourier Series. It will have infinite extent. This means infinite bandwidth. 3) Now, sample the square wave. This violates the Nyquist criterion because the bandwidth of the sampled function isn't limited. Aliasing in frequency occurs. 4) Now, whatever you do with the sampled square wave (e.g. compute a DFT) isn't going to match the Fourier Series that you computed in (2) above. ------ To apply the Fourier Series, the time function must be periodic. Indeed, when we compute a Discrete Fourier Transform, that's an assumption that's made - since the frequency domain components are perforce discrete and harmonically related. And, if the time waveform is captured for exactly an integer number of cycles then this assumption of periodicity in time matches the intended waveform of infinite extent. But, when we sample in time we effectively force the frequency domain to become periodic. And that's not at all similar to the result of computing a Fourier Series where the higher frequency components generally decay with increasing frequency. I hope this helps clarify. Fred
Reply by ●March 5, 20082008-03-05
On Mar 5, 9:13 am, "Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote:> "sumeer" <sumeerbhat...@yahoo.com> wrote in message > > news:Lt2dnXbcy4FIV1PanZ2dnUVZ_qqgnZ2d@giganews.com... > > > If we talk about the complex Fourier series, Matlab FFT matches with what > > it should be > > >http://cnx.org/content/m0065/latest/ > > > Anyone has any comments? > > I don't readily see how you reach that conclusion... Perhaps you can > illuminate. > > ---------------- > > To extend the comments about FFT vs. Fourier Series: > > Some identities: > > ***time <> frequency ... Fourier Transform or as specified - a transform > pair > > ***Continuous time, periodic <> Discrete frequency and infinite extent > > A Fourier Transform of the continuous, periodic time function will end up > with discrete frequencies and lends itself to using the Fourier Series > formulation to get the same thing. > > ***Discrete time, periodic <> Discrete frequency, periodic > > A Fourier Transform of a discrete, periodic time function will end up with > discrete frequencies AND will be periodic. This differs from a Fourier > Series of a continuous, periodic time function in that the former is > periodic while the latter is of infinite extent. > > A key difference, no matter how you want to formulate or describe it, goes > something like this: > 1) Start with a square wave with infinitely sharp transitions. > 2) Compute the Fourier Series. It will have infinite extent. This means > infinite bandwidth. > 3) Now, sample the square wave. This violates the Nyquist criterion because > the bandwidth of the sampled function isn't limited. Aliasing in frequency > occurs. > > 4) Now, whatever you do with the sampled square wave (e.g. compute a DFT) > isn't going to match the Fourier Series that you computed in (2) above. > > ------ > To apply the Fourier Series, the time function must be periodic. Indeed, > when we compute a Discrete Fourier Transform, that's an assumption that's > made - since the frequency domain components are perforce discrete and > harmonically related. > > And, if the time waveform is captured for exactly an integer number of > cycles then this assumption of periodicity in time matches the intended > waveform of infinite extent. > > But, when we sample in time we effectively force the frequency domain to > become periodic. And that's not at all similar to the result of computing a > Fourier Series where the higher frequency components generally decay with > increasing frequency. > > I hope this helps clarify. > > FredIn other words, don't expect that the interpretations, coefficients and meanings of an expression with the big funky annotated E will be the same as those of a similar expression with the tall stretched annotated S. YAMV (Your annotations may vary), too. Dale B. Dalrymple http://dbdimages.com
Reply by ●March 5, 20082008-03-05
"dbd" <dbd@ieee.org> wrote in message news:9a8335e8-c446-4665-92e8-992d39b6149b@h11g2000prf.googlegroups.com...> In other words, don't expect that the interpretations, coefficients > and meanings of an expression with the big funky annotated E will be > the same as those of a similar expression with the tall stretched > annotated S. > > YAMV (Your annotations may vary), too. > > Dale B. Dalrymple > http://dbdimages.comRight. Except that the big funky annotated E (sigma) will be the same as those of a similar expression with the tall stretched annotated S when the function to be integrated / summed is discrete. You can always integrate. You can't always sum discrete elements unless they exist. Fred
Reply by ●March 5, 20082008-03-05
On Mar 5, 11:34 am, "Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote:> "dbd" <d...@ieee.org> wrote in message > > news:9a8335e8-c446-4665-92e8-992d39b6149b@h11g2000prf.googlegroups.com... > > > In other words, don't expect that the interpretations, coefficients > > and meanings of an expression with the big funky annotated E will be > > the same as those of a similar expression with the tall stretched > > annotated S. > > > YAMV (Your annotations may vary), too. > > > Dale B. Dalrymple > >http://dbdimages.com > > Right. Except that the big funky annotated E (sigma) will be the same as > those of a similar expression with the tall stretched annotated S when the > function to be integrated / summed is discrete. > > You can always integrate. You can't always sum discrete elements unless > they exist. > > FredWhat we need to look out for are those times when the tall stretched annotated S deals with things that are not as they actually exist. Dale B. Dalrymple






