ref: 497f1c6a2dcb2a9b2e4fb84a67e3d201dee79ef8
parent: ad6e0fdd44a6740ab921aaeb8170c42542677f0e
author: Erik de Castro Lopo <erikd@mega-nerd.com>
date: Thu May 24 16:01:27 EDT 2007
Move octave scripts to Octave dir.
--- a/generate_filter.m
+++ /dev/null
@@ -1,35 +1,0 @@
-function f = generate_filter (cycles, fudge_factor, increment, atten)
-
-if nargin != 4,
- error ("Need four args.") ;
- endif
-
-# Calclate N and make sure it is odd.
-N = fix (4 * cycles * fudge_factor * increment) ;
-
-if rem (N, 2) != 1,
- N = N - 1 ;
- endif
-
-# Generate the Sinc function.
-
-m = -((N-1)/2):((N-1)/2) ;
-f = sinc (m / fudge_factor / increment) ;
-
-# Genertate the window function and apply it.
-
-w = kaiser (N, (atten + 0.5) / 10) ;
-w = w' ;
-
-f = f .* w ;
-
-f = f / sum (f) ;
-
-endfunction
-
-# Do not edit or modify anything in this comment block.
-# The arch-tag line is a file identity tag for the GNU Arch
-# revision control system.
-#
-# arch-tag: 7e57a3cb-3f5c-4346-bfcd-4da1e758e2a7
-
--- a/make_src_filter.m
+++ /dev/null
@@ -1,126 +1,0 @@
-function f = make_src_filter (cycles, increment, atten, filename)
-
-# This works :
-#
-# f = make_filter (67, 128, 100.3) ;
-# f = make_filter (13, 128, 100.5) ;
-# f = make_filter (185, 4, 157.0) ;
-
-
-#=======================================================================
-
-if nargin < 3,
- error ('Try make_filter (12, 32, 88, "output.txt")') ;
- endif
-
-if nargin < 4,
- filename = 0 ;
-elseif (isstr (filename) == 0),
- error ("Fourth parameter must be a file name.") ;
- endif
-
-fudge_factor1 = 1.0 ;
-f1 = generate_filter (cycles, fudge_factor1, increment, atten) ;
-[stop_atten stop_band_start1 minus_3db] = measure_filter (f1, atten) ;
-printf (" fudge_factor : %15.13f stop_band_start : %15.13f 1\n", fudge_factor1, stop_band_start1) ;
-
-fudge_factor2 = 1.25 ;
-f2 = generate_filter (cycles, fudge_factor2, increment, atten) ;
-[stop_atten stop_band_start2 minus_3db] = measure_filter (f2, atten) ;
-printf (" fudge_factor : %15.13f stop_band_start : %15.13f 2\n", fudge_factor2, stop_band_start2) ;
-
-f = f1 ;
-fudge_factor = fudge_factor1 ;
-stop_band_start = stop_band_start1 ;
-
-while ((stop_band_start1 - stop_band_start2) > 0.00000001)
- if (stop_band_start1 < stop_band_start2)
- printf ("stop_band_start1 < stop_band_start2\n") ;
- break ;
- endif
-
- fudge_factor = fudge_factor1 + (fudge_factor2 - fudge_factor1) / 2 ;
- f = generate_filter (cycles, fudge_factor, increment, atten) ;
- [stop_atten stop_band_start minus_3db] = measure_filter (f, atten) ;
-
- if (stop_band_start > 1.0)
- printf ("A %10.8f %10.8f %10.8f\n", fudge_factor1, fudge_factor, fudge_factor2) ;
- continue ;
- endif
-
- if (stop_band_start < 0.5 / increment)
- f2 = f ;
- stop_band_start2 = stop_band_start ;
- fudge_factor2 = fudge_factor ;
- choice = 2 ;
- else
- f1 = f ;
- stop_band_start1 = stop_band_start ;
- fudge_factor1 = fudge_factor ;
- choice = 1 ;
- endif
-
- printf (" fudge_factor : %15.13f stop_band_start : %15.13f %d\n", fudge_factor, stop_band_start, choice) ;
- endwhile
-
-printf ("\n") ;
-
-#-------------------------------------------------------------------------------
-# Grab only half the coefficients.
-
-N = length (f) ;
-
-f = increment * f' ;
-
-if rem (length (f), 2) == 1,
- index = find (f == max (f)) ;
- half_f = f (index:length (f)) ;
-else
- error ("Length should be odd.") ;
- half_f = f ((length(f)/2):length(f)) ;
- endif
-
-#-------------------------------------------------------------------------------
-# Print analysis.
-
-printf ("# f = make_filter (%d, %d, %4.1f) ;\n", cycles, increment, atten) ;
-printf ("# Coeff. count : %d\n", N) ;
-printf ("# Fudge factor : %9.7f\n", fudge_factor) ;
-printf ("# Pass band width : %12.10f (should be %12.10f)\n", stop_band_start, 0.5 / increment) ;
-printf ("# Stop band atten. : %5.2f dB\n", abs (stop_atten)) ;
-printf ("# -3dB band Width : %5.3f\n", 0.5 / increment / minus_3db) ;
-printf ("# half length : %d\n", length (half_f)) ;
-printf ("# increment : %d\n", increment) ;
-
-if filename,
- file = fopen (filename, "w") ;
- if file == 0,
- str = sprintf ("Error, not able to open '%s'", filename)
- error (str) ;
- endif
-
- fprintf (file, "/*\n") ;
- fprintf (file, "** f = make_filter (%d, %d, %4.1f) ;\n", cycles, increment, atten) ;
- fprintf (file, "** Pass band width : %9.7f (should be %9.7f)\n", stop_band_start, 0.5 / increment) ;
- fprintf (file, "** Stop band atten. : %5.2f dB\n", abs (stop_atten)) ;
- fprintf (file, "** -3dB band width : %5.3f\n", 0.5 / increment / minus_3db) ;
- fprintf (file, "** half length : %d\n", length (half_f)) ;
- fprintf (file, "** increment : %d\n", increment) ;
- fprintf (file, "*/\n\n") ;
-
- for val = half_f,
- fprintf (file, "% 24.20e,\n", val) ;
- endfor
-
- fprintf (file, " 0\t\t\t/* Need a final zero coefficient */\n\n") ;
- fclose (file) ;
- endif
-
-endfunction
-
-# Do not edit or modify anything in this comment block.
-# The arch-tag line is a file identity tag for the GNU Arch
-# revision control system.
-#
-# arch-tag: 2f1ff4fa-ea6a-4e54-a5f8-dad55def9834
-
--- a/measure_filter.m
+++ /dev/null
@@ -1,70 +1,0 @@
-function [stop_atten stop_band_start minus_3db] = measure_filter (f, atten)
-
-
-spec_len = 400000 ;
-
-# Calculate the spectrum.
-
-spec = 20 * log10 (abs (fft ([f zeros(1, spec_len - length (f))]))) ;
-
-spec = spec (1:spec_len/2) ;
-
-#-------------------------------------------------------------------------------
-# Find the first null which starts off the stop band.
-
-first_null = 0 ;
-for k = 2:length (spec) - 1,
- if spec (k) < -0.8 * atten && spec (k-1) > spec (k) && spec (k) < spec (k + 1),
- first_null = k ;
- break
- endif
- endfor
-
-#-------------------------------------------------------------------------------
-# Find the stop band minimum attenuation.
-
-stop_atten = max (spec (first_null:length (spec))) ;
-
-#-------------------------------------------------------------------------------
-# Find the x position on the transition band which has the same attenuation.
-
-atten_start = 0 ;
-for k = 1:first_null,
- if spec (k) > stop_atten && spec (k + 1) < stop_atten,
- atten_start = k ;
- break ;
- endif
- endfor
-
-atten_start = atten_start - 1 ; # Arrays are 1 based so subtract 1.
-
-stop_band_start = atten_start + (stop_atten - spec (atten_start)) / (spec (atten_start+1) - spec (atten_start)) ;
-
-
-stop_band_start = stop_band_start / spec_len ;
-
-#-------------------------------------------------------------------------------
-# Find -3db point.
-
-minus_3db = 0 ;
-for k = 1:first_null,
- if spec (k) > -3.0 && spec (k + 1) < -3.0,
- minus_3db = k ;
- break ;
- endif
- endfor
-
-minus_3db = minus_3db - 1 ; # Arrays are 1 based so subtract 1.
-
-minus_3db = minus_3db + (stop_atten - spec (minus_3db)) / (spec (minus_3db+1) - spec (minus_3db)) ;
-
-minus_3db = minus_3db / spec_len ;
-
-endfunction
-
-# Do not edit or modify anything in this comment block.
-# The arch-tag line is a file identity tag for the GNU Arch
-# revision control system.
-#
-# arch-tag: cc2bc9a2-d387-4fed-aa0a-570e91f17c99
-