R/E/P Community

Please login or register.

Login with username, password and session length
Advanced search  

Pages: [1]   Go Down

Author Topic: Theory question: filtered square waves exhibit higher peak values?  (Read 7021 times)

blueintheface

  • Newbie
  • *
  • Offline Offline
  • Posts: 24
Theory question: filtered square waves exhibit higher peak values?
« on: September 18, 2006, 06:38:17 AM »

One another board, someone posted that whenever they apply EQ (cut or filtering) the peak levels increase.

One explanation given was that:

' . . . it's pure math, and has nothing to do with digital vs analog, or even less to do with Logic's way to deal with digital audio . . . take a square signal and filter the high frequency components, and you will end up with a resulting signal that peaks higher . . . '

This makes no sense to me as an explanation for what is happening -   and it would seem more likely that this is a characteristic (flaw) in Logic's filtering algoritms?

I always thought that as a square wave is progressively (low-pass) filtered, it approcimates a sine wave of the same peak value . . .  ?

However, I'd love to be set straight on this, and if there is a technical explanation, could someone point me to it?

The original thread, with pic's, is here: http://logicprohelp.com/viewtopic.php?t=5489&sid=53117d8 8f5adbbc66ab2818ddb1f3418

P.S. I'm also unhappy with the explanation given in the same thread  
Logged

Jon Hodgson

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1854
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #1 on: September 18, 2006, 08:04:27 AM »

blueintheface wrote on Mon, 18 September 2006 11:38

I always thought that as a square wave is progressively (low-pass) filtered, it approcimates a sine wave of the same peak value . . .  ?



An understandable error, but an error nonetheless.

This would be easier to show graphically, but I'll try to do it in words and numbers.

A square wave is a sum of a fundamental, then odd harmonics scaled by the harmonic multiplier.

So you have a waveform that is

Fundamental + 1/3 * 3rd harmonic + 1/5 * 5th harmonic + 1/7 * 7th harmonic

and so on.

Now for simplicities sake lets assume a perfect brick wall lowpass filter, so anything above the cutoff is removed completely, and everything below it passes unhindered.

And rather than sweeping it down, let's sweep it up.

So we start with the filter set so that only the fundamental passes through, and then fundamental has a peak value of 1. So our waveform is a sine wave, peak 1.

Now we sweep the filter up so it lets through the third harmonic, what is the peak of the waveform now?

Well let's start by looking at the point in the waveform which was the peak before, i.e. one quarter of the way through the cycle, that is where the fundamental peaks, but it is also the point where the third harmonic peaks in the opposite direction. So the contribution of the fundamental is +1, but the contribution of the harmonic is -1/3, giving a level at that point of +2/3, or 0.667

In fact with just the third harmonic being allowed through as well as the fundamental the peak points in the waveform occur at different points and have a value of 0.833.

Basically adding the harmonic lifts some parts of the waveform up, and pushes others down, making it flatter on top, but also reducing the peak amplitude. As you add more and more harmonics it gets flatter and flatter, but each time the peak also gets slightly less.
Logged

danlavry

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 997
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #2 on: September 18, 2006, 06:40:07 PM »

blueintheface wrote on Mon, 18 September 2006 11:38

One another board, someone posted that whenever they apply EQ (cut or filtering) the peak levels increase.

One explanation given was that:

' . . . it's pure math, and has nothing to do with digital vs analog, or even less to do with Logic's way to deal with digital audio . . . take a square signal and filter the high frequency components, and you will end up with a resulting signal that peaks higher . . . '

This makes no sense to me as an explanation for what is happening -   and it would seem more likely that this is a characteristic (flaw) in Logic's filtering algoritms?

I always thought that as a square wave is progressively (low-pass) filtered, it approcimates a sine wave of the same peak value . . .  ?

However, I'd love to be set straight on this, and if there is a technical explanation, could someone point me to it?

The original thread, with pic's, is here:   http://logicprohelp.com/viewtopic.php?t=5489&sid=53117d8 8f5adbbc66ab2818ddb1f3418

P.S. I'm also unhappy with the explanation given in the same thread  


Hi,

The plot previously here is removed because it had an error - the amplitude of the fundumental was scaled wrong. Jon pointed it out, so I posted a corrected version a few posts later.

My conclusions are correct - when you filter out higher harmonics out of a square wave, the peaks increase. But my plot was confusing. The new plot should provide the proper visual.

Regards
Dan Lavry
http://www.lavryengineering.com  
 
Logged

Jon Hodgson

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1854
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #3 on: September 18, 2006, 08:17:54 PM »

Dan,

That plot doesn't look right to me.

If we take the fundamental with just the third harmonic.

The first peak will happen at 45 degrees, so the fundamental has a magnitude at that point of 0.707

The third harmonic will be at 3x45 = 135 degrees at this point, giving it a magnitude of 0.707 / 3 = 0.236

That gives a total amplitude of 0.707 + 0.236 = 0.943

Your graph shows a level of about 1.2 at that point.

Am I missing something?

Logged

AndreasN

  • Full Member
  • ***
  • Offline Offline
  • Posts: 247
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #4 on: September 19, 2006, 02:08:16 AM »

AFAIK; the fundamental harmonic should be 3dB higher than the ideal flat square wave(without ringing).


The various java applets at this site might provide useful. Especially the ones under the Signal Processing heading, the Fourier series applets and the Digital Filters applet.


Andreas N
Logged

blueintheface

  • Newbie
  • *
  • Offline Offline
  • Posts: 24
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #5 on: September 19, 2006, 06:44:56 AM »

Thank you for the explanations. It makes sense now  Very Happy
Logged

Jon Hodgson

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1854
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #6 on: September 19, 2006, 11:02:03 AM »

blueintheface wrote on Tue, 19 September 2006 11:44

Thank you for the explanations. It makes sense now  Very Happy


Except that none of us quite agree!!

Andreas, I'm getting a difference of 2.1dB when I calculate it out.

But actually Andreas' link is very useful, especially the Fourier Series Applet.

Firstly you can use it to confirm that the peak of the fundamental is higher than the peak of the generated square wave, but secondly you can use it to demonstrate a phenomenon which is possibly far more responsible for the phenomenon you see.

Set it to "phase and magnitude" mode.

Select a waveform, say a square wave.

Now grab the phase of the third harmonic (in the lower bar) and move it around, see what that does to the peak!

Note that for a continuous wave changing in isolation the phase of the various components wouldn't make it sound any different, though it might look massively different.

Analogue filters and many digital filters (including most of the ones you'll get in the EQ section of a mixer) affect phase of the various components as well as level, so could well result in increased peak levels as a result of this.



Logged

AndreasN

  • Full Member
  • ***
  • Offline Offline
  • Posts: 247
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #7 on: September 20, 2006, 04:12:06 AM »

Jon Hodgson wrote on Tue, 19 September 2006 17:02


Andreas, I'm getting a difference of 2.1dB when I calculate it out.


2.1dB is a bit odd number, perhaps you're calculating with a finite bandwidth/number of harmonics? That would leave some ringing at the edges.


The 3dB number is the same as the crest ratio(RMS to peak level) of a sine wave. Square wave have equal RMS and peak levels.

You also sorta said it yourself, I think? Quote: "The first peak will happen at 45 degrees, so the fundamental has a magnitude at that point of 0.707". At 90 degrees, that would be 1.414, 3dB, right..?

Also recall to get that number on the meters when linphase lowpass filtering an ideal(100% flat) computer generated square wave to the fundamental sine. Don't have the tools to test this here and now though.


This also addresses the thread starts question:
Quote:

"I always thought that as a square wave is progressively (low-pass) filtered, it approcimates a sine wave of the same peak value . . . ?


If the sine wave had the same peak value as the square, it would be 3dB lower in the level that counts more often than not - the RMS value. Peak levels have a tendency to vary all over the place without giving any hint of whats actually going on. RMS levels resembles the way we hear closer than peak level information does.




Im just a humble n00b though, learned this math stuff by intuition, so someone please correct me if needed! =)


Cheers,

Andreas N
Logged

Jon Hodgson

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1854
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #8 on: September 20, 2006, 04:47:11 AM »

AndreasN wrote on Wed, 20 September 2006 09:12

Jon Hodgson wrote on Tue, 19 September 2006 17:02


Andreas, I'm getting a difference of 2.1dB when I calculate it out.


2.1dB is a bit odd number, perhaps you're calculating with a finite bandwidth/number of harmonics? That would leave some ringing at the edges.


I'm calculating at the 90 degree point, went to the 513th harmonic and split the difference between the last two results, they were within .002 of a dB by that time anyway.


Quote:

The 3dB number is the same as the crest ratio(RMS to peak level) of a sine wave. Square wave have equal RMS and peak levels.


Except that that would mean that your sine wave contained exactly the same signal power as the square wave, despite the fact that the square wave has a number of signals added, rather unlikely.

Quote:

You also sorta said it yourself, I think? Quote: "The first peak will happen at 45 degrees, so the fundamental has a magnitude at that point of 0.707". At 90 degrees, that would be 1.414, 3dB, right..?


No, at that point the fundamental wuld have a value of 1. With only the third harmonic added the level would be 0.667.

Quote:

Also recall to get that number on the meters when linphase lowpass filtering an ideal(100% flat) computer generated square wave to the fundamental sine. Don't have the tools to test this here and now though.


You don't need the tools, just take the 90 degree point.

Now for you to be correct, if the fundamental peaks 3dB higher than the square, and the fundamental peaks at 1 (happens at 90 degrees) then the square at that point should have a level of 0.707

Now at that point it's easy to work out the level of square wave is

sin(90) + sin(3*90)/3 + sin(5*90)/5 + sin(7*90)/7 ....

which becomes

1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 ......

now lets just move along that equation, adding a term at a time, the result are

1
0.667
0.867
0.723
0.835

Note the last two, the result is never going to drop down to 0.707, in fact it is converging on a value somewhere in the region of  0.779


Quote:

If the sine wave had the same peak value as the square, it would be 3dB lower in the level that counts more often than not - the RMS value. Peak levels have a tendency to vary all over the place without giving any hint of whats actually going on. RMS levels resembles the way we hear closer than peak level information does.


Correct, except for the 3dB bit

Quote:

Im just a humble n00b though, learned this math stuff by intuition, so someone please correct me if needed! =)


Intuition is a good start, but maths works better if you actually write the numbers down and juggle them around a bit  Smile
Logged

AndreasN

  • Full Member
  • ***
  • Offline Offline
  • Posts: 247
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #9 on: September 20, 2006, 05:11:34 AM »

Jon Hodgson wrote on Wed, 20 September 2006 10:47


I'm calculating at the 90 degree point, went to the 513th harmonic and split the difference between the last two results, they were within .002 of a dB by that time anyway.


Okay! I'm with you.

Quote:

Except that that would mean that your sine wave contained exactly the same signal power as the square wave, despite the fact that the square wave has a number of signals added, rather unlikely.


Guess that's where my train of thought lost the track. :D

Quote:

Intuition is a good start, but maths works better if you actually write the numbers down and juggle them around a bit  :)


Hehe.. For sure.

I'm here to learn and love to stand corrected! Thanks for the quick reply and good explanation.


Andreas - shambling back to trigonometry class..
Logged

ericjenson

  • Full Member
  • ***
  • Offline Offline
  • Posts: 218
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #10 on: September 21, 2006, 01:44:42 AM »

as an ME, experimenting years ago, i used to brickwall lopass everything under about 150 Hz, and then clip the hell out of it.
say, i put a gain of 12 dB, for sake of example , so it would digitally clip, then i would drop the level 12 dB and reapply the filter, what i got were peaks sometimes at -10 dB or sometimes a little more, depending on how severely clipped.

i was doing this to try and gain headroom for final loudness in my mastering without distorting the higher freq's so much.

even tho after the filtering the peaks of the square waves would go up, i was still gaining headroom and i noticed that the impact of the bass notes and kick drum were still percieved the same before and after,

i also noticed that the attack , or velocity of the waveforms weren't sacrificed, a sort of saturation was occuring, but in a roundabout way. the wave forms were no longer square tops after filtering, but nicely rounded once again, with transients still intact.

i have since abandoned this practice, but later found out that in certain broadcasting processors for FM radio, the same thing was being done, but not just to the bass freq's but multiband clipping, filtered in each band after clipping to minimize distortion, then mixed back together again to gain higher modulation(RMS) before final limiting.

i never thought about it to the depth that this thread has gone to, but it is interesting to see the math behind this phenomenon.

thx

Logged
Eric Jenson
Mastering Engineer
Acoustics Engineering Apprentice

danlavry

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 997
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #11 on: September 21, 2006, 02:02:14 PM »

Jon Hodgson wrote on Tue, 19 September 2006 16:02

blueintheface wrote on Tue, 19 September 2006 11:44

Thank you for the explanations. It makes sense now  Very Happy


Except that none of us quite agree!!




First, I was out for a few days, so I am sorry to be so slow to respond.

Here is the point:

When one is taking a sine wave with amplitude=1, and adding to it a third harmonics with amplitude=3, you are going to end up with less then unity.

But the above does NOT deal with the question at hand. The STARTING POINT is a square wave of amplitude one. Such a square wave, with amplitude=1 is not made out of an amplitude series of 1, 1/3, 1/5... There is a 4/pi multiplier constant:

Vsquare = 4/pi * [1*sin(f1*t)+ 1/3*sin(3*f1*t)+1/5*sin(5*f1*t)...

So if you want to see what happens when you remove the harmonics of a square wave, you need to assign them the proper constant, and then we can all agree that the filtering will cause peaks to go over 1.

Best Regards
Dan Lavry
http://www.lavryengineeing.com
Logged

danlavry

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 997
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #12 on: September 21, 2006, 02:48:26 PM »

AndreasN wrote on Tue, 19 September 2006 07:08

AFAIK; the fundamental harmonic should be 3dB higher than the ideal flat square wave(without ringing).


The various java applets at this site might provide useful. Especially the ones under the Signal Processing heading, the Fourier series applets and the Digital Filters applet.

Andreas N


Hi Andreas,

Almost... It is 4/pi higher (about 2.098dB).
And yes, it is back to "basic trigonometric Forier series", no rocket science for some, but rather confusing for others...

I answered the question by starting off with an assumption that the square wave was perfect. That by itself is a simplification, and as a rule there is some ringing to start with (over 9%).

But the general answer is:
When filtering a square wave (removing the higher harmonics), the peaks will get bigger.

Regards
Dan Lavry
http://www.lavryengineering.com    
Logged

Jon Hodgson

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1854
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #13 on: September 21, 2006, 02:55:21 PM »

danlavry wrote on Thu, 21 September 2006 19:02

Jon Hodgson wrote on Tue, 19 September 2006 16:02

blueintheface wrote on Tue, 19 September 2006 11:44

Thank you for the explanations. It makes sense now  Very Happy


Except that none of us quite agree!!




First, I was out for a few days, so I am sorry to be so slow to respond.

Here is the point:

When one is taking a sine wave with amplitude=1, and adding to it a third harmonics with amplitude=3, you are going to end up with less then unity.

But the above does NOT deal with the question at hand. The STARTING POINT is a square wave of amplitude one. Such a square wave, with amplitude=1 is not made out of an amplitude series of 1, 1/3, 1/5... There is a 4/pi multiplier constant:

Vsquare = 4/pi * [1*sin(f1*t)+ 1/3*sin(3*f1*t)+1/5*sin(5*f1*t)...

So if you want to see what happens when you remove the harmonics of a square wave, you need to assign them the proper constant, and then we can all agree that the filtering will cause peaks to go over 1.

Best Regards
Dan Lavry
http://www.lavryengineeing.com


Actually the amplitude of the square wave was not defined in the original question. The question was about relative amplitudes not absolute ones.

Firstly the graph you posted is confusing, all the plots other than the pure sine wave appear to be scaled such that they are leading to a square wave of a given amplitude, I'll ignore the scale on the left hand side and just say the amplitude of the final "perfect" square wave is 1. Therefore it would be reasonable for people to assume that the pure sine wave was also scaled accordingly, but it isn't, since if it was then as you just pointed out it's amplitude would be 4/pi, not 1 as in the graph.

Secondly in your original post you stated

Quote:

Alternatively, you could say that as soon as you added a third harmonic, the peak is up by about 20% (almost 1.6dB). Then as you add harmonics (5th, 7th...) the peaks goes down towards 9%...


Well from the structure of that sentence, combined with the graph, it would be reasonable to assume that what you meant was  "as soon as you added a third harmonic [to the fundamental], the peak is up by about 20%", which wouldn't be correct. What is correct is that the combination of fundamental plus third harmonic only is about 20% higher than resultant square wave with infinite harmonics.

It would also be correct to say that the fundamental alone is about 27% up on the final square wave.

It may not be what you intended to say, but that is how it reads, and that is what the graph appears to show, so I thought it best to clarify that for people.
Logged

danlavry

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 997
Re: Theory question: filtered square waves exhibit higher peak values?
« Reply #14 on: September 21, 2006, 03:52:25 PM »

[/quote]

Jon said:

It would also be correct to say that the fundamental alone is about 27% up on the final square wave.

It may not be what you intended to say, but that is how it reads, and that is what the graph appears to show, so I thought it best to clarify that for people.[/quote]


Hi Jon,

You are correct. The fundamental is not scaled correctly. I started with a sine wave of unity, then I added the other waveforms. That was an error. This time I started with a general expression, which scaled ALL the waveforms, including the case of a single fundamental.  

Here is the graph with a proper fundamental:

index.php/fa/3505/0/

Jon, thank you for pointing it out. I am sorry for causing the confusion, and I hope the revised plot gets us all to be in agreement.

Regrads
Dan Lavry
http://www.lavryengineering.com
Logged
Pages: [1]   Go Up
 

Site Hosted By Ashdown Technologies, Inc.

Page created in 0.146 seconds with 17 queries.