Fourier transform of a lowpass filter

Thread Starter

JohanEricson

Joined Aug 30, 2017
36
Hi!
First let me set the stage for my question:
I'm writing a report on lowpass fitlers and Fourier series. I have a filter with the transferfunction H(w) = a/(jw+a) and a signal that can be described by the fourier series as shown in the picture "fourier square".
First i plot the fourierseries through the filter in MATLAB and varied the value for a, and as expected the bigger the a, the bigger the frequency content. You can se the result for a=10 in the picture "a=10"

I then did the same thing in simulink, the same square signal and the same filter, and at first i was not suprised at all about the result seen in picture "scope a10".

But as i sat down starting to think about it i realised, why doesen't the plot and the scope image look the same?
I mean, i filter out some frequency components of the square wave in both cases..? And for the same filter and same value of a it should be the same frequency components.

I realise this probably is a case theory vs. reality, but i cant wrap my head around it..
The reason i didn't think of it as something "strange" at first is that all the time i was thinking of it as a simple RC filter and seeing the output as the charge and discharge of the capacitor having in mind that it nowhere said that it actually is a RC-filter.

What is happening here, why cant we se the harmonics in the real world case? are they just very attenuated?

So basically my question is: Why does the two prctures differ when they describe the same situation?

Thank You!
 

Attachments

MrAl

Joined Jun 17, 2014
11,389
Hello,

I do not know how your software handles this, but with a quick glance it appears that the second picture "scope a10.jpg" is the signal you are working with, and the first picture "A=10.jpg" is the signal after reconstructing but with harmonics limited to maybe the fifth harmonic. So it appears either the way you are doing it or the software itself is limiting the reconstruction to only the first 5 harmonics so you will see artifacts which appear almost like little sine waves riding on the original signal. To see a better reconstruction find out how to increase the harmonics up to maybe the 21st or even higher. The higher you go the better it starts to look except for the edge ringing which just gets sort of thinner.

I did not check your functions to see if they were correct, but you'd have to supply the exact timing of the pulse wave for that, so i assume they are correct. If not, then they have to be corrected. If you go higher in harmonics for the reconstruction and it does not get better, then they are most likely wrong.
 

Papabravo

Joined Feb 24, 2006
21,159
Any series can be truncated and have a finite number of terms along with the associated errors; or it can have an infinite number of terms and be as accurate as desired. In many programming languages, the transcendental functions are computed with truncated Chebyshev series which limit the maximum error over the interval of the approximation.
 

Thread Starter

JohanEricson

Joined Aug 30, 2017
36
Hello,

I do not know how your software handles this, but with a quick glance it appears that the second picture "scope a10.jpg" is the signal you are working with, and the first picture "A=10.jpg" is the signal after reconstructing but with harmonics limited to maybe the fifth harmonic. So it appears either the way you are doing it or the software itself is limiting the reconstruction to only the first 5 harmonics so you will see artifacts which appear almost like little sine waves riding on the original signal. To see a better reconstruction find out how to increase the harmonics up to maybe the 21st or even higher. The higher you go the better it starts to look except for the edge ringing which just gets sort of thinner.

I did not check your functions to see if they were correct, but you'd have to supply the exact timing of the pulse wave for that, so i assume they are correct. If not, then they have to be corrected. If you go higher in harmonics for the reconstruction and it does not get better, then they are most likely wrong.
Thank you AGAIN MrAI for your answer!
I think we are talking about to different things, I guess you are talking about the "square wave fitting" of the signal seen in the picture "A=10"? That one is limited in its frequency content by the filter H(w) = A/(jw+A) and is therefore not the same as the blue square wave in
"scope a10" which is the unfiltered signal.

But the yellow line in "scope a10" is the same signal through the same filter as the one in "A=10", so the question is why don't they look the same?

Basically why, if i put the same filter on a fourier series and on a "real signal" don't i get the same result?

Do i make any sense?
I don't really know how express what i think.
maybe this is more clear: https://electronics.stackexchange.c...r-applied-to-a-square-wave-gives-a-weird-wave

And yes there is an answer in the link, but i was hoping to be able to ask some further questions. :D
 

MrAl

Joined Jun 17, 2014
11,389
Thank you AGAIN MrAI for your answer!
I think we are talking about to different things, I guess you are talking about the "square wave fitting" of the signal seen in the picture "A=10"? That one is limited in its frequency content by the filter H(w) = A/(jw+A) and is therefore not the same as the blue square wave in
"scope a10" which is the unfiltered signal.

But the yellow line in "scope a10" is the same signal through the same filter as the one in "A=10", so the question is why don't they look the same?

Basically why, if i put the same filter on a fourier series and on a "real signal" don't i get the same result?

Do i make any sense?
I don't really know how express what i think.
maybe this is more clear: https://electronics.stackexchange.c...r-applied-to-a-square-wave-gives-a-weird-wave

And yes there is an answer in the link, but i was hoping to be able to ask some further questions. :D
Hello again,

The answer lies in your question:
"Basically why, if i put the same filter on a fourier series and on a "real signal" don't i get the same result?"

This is not a question that is technically detailed enough to be able to answer the question without more information.
The question turns to exactly what you mean when you say you "put" the same filter on the Fourier Series, and on a "real" signal.

You would have to describe the process you use to "put" any signal through a filter and that will clear this up. The reason i say this is because if you have an infinite Fourier Series and you filter it correctly and then reconstruct the signal from that, you will get the same result as if you just do it in the time domain. If you dont, then something is wrong with the way you "put" it through the filter.

What i suspect here, just a guess, is that you may be artificially eliminating harmonics in order to draw the first picture, and that is not teh same thing that the filter does. The filter acts on each harmonic in a slightly different way, both for amplitude and phase shift, and that has to be taken into account when "eliminating" any harmonics.
For example, if we take an ordinary square wave and just do not include harmonics greater than say 5, then we will see a squarish wave with ripples not really a signal that looks like a square wave filtered by a low pass filter. To get the right output signal from the Fourier components, we have to do each one separately and add the results, including any phase shift.

So the problem is most likely a misinterpretation of how a filter actually acts on harmonics. It does not just take the higher ones to zero, there is always some left with a non ideal low pass filter.

Take another look and see if you can find out what went wrong, Without seeing exactly what you did it will be hard to tell for sure.
If you still cant find anything, i'll see if i can recreate your results with some arbitrary square wave and show the results from a time domain standpoint and a frequency domain standpoint using a number of harmonics.
 

Thread Starter

JohanEricson

Joined Aug 30, 2017
36
Hi again!

Okay i see what you mean.
I used MATLAB to plot the Fourier series with this code that was given to me.
A = 7;
k_max = floor(2*A/pi);
w0 = pi/2;
t = 0:0.01:10;
a0 = 3/4;
y = a0;
for k = 1:k_max
ak = (1/(k*pi))*sin(k*3*pi/2);
bk = (1/(k*pi))*(1-cos(k*3*pi/2));
wk = k*w0;
belopp = A/(sqrt(wk^2+A^2));
fas = -atan(wk/A);
part = belopp*(ak*cos(wk*t+fas)+bk*sin(wk*t+fas));
y = y+part;
end
plot(t,y)

And what i did to change the frequency content was just do change the filter parameter A.

As far as i can tell the filter is acting upon each frequency component expect the one where k=0.

Starting to feel like I may be comparing apples and oranges but I just can't see it.
 

MrAl

Joined Jun 17, 2014
11,389
Hello again,

Ok i guess your signal is up for 3/4 of the time and zero for 1/4 of the time right?

I happened to do the inverse of that, up at 1 for 1/4 of the time and down to zero for 3/4 of the time. The results are shown int eh attachment. You can see that they are almost identical going up to the 21st harmonic.
You can try that exercise too.

I'll try your signal a little later hopefully. If done right there's no reason why it should not work, except for a math error.
However, since max k is only around 4 or 5, the reconstructed signal will look very very ripply so you'll see lots of extra waves in it.
Try increasing max k to some larger value like 21.

LATER:
Ok tried your signal with a filter 1/(s+1) and i get the same results as the simulation again. The only difference is that the simulation has sharper corners and that is because i limit the reconstructed plot to the 21st harmonic. Even with n max up to 4 though i get reasonable results, just a little bit wavy and rounded.
The second pic shows this.
 

Attachments

Last edited:

Thread Starter

JohanEricson

Joined Aug 30, 2017
36
Hi!

hmm okay, i'm going to fiddle around with my values a bit and se i can draw some conclusions and i'll come back with my findings.

Thanks!
 

MrAl

Joined Jun 17, 2014
11,389
Hello again,

I am wondering how the line t=0:0.01:10 or whatever affects the summation later.
I dont use Matlab so i am not that familiar with the syntax.

If it is summing each time for every t, then that's not right.
You could do it differently i think to make sure it sums correctly if you have a doubt too.
Everything else looks ok.
 

Thread Starter

JohanEricson

Joined Aug 30, 2017
36
Hi again!

We've been doing some testing in matlab!
First off, t=0:0.01:10 is just setting the x-axis in the plot from zero to ten, increasing in steps by one.
The summation is done by y = y+part through iteration of K.

And we did some experiments with k_max. We just set it to 100 and watched what happened, and got exactly the result we were looking for!
So what is happening?
The things depending on K in the code is the iteration of the for-loop and the angular frequency in the fourier series.
Are we including more harmonics now that we sum more terms, if so, wouldn't that mean we are changing the filter?

Peace!
 

MrAl

Joined Jun 17, 2014
11,389
Hi again!

We've been doing some testing in matlab!
First off, t=0:0.01:10 is just setting the x-axis in the plot from zero to ten, increasing in steps by one.
The summation is done by y = y+part through iteration of K.

And we did some experiments with k_max. We just set it to 100 and watched what happened, and got exactly the result we were looking for!
So what is happening?
The things depending on K in the code is the iteration of the for-loop and the angular frequency in the fourier series.
Are we including more harmonics now that we sum more terms, if so, wouldn't that mean we are changing the filter?

Peace!
Hi,

No the filter acts on ALL harmonics that you throw at it. Of course those harmonics have to be the ones that are present in the signal though. The more harmonics you include the better the reconstruction looks because it gets the higher frequencies which are responsible for the sharp turns.

The filter only changes if you change the amplitude and/or phase shift caused by that filter.

So you got the right result now? That's great. Maybe you can plot it now. Did it match the plot i did except maybe in overall amplitude?
 

Thread Starter

JohanEricson

Joined Aug 30, 2017
36
Hi,

No the filter acts on ALL harmonics that you throw at it. Of course those harmonics have to be the ones that are present in the signal though. The more harmonics you include the better the reconstruction looks because it gets the higher frequencies which are responsible for the sharp turns.

The filter only changes if you change the amplitude and/or phase shift caused by that filter.

So you got the right result now? That's great. Maybe you can plot it now. Did it match the plot i did except maybe in overall amplitude?
Hi!
After speaking to my professor it turns out that the two cases were never meant to be the same, and so that explains why the term k_max was so small. But we had a discussion about the differences and the reasons they behave like they do, and I think it cleared most of it up.

I understand now that I'm comparing two different cases:
In the Fourier plot we have CUT OUT the higher harmonics, basically making a filter with a frequency response that is STOPPING all the above frequencies.

But in the other case (also the real case) the higher harmonics cant be totally cut out, only strongly attenuated and phase shifted but still present in the result.

And this real case can be plotted in the Fourier plot if we take in into consideration more harmonics. Of course, we cant plot infinitely many harmonics but a big number like 100 would get us a good estimation.
 

MrAl

Joined Jun 17, 2014
11,389
Hi!
After speaking to my professor it turns out that the two cases were never meant to be the same, and so that explains why the term k_max was so small. But we had a discussion about the differences and the reasons they behave like they do, and I think it cleared most of it up.

I understand now that I'm comparing two different cases:
In the Fourier plot we have CUT OUT the higher harmonics, basically making a filter with a frequency response that is STOPPING all the above frequencies.

But in the other case (also the real case) the higher harmonics cant be totally cut out, only strongly attenuated and phase shifted but still present in the result.

And this real case can be plotted in the Fourier plot if we take in into consideration more harmonics. Of course, we cant plot infinitely many harmonics but a big number like 100 would get us a good estimation.
Hello again,

That's what i was suggesting in post #5. That is still an interesting case though in that if we completely eliminate all the harmonics above some number like 4 or 5, that would be exactly what we would get with an ideal low pass filter. An ideal low pass filter is not realizable in the real analog world but a digital filter might be able to do that.
An ideal low pass filter with a gain of 1 would allow any pass band frequencies to pass through with no attenuation and completely eliminate any above that.
 

MrAl

Joined Jun 17, 2014
11,389
Hello again,

One last note. I intended to do this earlier but didnt get a chance to do it until now.

Here is a side by side comparison of your original plot vs a plot using a perfect ideal low pass filter.
Note how similar they look. The original has a little phase shift that's the only difference i think.
 

Attachments

Top