diff options
Diffstat (limited to 'gnuradio-core/src/utils')
31 files changed, 1267 insertions, 0 deletions
diff --git a/gnuradio-core/src/utils/cic_comp_taps.m b/gnuradio-core/src/utils/cic_comp_taps.m new file mode 100644 index 000000000..9ae5cb167 --- /dev/null +++ b/gnuradio-core/src/utils/cic_comp_taps.m @@ -0,0 +1,45 @@ +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +# See Altera Application Note AN455 +# +# R = decimation factor, 8-256 +# Fc = passband (one-sided) cutoff frequency +# L = number of taps + +function taps = cic_comp_taps(R, Fc, L) + M = 1; %% Differential delay + N = 4; %% Number of stages + B = 18; %% Coeffi. Bit-width + Fs = 64e6; %% (High) Sampling freq in Hz before decimation + Fo = R*Fc/Fs; %% Normalized Cutoff freq; 0<Fo<=0.5/M; + p = 2e3; %% Granularity + s = 0.25/p; %% Step size + fp = [0:s:Fo]; %% Pass band frequency samples + fs = (Fo+s):s:0.5; %% Stop band frequency samples + f = [fp fs]*2; %% Normalized frequency samples; 0<=f<=1 + Mp = ones(1,length(fp)); %% Pass band response; Mp(1)=1 + Mp(2:end) = abs( M*R*sin(pi*fp(2:end)/R)./sin(pi*M*fp(2:end))).^N; + Mf = [Mp zeros(1,length(fs))]; + f(end) = 1; + h = fir2(L,f,Mf); %% Filter length L+1 + taps = h/sum(h); %% Floating point coefficients +endfunction diff --git a/gnuradio-core/src/utils/cool.m b/gnuradio-core/src/utils/cool.m new file mode 100644 index 000000000..f8b8a5cea --- /dev/null +++ b/gnuradio-core/src/utils/cool.m @@ -0,0 +1,50 @@ +%% Copyright (C) 1999,2000 Kai Habel +%% +%% This program is free software; you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation; either version 3 of the License, or +%% (at your option) any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program; if not, write to the Free Software +%% Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA + +%% -*- texinfo -*- +%% @deftypefn {Function File} {} cool (@var{n}) +%% Create color colormap. +%% (cyan to magenta) +%% The argument @var{n} should be a scalar. If it +%% is omitted, the length of the current colormap or 64 is assumed. +%% @end deftypefn +%% @seealso{colormap} + +%% Author: Kai Habel <kai.habel@gmx.de> + +function map = cool (number) + + if (nargin == 0) + number = rows (colormap); + elseif (nargin == 1) + if (! is_scalar (number)) + error ("cool: argument must be a scalar"); + end + else + usage ("cool (number)"); + end + + if (number == 1) + map = [0, 1, 1]; + elseif (number > 1) + r = (0:number - 1)' ./ (number - 1); + g = 1 - r; + b = ones (number, 1); + map = [r, g, b]; + else + map = []; + end + diff --git a/gnuradio-core/src/utils/db_width.m b/gnuradio-core/src/utils/db_width.m new file mode 100644 index 000000000..e9c64cc79 --- /dev/null +++ b/gnuradio-core/src/utils/db_width.m @@ -0,0 +1,35 @@ +% +% Copyright 2001 Free Software Foundation, Inc. +% +% This file is part of GNU Radio +% +% GNU Radio is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 3, or (at your option) +% any later version. +% +% GNU Radio is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with GNU Radio; see the file COPYING. If not, write to +% the Free Software Foundation, Inc., 51 Franklin Street, +% Boston, MA 02110-1301, USA. + +%% find the N-dB width of the given filter +%% E.g., to find the 3-dB width, use width = db_width (taps, -3.0) +%% the result is normalized to nyquist == 1 + +function width = db_width (taps, db) + [H,w] = freqz (taps, 1, 4096); + Habs = abs(H); + max_H = max(Habs); + min_H = min(Habs); + threshold = max_H * 10^(db/20); + if (min_H > threshold) + error ("The %g dB point is never reached", db); + end + above = Habs >= threshold; + width = sum(above) / length (above); diff --git a/gnuradio-core/src/utils/filter_tools.m b/gnuradio-core/src/utils/filter_tools.m new file mode 100644 index 000000000..552791e33 --- /dev/null +++ b/gnuradio-core/src/utils/filter_tools.m @@ -0,0 +1,42 @@ +% +% Copyright 2001 Free Software Foundation, Inc. +% +% This file is part of GNU Radio +% +% GNU Radio is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 3, or (at your option) +% any later version. +% +% GNU Radio is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with GNU Radio; see the file COPYING. If not, write to +% the Free Software Foundation, Inc., 51 Franklin Street, +% Boston, MA 02110-1301, USA. +% +%% equivalent to the C++ code in VrComplexFIRfilter::buildFilterComplex + +1; + +%% hamming window, nothing fancy + +function taps = build_filter_complex_lp (gain, ntaps) + + taps = gain * (0.54 - 0.46 * cos (2 * pi * (0:ntaps-1)' / (ntaps-1))); + +end + +%% old_taps describes a low pass filter, convert it to bandpass +%% centered at center_freq. center_freq is normalized to Fs (sampling freq) + +function new_taps = freq_shift_filter (old_taps, center_freq) + + ntaps = length(old_taps); + + new_taps = exp (j*2*pi*center_freq*(0:ntaps-1)') .* old_taps; + +end diff --git a/gnuradio-core/src/utils/is_complex.m b/gnuradio-core/src/utils/is_complex.m new file mode 100644 index 000000000..4700467b1 --- /dev/null +++ b/gnuradio-core/src/utils/is_complex.m @@ -0,0 +1,24 @@ +# +# Copyright 2004 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function p = is_complex (x) + p = any (imag (x) != 0); +endfunction; diff --git a/gnuradio-core/src/utils/lp_to_bp.m b/gnuradio-core/src/utils/lp_to_bp.m new file mode 100644 index 000000000..4e73f6cc7 --- /dev/null +++ b/gnuradio-core/src/utils/lp_to_bp.m @@ -0,0 +1,27 @@ +# +# Copyright 2002 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +## transform low pass coefficients into bandpass coefficients + +function bp_taps = lp_to_bp (lp_taps, center_freq, sampling_freq) + arg = 2 * pi * center_freq / sampling_freq; + bp_taps = lp_taps .* exp (j*arg*(0:length(lp_taps)-1)'); +endfunction diff --git a/gnuradio-core/src/utils/partition-cascaded-decimating-filters.scm b/gnuradio-core/src/utils/partition-cascaded-decimating-filters.scm new file mode 100644 index 000000000..6ae7877f9 --- /dev/null +++ b/gnuradio-core/src/utils/partition-cascaded-decimating-filters.scm @@ -0,0 +1,67 @@ +;; Estimate the total work (ntaps * sampling rate) for two cascaded +;; decimating low pass filters. +;; +;; The basic assumption is that the number of taps required in any +;; section is inversely proportional to the normalized transition width +;; for that section. +;; +;; FS is the input sampling frequency +;; F1 is the cutoff frequency +;; F2 is the far edge of the transition band +;; DEC1 is the decimation factor for the first filter +;; DEC2 is the decimation factor for the 2nd filter +;; +;; The total decimation factor is DEC1 * DEC2. Therefore, +;; the output rate of the filter is FS / (DEC1 * DEC2) + +(require 'common-list-functions) +(require 'factor) + + + +(define (work2 fs f1 f2 dec1 dec2) + (+ (work1 fs f1 (/ fs (* 2 dec1)) dec1) + (work1 (/ fs dec1) f1 f2 dec2))) + + +;; work for a single section + +(define (work1 fs f1 f2 dec) + (/ (* fs (/ fs (- f2 f1))) dec)) + + +;; return the max integer dec such that fs/(2*dec) >= f2 + +(define (max-dec fs f2) + (inexact->exact (floor (/ fs (* 2 f2))))) + + +;; `adjoin' returns the adjoint of the element OBJ and the list LST. +;; That is, if OBJ is in LST, `adjoin' returns LST, otherwise, it returns +;; `(cons OBJ LST)'. + +(define (adjoin-equal obj lst) + (if (member obj lst) lst (cons obj lst))) + + +;;; not quite right + +(define (permute lst) + (let ((result '())) + (define (aux set head) + (if (null? set) + (set! result (cons head result)) + (for-each (lambda (x) + (aux (set-difference set (list x)) + (cons x head))) + set))) + (aux lst '()) + result)) + +;; `extract-nth' returns the Nth element of LST consed on to the +;; list resulting from splicing out the Nth element of LST. +;; Indexing is 0 based. + +(define (extract-nth n lst) + lst) + diff --git a/gnuradio-core/src/utils/permute.scm b/gnuradio-core/src/utils/permute.scm new file mode 100644 index 000000000..23ddfc999 --- /dev/null +++ b/gnuradio-core/src/utils/permute.scm @@ -0,0 +1,27 @@ +(require 'common-list-functions) + + +(define (permute lst) + (define (aux set head) + (cond ((null? set) head) + (else + (map (lambda (x) + (aux (set-difference set (list x)) + (cons x head))) + set)))) + (aux lst '())) + +(define (permute-2 lst) + (let ((result '())) + (define (aux set head) + (if (null? set) + (set! result (cons head result)) + (for-each (lambda (x) + (aux (set-difference set (list x)) + (cons x head))) + set))) + (aux lst '()) + result)) + + + diff --git a/gnuradio-core/src/utils/plot_cic_decimator_response.m b/gnuradio-core/src/utils/plot_cic_decimator_response.m new file mode 100644 index 000000000..8f06aeafe --- /dev/null +++ b/gnuradio-core/src/utils/plot_cic_decimator_response.m @@ -0,0 +1,44 @@ +# +# Copyright 2004 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function plot_cic_decimator_response (R, N, M) + ## R = decimation rate + ## N = number of stages (4) + ## M = 1 + gain = (R*M)^N + npoints = 1024; + w = 0:1/npoints:1-1/npoints; + w = w * 1 * pi; + ## w = w * R; + length(w); + num = sin (w*R*M/2); + length (num); + ## H = sin (w*R*M/2) ./ sin (w/2) + denom = sin(w/2); + length (denom); + H = (num ./ denom) .^ N; + H(1) = gain; + H = H ./ gain; + plot (R*w/(2*pi), 10 * log10 (H)); + ## plot (R*w/(2*pi), H); +endfunction + + diff --git a/gnuradio-core/src/utils/plot_freq_response.m b/gnuradio-core/src/utils/plot_freq_response.m new file mode 100644 index 000000000..335c51d62 --- /dev/null +++ b/gnuradio-core/src/utils/plot_freq_response.m @@ -0,0 +1,36 @@ +# +# Copyright 2001 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function plot_freq_response (b,...) + if (nargin == 1) + ## Response of an FIR filter + a = 1; + elseif (nargin == 2) + ## response of an IIR filter + a = va_arg (); + endif + + [H,w] = freqz (b,a); + plot (w/(2*pi), abs(H)); + grid; + xlabel ('Normalized Frequency (Fs == 1)'); + ylabel ('Magnitude (linear)'); +endfunction diff --git a/gnuradio-core/src/utils/plot_freq_response_db.m b/gnuradio-core/src/utils/plot_freq_response_db.m new file mode 100644 index 000000000..10ce7d6e1 --- /dev/null +++ b/gnuradio-core/src/utils/plot_freq_response_db.m @@ -0,0 +1,39 @@ +# +# Copyright 2001 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function plot_freq_response_db (b,...) + if (nargin == 1) + ## Response of an FIR filter + a = 1; + elseif (nargin == 2) + ## response of an IIR filter + a = va_arg (); + endif + + [H,w] = freqz (b,a); + + grid; + xlabel ('Normalized Frequency (Fs == 1)'); + ylabel ('Magnitude Squared (dB)'); + abs = abs(H); +# plot (w/(2*pi), 20 * log10 (abs/max(abs))); + plot (w/(2*pi), 20 * log10 (abs)); +endfunction diff --git a/gnuradio-core/src/utils/plot_freq_response_phase.m b/gnuradio-core/src/utils/plot_freq_response_phase.m new file mode 100644 index 000000000..591bd5b94 --- /dev/null +++ b/gnuradio-core/src/utils/plot_freq_response_phase.m @@ -0,0 +1,38 @@ +# +# Copyright 2001 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function plot_freq_response_db (b,...) + if (nargin == 1) + ## Response of an FIR filter + a = 1; + elseif (nargin == 2) + ## response of an IIR filter + a = va_arg (); + endif + + [H,w] = freqz (b,a); + + grid; + xlabel ('Normalized Frequency (Fs == 1)'); + ylabel ('Phase (radians)'); + abs = abs(H); + plot (w/(2*pi), atan2(imag(H), real(H))) +endfunction diff --git a/gnuradio-core/src/utils/plotfft.m b/gnuradio-core/src/utils/plotfft.m new file mode 100644 index 000000000..20a2efd4c --- /dev/null +++ b/gnuradio-core/src/utils/plotfft.m @@ -0,0 +1,40 @@ +# +# Copyright 2001 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function plotfft (data, sample_rate) + + if (nargin == 1) + sample_rate = 1.0; + endif; + + if ((m = nargchk (1,2,nargin))) + usage (m); + endif; + + len = length(data); + s = fft (data.*kaiser(len, 5)); + + incr = sample_rate/len; + min_x = -sample_rate/2; + max_x = sample_rate/2 - incr; + plot (min_x:incr:max_x, abs(fftshift(s))); + +endfunction diff --git a/gnuradio-core/src/utils/plotfftavgk.m b/gnuradio-core/src/utils/plotfftavgk.m new file mode 100644 index 000000000..c82c540f3 --- /dev/null +++ b/gnuradio-core/src/utils/plotfftavgk.m @@ -0,0 +1,61 @@ +# +# Copyright 2002 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function plotfftavgk_db (all_data, k, sample_rate) + + if (nargin == 2) + sample_rate = 1.0; + endif; + + if ((m = nargchk (2,3,nargin))) + usage (m); + endif; + + ## len = 1024; + len = 8192; + ##window = ones (len, 1); + window = kaiser (len, 5); + + s = zeros (len,1); + + count = min (100, floor (length (all_data)/len)); + + for i = 0:count-1; + data = all_data((k+i)*len + 1 : (k+i+1)*len); + s = s + abs (fft (data.*window)); + endfor; + + s = s ./ count; + + incr = sample_rate/len; + min_x = -sample_rate/2; + max_x = sample_rate/2 - incr; + + x = min_x:incr:max_x; + ## y = 20 * log10(fftshift(s)); + y = (fftshift(s)); + plot (x, y); + + i = find (y == max(y)) + x(i) + y(i) + +endfunction diff --git a/gnuradio-core/src/utils/plotfftavgk_db.m b/gnuradio-core/src/utils/plotfftavgk_db.m new file mode 100644 index 000000000..73cee140d --- /dev/null +++ b/gnuradio-core/src/utils/plotfftavgk_db.m @@ -0,0 +1,73 @@ +# +# Copyright 2001 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function plotfftavgk_db (all_data, k, sample_rate) + + if (nargin == 2) + sample_rate = 1.0; + endif; + + if ((m = nargchk (2,3,nargin))) + usage (m); + endif; + + len = 1024; + ## len = 8192; + ##window = ones (len, 1); + #window = kaiser (len, 5); + window = hanning (len); + + s = zeros (len,1); + + count = min (100, floor (length (all_data)/len)); + + for i = 0:count-1; + data = all_data((k+i)*len + 1 : (k+i+1)*len); + s = s + abs (fft (data.*window)); + endfor; + + s = s ./ count; + + incr = sample_rate/len; + + if is_complex (all_data); + min_x = -sample_rate/2; + max_x = sample_rate/2 - incr; + + x = min_x:incr:max_x; + y = 20 * log10(fftshift(s)); + plot (x, y); + else + min_x = 0 + max_x = sample_rate/2 - incr; + + x = min_x:incr:max_x; + y = 20 * log10(s(1:len/2)); + plot (x, y); + + endif; + + + i = find (y == max(y)) + x(i) + y(i) + +endfunction diff --git a/gnuradio-core/src/utils/plotfftk.m b/gnuradio-core/src/utils/plotfftk.m new file mode 100644 index 000000000..df2bf3aca --- /dev/null +++ b/gnuradio-core/src/utils/plotfftk.m @@ -0,0 +1,41 @@ +# +# Copyright 2001 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function plotfftk (all_data, k, sample_rate) + + if (nargin == 2) + sample_rate = 1.0; + endif; + + if ((m = nargchk (2,3,nargin))) + usage (m); + endif; + + len = 1024; + data = all_data(k*len + 1 : (k+1)*len); + s = fft (data.*kaiser(len, 5)); + + incr = sample_rate/len; + min_x = -sample_rate/2; + max_x = sample_rate/2 - incr; + plot (min_x:incr:max_x, abs(fftshift(s))); + +endfunction diff --git a/gnuradio-core/src/utils/plotfftk_db.m b/gnuradio-core/src/utils/plotfftk_db.m new file mode 100644 index 000000000..b2c85412f --- /dev/null +++ b/gnuradio-core/src/utils/plotfftk_db.m @@ -0,0 +1,43 @@ +# +# Copyright 2001 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function plotfftk_db (all_data, k, sample_rate) + + if (nargin == 2) + sample_rate = 1.0; + endif; + + if ((m = nargchk (2,3,nargin))) + usage (m); + endif; + + len = 1024; + data = all_data(k*len + 1 : (k+1)*len); + ## s = fft (data.*kaiser(len, 5)); + ## s = fft (data.*hamming(len)); + s = fft (data.*hanning(len)); + + incr = sample_rate/len; + min_x = -sample_rate/2; + max_x = sample_rate/2 - incr; + plot (min_x:incr:max_x, 20 * log10(abs(fftshift(s)))); + +endfunction diff --git a/gnuradio-core/src/utils/put_markers.m b/gnuradio-core/src/utils/put_markers.m new file mode 100644 index 000000000..1244d31aa --- /dev/null +++ b/gnuradio-core/src/utils/put_markers.m @@ -0,0 +1,32 @@ +# +# Copyright 2002 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function put_markers (y) + + if (nargin == 0) + y = 25; + endif; + + hold on; + plot (3.06e6, y, '@'); + plot (8.44e6, y, '@'); + +endfunction diff --git a/gnuradio-core/src/utils/rainbow.m b/gnuradio-core/src/utils/rainbow.m new file mode 100644 index 000000000..35fab19b8 --- /dev/null +++ b/gnuradio-core/src/utils/rainbow.m @@ -0,0 +1,53 @@ +## Copyright (C) 1999,2000 Kai Habel +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA + +## -*- texinfo -*- +## @deftypefn {Function File} {} rainbow (@var{n}) +## Create color colormap. +## (red through yellow, green, cyan,blue,magenta to red) +## The argument @var{n} should be a scalar. If it +## is omitted, the length of the current colormap or 64 is assumed. +## @end deftypefn +## @seealso{colormap} + +## Author: Kai Habel <kai.habel@gmx.de> + +## 2001-09-13 Paul Kienzle <pkienzle@users.sf.net> +## * renamed to rainbow for use with tk_octave +## * remove reference to __current_color_map__ + +function map = rainbow (number) + + if (nargin == 0) + number = length(colormap); + elseif (nargin == 1) + if (! is_scalar (number)) + error ("rainbow: argument must be a scalar"); + endif + else + usage ("rainbow (number)"); + endif + + if (number == 1) + map = [1, 0, 0]; + elseif (number > 1) + h = linspace (0, 1, number)'; + map = hsv2rgb ([h, ones(number, 1), ones(number, 1)]); + else + map = []; + endif + +endfunction diff --git a/gnuradio-core/src/utils/read_char_binary.m b/gnuradio-core/src/utils/read_char_binary.m new file mode 100644 index 000000000..029cea783 --- /dev/null +++ b/gnuradio-core/src/utils/read_char_binary.m @@ -0,0 +1,45 @@ +% +% Copyright 2001 Free Software Foundation, Inc. +% +% This file is part of GNU Radio +% +% GNU Radio is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 3, or (at your option) +% any later version. +% +% GNU Radio is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with GNU Radio; see the file COPYING. If not, write to +% the Free Software Foundation, Inc., 51 Franklin Street, +% Boston, MA 02110-1301, USA. +% + +function v = read_char_binary (filename, count) + + %% usage: read_char (filename, [count]) + %% + %% open filename and return the contents, treating them as + %% signed short integers + %% + + m = nargchk (1,2,nargin); + if (m) + usage (m); + end + + if (nargin < 2) + count = Inf; + end + + f = fopen (filename, 'rb'); + if (f < 0) + v = 0; + else + v = fread (f, count, 'char'); + fclose (f); + end diff --git a/gnuradio-core/src/utils/read_complex_binary.m b/gnuradio-core/src/utils/read_complex_binary.m new file mode 100644 index 000000000..eb81f0fa0 --- /dev/null +++ b/gnuradio-core/src/utils/read_complex_binary.m @@ -0,0 +1,48 @@ +% +% Copyright 2001 Free Software Foundation, Inc. +% +% This file is part of GNU Radio +% +% GNU Radio is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 3, or (at your option) +% any later version. +% +% GNU Radio is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with GNU Radio; see the file COPYING. If not, write to +% the Free Software Foundation, Inc., 51 Franklin Street, +% Boston, MA 02110-1301, USA. +% + +function v = read_complex_binary (filename, count) + + %% usage: read_complex_binary (filename, [count]) + %% + %% open filename and return the contents as a column vector, + %% treating them as 32 bit complex numbers + %% + + m = nargchk (1,2,nargin); + if (m) + usage (m); + end + + if (nargin < 2) + count = Inf; + end + + f = fopen (filename, 'rb'); + if (f < 0) + v = 0; + else + t = fread (f, [2, count], 'float'); + fclose (f); + v = t(1,:) + t(2,:)*i; + [r, c] = size (v); + v = reshape (v, c, r); + end diff --git a/gnuradio-core/src/utils/read_cshort_binary.m b/gnuradio-core/src/utils/read_cshort_binary.m new file mode 100644 index 000000000..149b6ca88 --- /dev/null +++ b/gnuradio-core/src/utils/read_cshort_binary.m @@ -0,0 +1,46 @@ +% +% Copyright 2001,2008 Free Software Foundation, Inc. +% +% This file is part of GNU Radio +% +% GNU Radio is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 3, or (at your option) +% any later version. +% +% GNU Radio is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with GNU Radio; see the file COPYING. If not, write to +% the Free Software Foundation, Inc., 51 Franklin Street, +% Boston, MA 02110-1301, USA. +% + +function cv = read_cshort_binary (filename, count) + + %% usage: read_cshort_binary (filename, [count]) + %% + %% open filename and return the contents, treating them as + %% signed short integers + %% + + m = nargchk (1,2,nargin); + if (m) + usage (m); + end + + if (nargin < 2) + count = Inf; + end + + f = fopen (filename, 'rb'); + if (f < 0) + cv = 0; + else + v = fread (f, count, 'short'); + fclose (f); + cv = v(1:2:end)+v(2:2:end)*j; + end diff --git a/gnuradio-core/src/utils/read_float_binary.m b/gnuradio-core/src/utils/read_float_binary.m new file mode 100644 index 000000000..d27d09b9c --- /dev/null +++ b/gnuradio-core/src/utils/read_float_binary.m @@ -0,0 +1,45 @@ +% +% Copyright 2001 Free Software Foundation, Inc. +% +% This file is part of GNU Radio +% +% GNU Radio is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 3, or (at your option) +% any later version. +% +% GNU Radio is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with GNU Radio; see the file COPYING. If not, write to +% the Free Software Foundation, Inc., 51 Franklin Street, +% Boston, MA 02110-1301, USA. +% + +function v = read_float_binary (filename, count) + + %% usage: read_float_binary (filename, [count]) + %% + %% open filename and return the contents, treating them as + %% 32 bit floats + %% + + m = nargchk (1,2,nargin); + if (m) + usage (m); + end + + if (nargin < 2) + count = Inf; + end + + f = fopen (filename, 'rb'); + if (f < 0) + v = 0; + else + v = fread (f, count, 'float'); + fclose (f); + end diff --git a/gnuradio-core/src/utils/read_int_binary.m b/gnuradio-core/src/utils/read_int_binary.m new file mode 100644 index 000000000..cd83bb663 --- /dev/null +++ b/gnuradio-core/src/utils/read_int_binary.m @@ -0,0 +1,46 @@ +% +% Copyright 2001,2002 Free Software Foundation, Inc. +% +% This file is part of GNU Radio +% +% GNU Radio is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 3, or (at your option) +% any later version. +% +% GNU Radio is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with GNU Radio; see the file COPYING. If not, write to +% the Free Software Foundation, Inc., 51 Franklin Street, +% Boston, MA 02110-1301, USA. +% + +function v = read_int_binary (filename, count) + + %% usage: read_int_binary (filename, [count]) + %% + %% open filename and return the contents, treating them as + %% signed integers + %% + + m = nargchk (1,2,nargin); + if (m) + usage (m); + end + + if (nargin < 2) + count = Inf; + end + + f = fopen (filename, 'rb'); + if (f < 0) + v = 0; + else + v = fread (f, count, 'int'); + fclose (f); + end +end diff --git a/gnuradio-core/src/utils/read_short_binary.m b/gnuradio-core/src/utils/read_short_binary.m new file mode 100644 index 000000000..7b42f5e2b --- /dev/null +++ b/gnuradio-core/src/utils/read_short_binary.m @@ -0,0 +1,45 @@ +% +% Copyright 2001 Free Software Foundation, Inc. +% +% This file is part of GNU Radio +% +% GNU Radio is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 3, or (at your option) +% any later version. +% +% GNU Radio is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with GNU Radio; see the file COPYING. If not, write to +% the Free Software Foundation, Inc., 51 Franklin Street, +% Boston, MA 02110-1301, USA. +% + +function v = read_short_binary (filename, count) + + %% usage: read_short_binary (filename, [count]) + %% + %% open filename and return the contents, treating them as + %% signed short integers + %% + + m = nargchk (1,2,nargin); + if (m) + usage (m); + end + + if (nargin < 2) + count = Inf; + end + + f = fopen (filename, 'rb'); + if (f < 0) + v = 0; + else + v = fread (f, count, 'short'); + fclose (f); + end diff --git a/gnuradio-core/src/utils/read_xambi.m b/gnuradio-core/src/utils/read_xambi.m new file mode 100644 index 000000000..5adb94264 --- /dev/null +++ b/gnuradio-core/src/utils/read_xambi.m @@ -0,0 +1,46 @@ +# +# Copyright 2001,2005 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function v = read_xambi (filename) + + ## usage: read_xambi (filename) + ## + ## read binary cross-ambiguity data from radar tools. + ## The file has an 8 float header, the first word of which specifies + ## the number of doppler bins. + ## returns a matrix + + if ((m = nargchk (1,1,nargin))) + usage (m); + endif; + + f = fopen (filename, "rb"); + if (f < 0) + v = 0; + else + header = fread(f, 8, "float"); + ndoppler_bins = header(1) + min_doppler = header(2) + max_doppler = header(3) + v = fread (f, [ndoppler_bins, Inf], "float"); + fclose (f); + endif; +endfunction; diff --git a/gnuradio-core/src/utils/runsum.m b/gnuradio-core/src/utils/runsum.m new file mode 100644 index 000000000..0f530b015 --- /dev/null +++ b/gnuradio-core/src/utils/runsum.m @@ -0,0 +1,9 @@ +function r = runsum(x) + len = length(x); + r = zeros (1, len); + r(1) = x(1); + for i = 2:len; + r(i) = r(i-1) + x(i); + endfor; +endfunction; + diff --git a/gnuradio-core/src/utils/single_pole_iir.m b/gnuradio-core/src/utils/single_pole_iir.m new file mode 100644 index 000000000..12e21f2ac --- /dev/null +++ b/gnuradio-core/src/utils/single_pole_iir.m @@ -0,0 +1,25 @@ +# +# Copyright 2002 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function [b, a] = single_pole_iir (alpha) + b = [alpha]; + a = [1, alpha - 1]; +endfunction
\ No newline at end of file diff --git a/gnuradio-core/src/utils/split_vect.m b/gnuradio-core/src/utils/split_vect.m new file mode 100644 index 000000000..aef5c5c38 --- /dev/null +++ b/gnuradio-core/src/utils/split_vect.m @@ -0,0 +1,15 @@ +% split vector into packets + +function y = split_vect(vect,N) + Z = floor(max(size(vect))/N); + y = []; + if(size(vect)(1)>size(vect)(2)) + v = vect'; + else + v = vect; + end + for i=1:Z + y(i,1:N) = v((i-1)*N+1:i*N); + end +end + diff --git a/gnuradio-core/src/utils/write_float_binary.m b/gnuradio-core/src/utils/write_float_binary.m new file mode 100644 index 000000000..79414878b --- /dev/null +++ b/gnuradio-core/src/utils/write_float_binary.m @@ -0,0 +1,40 @@ +# +# Copyright 2001 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function v = write_float_binary (data, filename) + + ## usage: write_float_binary (data, filename) + ## + ## open filename and write data to it as 32 bit floats + ## + + if ((m = nargchk (2,2,nargin))) + usage (m); + endif; + + f = fopen (filename, "wb"); + if (f < 0) + v = 0; + else + v = fwrite (f, data, "float"); + fclose (f); + endif; +endfunction; diff --git a/gnuradio-core/src/utils/write_short_binary.m b/gnuradio-core/src/utils/write_short_binary.m new file mode 100644 index 000000000..72b3c408e --- /dev/null +++ b/gnuradio-core/src/utils/write_short_binary.m @@ -0,0 +1,40 @@ +# +# Copyright 2001 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +function v = write_short_binary (data, filename) + + ## usage: write_short_binary (data, filename) + ## + ## open filename and write data to it as 16 bit shorts + ## + + if ((m = nargchk (2,2,nargin))) + usage (m); + endif; + + f = fopen (filename, "wb"); + if (f < 0) + v = 0; + else + v = fwrite (f, data, "short"); + fclose (f); + endif; +endfunction; |