## Wednesday, January 12, 2011

### On an LC Bandpass Filter for receivers… in PHP

Yesterday I was reading "brainwagon.org" blog and there was a nice piece of software code for an LC bandpass filter design, the code was in Python and although it can run on my computer decided to convert it to PHP as an relaxation exercise...

Here's the result of the quick hack on the original code, I named it lcbandpass.php.

`?php#!/usr/bin/env python# An simple program to compute the value of components needed for a# Doubly Tuned Circuit LC filter that can serve as a bandpass filter# for homebrew receivers.   The equations come from the sidebar equations# presented in EMRFD (I have the first edition, where it appears on page# 3.14)## Written by Mark VandeWettering## changed (lousily) to php by Ricardo - CT2GQV// from math import sqrt, pi// edit bellow to suit your needs...\$F = 7050000;            # frequency of operation in Hz\$B = 100000 ;             # bandwidth\$R0 = 50;                 # load resistance\$L = 0.000001156;         # inductance of the two coils\$Qu = 250;               # "Q" of the coils, approximate// end edit\$k = sqrt(2)/2;         # I hardcoded the Butterworth filter equations\$q = sqrt(2);\$pi = 3.1415927; // I think...from memory\$omega = 2.0 * \$pi * \$F ;\$c0 = 1. / (\$omega * \$omega * \$L) ;\$c12 = \$c0 * \$k * \$B / \$F ;\$qe = (\$q * \$F * \$Qu) / (\$B * \$Qu - \$q * \$F) ;\$ce = 1.0 / (\$omega * sqrt(\$R0 * \$qe * \$omega * \$L - \$R0 * \$R0)) ;\$ct = \$c0 - \$ce - \$c12 ;\$breakline = "\n";// use br for the web...// Work nice only on fixed size font terminal.echo"     CE           C12           CE";echo "\$breakline";echo" +---||---+---+---||---+----+---||---+";echo "\$breakline";echo" |        |   |        |    |        |";echo "\$breakline";echo" <        (   |        (    |        <";echo "\$breakline"; echo" > R0     ) L - Ctune  ) L  - Ctune  > R0";echo "\$breakline";echo" <        (   -        (    -        <";echo "\$breakline";  echo" >        )   |        )    |        >";echo "\$breakline";echo" |        |   |        |    |        |";echo "\$breakline";echo" V        V   V        V    V        V";echo "\$breakline";echo "\$breakline";// no rounding was provided in the output...\$F = \$F/1000000; echo "F     =  \$F Mhz \$breakline";\$B = \$B/1000000; echo "B     =  \$B Mhz \$breakline";echo "R0    =  \$R0 ohms \$breakline";\$L = \$L * 1000000; echo "L     =  \$L microhenries \$breakline";\$c12 = \$c12*1000000000000; echo "C12   =  \$c12 pf \$breakline";\$ce =   \$ce*1000000000000; echo "CE    =  \$ce pf \$breakline";\$ct =   \$ct*1000000000000; echo "Ctune =  \$ct pf \$breakline";?>`

Run it on a terminal with the command: php lcbandpass.php (or: php yourfilename.php) and this is the result:

The original post and software is at: http://brainwagon.org/2011/01/11/on-an-lc-bandpass-filter-for-receivers/