Sunday, September 11, 2011

Fun with Filters!

A couple weeks ago I built a simple 1KHz 6Vpp Sine Wave Generator from a handful of opamps and passives I had laying around. You can check out that project here.

I thought it would be fun to quantify just how good of a Sine Wave this circuit was; after all it was just a wave-shaped triangle wave, so I wasn't expecting  too much. But if I quantify how good of a sine wave it is I can tweak the circuit to try and make if better.

Since my Sine Wave is at 1KHz I thought I'd measure its quality using an audio Total Harmonic Distortion (THD) technique.
Essentially, a perfect sine wave should only have a single frequency component at the fundamental frequency, but real sine waves have harmonic distortion. This harmonic distortion is the part of the sine wave that we really don't want; a poor sine wave has lots of harmonic content and a good sine wave has little to no harmonic content. So if we measure the amplitude of the harmonics we can quantify how good our sine wave is!

What we need to do is design a Notch filter at 1KHz. This will remove the fundamental frequency and leave the Harmonic content. Below is an LTSPICE schematic of Sine Wave Generator and Notch Filter.
The next picture is the frequency response of the notch filter; you can see it is centered at 1KHz.
When the 1KHz signal is passed through the 1KHz centered notch filter the fundemental frequency is removed and what is left is the Harmonic content. You can see the 3rd harmonic at ~3KHz is what is left.
(The blue is the signal coming out of the Filter)
Below is the FFT of the input Sine Wave and the Output of the Notch Filter; you can see the fundamental frequency amplitude is lower with minimal effect on the harmonic content.

Now that I had a base line simulation working I grabbed my soldering iron and built up the 1KHz Notch Filter dead bug style in an Altoids box. I wish I had a Network Analyzer or at minimum a Spectrum Analyzer with a tracking output to measure my filters frequency response, but all I had was a function generator and a scope.  I swept the function generator's output frequency from 10Hz to 100KHz and could see that my filter worked well at filtering out 1KHz signals.


(Channel A = Input Signal, Channel B = Output of Notch Filter)
The output of the Sine Wave generator measured 2.25Vrms and the output of the Notch filter was 139mVrms. This gives me a THD of (139mV/2.25V) = 6%

I wanted a second opinion, so I grabbed a HP 331A Distortion Analyzer and set it up. I hadn't used one of these since I interned at an RF Radio Manufacturer back in 2002. I used it to measure receiver sensitivity performance.

I had to dig up a manual to remember how to setup the HP 331A. It is a bit confusing because you have to setup the meter to 100% full scale based on your input, then adjust the frequency & balance adjustments until you get the lowest % THD reading. I monitored the Output of the 331A with a scope to see that I had fully removed the 1KHz fundamental and all that was left was a dirty looking 3KHz waveform (3rd harmonic).

The HP 331A measured a THD of 7.4%; pretty close to my homemade notch filter 6% reading. It makes sense that my filter's THD measurement would be lower, because it probably attenuated the 3rd harmonic a bit more than the much more precise HP 331A's notch filter would do.

Below is a scope screen shot of the output of my notch filter (top) and the output of the HP 331A (bottom).
Both filters did a nice job removing the fundamental and the 3rd harmonic is defiantly the most dominate remaining frequency. This was a fun project and cool to see that my Notch Filter implementation's THD readings weren't that far off from a HP331A's measurements.

Update: Sept. 13th, 2011
 
I thought I would do one last test to see the performance of the Notch Filter on a much cleaner sine wave. I used a BK Precision 3011B to generate an identical (but much cleaner) 1KHz 6Vp-p Sine Wave and used the Notch Filter to measure its THD.
The center frequency of my notch filter looks to be ~1074Hz; that is where I got the best filter performance.
(Top = Input Sine Wave, Bottom = Output of Notch Filter)
The THD measured was (19.5mVrms / 2.25Vrms) = 0.86%, a much cleaner Sine Wave than my home brewed one at 6%.


Here are Links to my LTSPICE files: Sine_&_Filter, Filter, and Filter_ac.

Link to HP 331A Manual.

References:
Distortion Analyzer by Rod Elliott
HP Journal: Distortion Analyzer
Texas Instruments Notch Filter AppNote

5 comments:

  1. Hy, i like this very much. I also tried to do this year ago, for using it as THD detector in audio amplifiers. But i have a problem. I have volume 20 on my radio, and i measure sine wave with oscilloscope and the sine is fine(no clipping). I calculated THD and let's say i got 10%. But then i put volume up to MAX, on oscilloscope i see clipped sine(with distortion). But when i calculated THD i got lower about THD=2%. Why that?? Wouldn't be higher if i have clipped sine wave?

    Please help!

    ReplyDelete
  2. Atko,

    Thanks for your kind words. What sort of notch filter were you using? You need to be aware of the filters max input signal. For example the notch filter I did only has a max input of around 6Vp-p, so the input sine wave needs to be less than that. I am guessing that your 10% THD input sine wave was already saturating the filter and when you increased the volume the clipping actually reduced the amount of saturation in the filter. The radio's output is also setup to drive low impedance speakers 4-8 Ohms and your notch filters input impedance might be significantly higher.

    You are correct the clipped sine wave should have significantly more distortion. I am assuming the issue is the filter you used was not matched up to the signal frequency or level of the radio you were using well enough.

    ReplyDelete
  3. Tnx for the reply. I used the same notch filter as you do(from that page project:distortion analyzer).

    Question: do you measure at the output of filter just AC voltage or RMS Voltage? After my test i was thinking about that, that i need RMS value and then devide it V2(rms)/V1(rms) and get THD as result.

    If you can help me...i want to do some distortion/clipping analyzer for audio amplifiers (any sort,power ..). From radio i get clean 40hz, and with oscilloscope i measure it on the output of amplifier. While i am raising gain on amplifier, amplitude of sine is also raising, and at one moment on oscilloscope there is no more clean sine wave but cutted on peaks(top/bottom). That is clip, which i want to measure. So i want to build some analyzer which will detect that clipped signal. I tried some circuit with comparator, but for each amplifier i need to calibrate it with oscilloscope so it is unusefull for me.

    I need something like that filter, which will filtered 40hz and leave only harmonics which can tell me if there is distortion or not. But i need like universal stuff so i don't have to calibrate for each amplifier. So i can use it on amp with 100W or with 10.000w ... Any easy or understandable way to do it?

    thank you

    ReplyDelete
  4. Dear thanks for your wonderful easy going description of your work. I am also trying to work on a notch filter on lt spice but i am facing a lil problem which am sure it'll be easy for you. I need a 500hz notch filter but i am not getting the correct output , perhaps i did a mistake in the components values. I uploaded the circuit and graph over http://khuwair.blogspot.com/2012/05/notch-filter-lt-spice.html
    because i couldn't upload it here in the comment.

    i will highly appreciate your help

    ReplyDelete
    Replies
    1. Hey Al-Yaqdhan,

      Your filter topology isn't quite right for a notch filter. Check out this LTSPICE file

      http://www.divshare.com/download/17679042-b87

      This will give you a 500Hz notch filter with only a buffer opamp. You'll need to play with the values to get resistor and cap values you can actually buy.

      Delete