| @@ -1,126 +0,0 @@ |
| 1 | | −function f = make_src_filter (cycles, increment, atten, filename) |
| 2 | | − |
| 3 | | −# This works : |
| 4 | | −# |
| 5 | | −# f = make_filter (67, 128, 100.3) ; |
| 6 | | −# f = make_filter (13, 128, 100.5) ; |
| 7 | | −# f = make_filter (185, 4, 157.0) ; |
| 8 | | − |
| 9 | | − |
| 10 | | −#======================================================================= |
| 11 | | − |
| 12 | | −if nargin < 3, |
| 13 | | − error ('Try make_filter (12, 32, 88, "output.txt")') ; |
| 14 | | − endif |
| 15 | | − |
| 16 | | −if nargin < 4, |
| 17 | | − filename = 0 ; |
| 18 | | −elseif (isstr (filename) == 0), |
| 19 | | − error ("Fourth parameter must be a file name.") ; |
| 20 | | − endif |
| 21 | | − |
| 22 | | −fudge_factor1 = 1.0 ; |
| 23 | | −f1 = generate_filter (cycles, fudge_factor1, increment, atten) ; |
| 24 | | −[stop_atten stop_band_start1 minus_3db] = measure_filter (f1, atten) ; |
| 25 | | −printf (" fudge_factor : %15.13f stop_band_start : %15.13f 1\n", fudge_factor1, stop_band_start1) ; |
| 26 | | − |
| 27 | | −fudge_factor2 = 1.25 ; |
| 28 | | −f2 = generate_filter (cycles, fudge_factor2, increment, atten) ; |
| 29 | | −[stop_atten stop_band_start2 minus_3db] = measure_filter (f2, atten) ; |
| 30 | | −printf (" fudge_factor : %15.13f stop_band_start : %15.13f 2\n", fudge_factor2, stop_band_start2) ; |
| 31 | | − |
| 32 | | −f = f1 ; |
| 33 | | −fudge_factor = fudge_factor1 ; |
| 34 | | −stop_band_start = stop_band_start1 ; |
| 35 | | − |
| 36 | | −while ((stop_band_start1 - stop_band_start2) > 0.00000001) |
| 37 | | − if (stop_band_start1 < stop_band_start2) |
| 38 | | − printf ("stop_band_start1 < stop_band_start2\n") ; |
| 39 | | − break ; |
| 40 | | − endif |
| 41 | | − |
| 42 | | − fudge_factor = fudge_factor1 + (fudge_factor2 - fudge_factor1) / 2 ; |
| 43 | | − f = generate_filter (cycles, fudge_factor, increment, atten) ; |
| 44 | | − [stop_atten stop_band_start minus_3db] = measure_filter (f, atten) ; |
| 45 | | − |
| 46 | | − if (stop_band_start > 1.0) |
| 47 | | − printf ("A %10.8f %10.8f %10.8f\n", fudge_factor1, fudge_factor, fudge_factor2) ; |
| 48 | | − continue ; |
| 49 | | − endif |
| 50 | | − |
| 51 | | − if (stop_band_start < 0.5 / increment) |
| 52 | | − f2 = f ; |
| 53 | | − stop_band_start2 = stop_band_start ; |
| 54 | | − fudge_factor2 = fudge_factor ; |
| 55 | | − choice = 2 ; |
| 56 | | − else |
| 57 | | − f1 = f ; |
| 58 | | − stop_band_start1 = stop_band_start ; |
| 59 | | − fudge_factor1 = fudge_factor ; |
| 60 | | − choice = 1 ; |
| 61 | | − endif |
| 62 | | − |
| 63 | | − printf (" fudge_factor : %15.13f stop_band_start : %15.13f %d\n", fudge_factor, stop_band_start, choice) ; |
| 64 | | − endwhile |
| 65 | | − |
| 66 | | −printf ("\n") ; |
| 67 | | − |
| 68 | | −#------------------------------------------------------------------------------- |
| 69 | | −# Grab only half the coefficients. |
| 70 | | − |
| 71 | | −N = length (f) ; |
| 72 | | − |
| 73 | | −f = increment * f' ; |
| 74 | | − |
| 75 | | −if rem (length (f), 2) == 1, |
| 76 | | − index = find (f == max (f)) ; |
| 77 | | − half_f = f (index:length (f)) ; |
| 78 | | −else |
| 79 | | − error ("Length should be odd.") ; |
| 80 | | − half_f = f ((length(f)/2):length(f)) ; |
| 81 | | − endif |
| 82 | | − |
| 83 | | −#------------------------------------------------------------------------------- |
| 84 | | −# Print analysis. |
| 85 | | − |
| 86 | | −printf ("# f = make_filter (%d, %d, %4.1f) ;\n", cycles, increment, atten) ; |
| 87 | | −printf ("# Coeff. count : %d\n", N) ; |
| 88 | | −printf ("# Fudge factor : %9.7f\n", fudge_factor) ; |
| 89 | | −printf ("# Pass band width : %12.10f (should be %12.10f)\n", stop_band_start, 0.5 / increment) ; |
| 90 | | −printf ("# Stop band atten. : %5.2f dB\n", abs (stop_atten)) ; |
| 91 | | −printf ("# -3dB band Width : %5.3f\n", 0.5 / increment / minus_3db) ; |
| 92 | | −printf ("# half length : %d\n", length (half_f)) ; |
| 93 | | −printf ("# increment : %d\n", increment) ; |
| 94 | | − |
| 95 | | −if filename, |
| 96 | | − file = fopen (filename, "w") ; |
| 97 | | − if file == 0, |
| 98 | | − str = sprintf ("Error, not able to open '%s'", filename) |
| 99 | | − error (str) ; |
| 100 | | − endif |
| 101 | | − |
| 102 | | − fprintf (file, "/*\n") ; |
| 103 | | − fprintf (file, "** f = make_filter (%d, %d, %4.1f) ;\n", cycles, increment, atten) ; |
| 104 | | − fprintf (file, "** Pass band width : %9.7f (should be %9.7f)\n", stop_band_start, 0.5 / increment) ; |
| 105 | | − fprintf (file, "** Stop band atten. : %5.2f dB\n", abs (stop_atten)) ; |
| 106 | | − fprintf (file, "** -3dB band width : %5.3f\n", 0.5 / increment / minus_3db) ; |
| 107 | | − fprintf (file, "** half length : %d\n", length (half_f)) ; |
| 108 | | − fprintf (file, "** increment : %d\n", increment) ; |
| 109 | | − fprintf (file, "*/\n\n") ; |
| 110 | | − |
| 111 | | − for val = half_f, |
| 112 | | − fprintf (file, "% 24.20e,\n", val) ; |
| 113 | | − endfor |
| 114 | | − |
| 115 | | − fprintf (file, " 0\t\t\t/* Need a final zero coefficient */\n\n") ; |
| 116 | | − fclose (file) ; |
| 117 | | − endif |
| 118 | | − |
| 119 | | −endfunction |
| 120 | | − |
| 121 | | −# Do not edit or modify anything in this comment block. |
| 122 | | −# The arch-tag line is a file identity tag for the GNU Arch |
| 123 | | −# revision control system. |
| 124 | | −# |
| 125 | | −# arch-tag: 2f1ff4fa-ea6a-4e54-a5f8-dad55def9834 |
| 126 | | − |