Mercurial > octave
comparison scripts/signal/sinc.m @ 904:3470f1e25a79
[project @ 1994-11-09 21:22:15 by jwe]
author | jwe |
---|---|
date | Wed, 09 Nov 1994 21:22:15 +0000 |
parents | 4e826edfbc56 |
children | 5cffc4b8de57 |
comparison
equal
deleted
inserted
replaced
903:b3692d63cca3 | 904:3470f1e25a79 |
---|---|
1 function result = sinc(x) | 1 function result = sinc (x) |
2 | 2 |
3 # usage: sinc(x) | 3 # usage: sinc(x) |
4 # | 4 # |
5 # Returns sin(pi*x)/(pi*x). | 5 # Returns sin(pi*x)/(pi*x). |
6 # | |
7 | 6 |
8 # We either need to set the do_fortran_indexing variable to "true" | 7 # We either need to set the do_fortran_indexing variable to "true" |
9 # or use reshape to convert the input matrix to a vector, so that | 8 # or use reshape to convert the input matrix to a vector, so that |
10 # we can use find to determine the elements of x that equal zero. | 9 # we can use find to determine the elements of x that equal zero. |
11 # I prefer reshaping. | 10 # I prefer reshaping. |
14 | 13 |
15 nels = nr*nc; | 14 nels = nr*nc; |
16 | 15 |
17 x = reshape(x,nels,1); | 16 x = reshape(x,nels,1); |
18 | 17 |
19 # Set result to all ones initially. | 18 # Set result to all ones initially. |
20 result = ones(nels,1); | 19 result = ones(nels,1); |
21 | 20 |
22 # Find non-zero elements in the input matrix. | 21 # Find non-zero elements in the input matrix. |
23 i = find(x); | 22 i = find(x); |
24 | 23 |
25 if (!isempty(i)) | 24 if (!isempty(i)) |
26 result(i) = sin(pi*x(i))./(pi*x(i)); | 25 result(i) = sin(pi*x(i))./(pi*x(i)); |
27 endif | 26 endif |