summaryrefslogtreecommitdiff
path: root/macros/fft1.sci
diff options
context:
space:
mode:
authorRashpat932024-08-09 11:47:44 +0530
committerGitHub2024-08-09 11:47:44 +0530
commitaf6fe82f90dcb2314a3d37a9a1e297fb0fc447f3 (patch)
tree80effebb59b2042de6635493f4831ba215f19eee /macros/fft1.sci
parentb10cff2c07747b039e3c3ee83a34d437e958356b (diff)
parent2e21edde1c1a251a60739b15e1c699172401f044 (diff)
downloadFOSSEE-Signal-Processing-Toolbox-master.tar.gz
FOSSEE-Signal-Processing-Toolbox-master.tar.bz2
FOSSEE-Signal-Processing-Toolbox-master.zip
Merge pull request #17 from avinashlalotra/masterHEADmaster
Abinash's Work
Diffstat (limited to 'macros/fft1.sci')
-rw-r--r--macros/fft1.sci112
1 files changed, 63 insertions, 49 deletions
diff --git a/macros/fft1.sci b/macros/fft1.sci
index a0a6438..f8a27fc 100644
--- a/macros/fft1.sci
+++ b/macros/fft1.sci
@@ -1,49 +1,63 @@
-function res = fft1 (x, n, dim)
-//Calculates the discrete Fourier transform of a matrix using Fast Fourier Transform algorithm.
-//Calling Sequence
-//fft (x, n, dim)
-//fft (x, n)
-//fft (x)
-//Parameters
-//x: input matrix
-//n: Specifies the number of elements of x to be used
-//dim: Specifies the dimention of the matrix along which the FFT is performed
-//Description
-//This is an Octave function.
-//The FFT is calculated along the first non-singleton dimension of the array. Thus, FFT is computed for each column of x.
-//
-//n is an integer specifying the number of elements of x to use. If n is larger than dimention along. which the FFT is calculated, then x is resized and padded with zeros.
-//Similarly, if n is smaller, then x is truncated.
-//
-//dim is an integer specifying the dimension of the matrix along which the FFT is performed.
-//Examples
-//x = [1 2 3; 4 5 6; 7 8 9]
-//n = 3
-//dim = 2
-//fft1 (x, n, dim)
-//ans =
-//
-// 6.0000 + 0.0000i -1.5000 + 0.8660i -1.5000 - 0.8660i
-// 15.0000 + 0.0000i -1.5000 + 0.8660i -1.5000 - 0.8660i
-// 24.0000 + 0.0000i -1.5000 + 0.8660i -1.5000 - 0.8660i
-
-funcprot(0);
-lhs = argn(1)
-rhs = argn(2)
-if (rhs < 1 | rhs > 3)
-error("Wrong number of input arguments.")
-end
-
-select(rhs)
-
- case 1 then
- res = callOctave("fft", x)
-
- case 2 then
- res = callOctave("fft", x, n)
-
- case 3 then
- res = callOctave("fft", x, n, dim)
-
- end
-endfunction
+/*Description
+ Calculates the discrete Fourier transform of a matrix using Fast Fourier Transform algorithm.
+ The FFT is calculated along the first non-singleton dimension of the array. Thus, FFT is computed for each column of D.
+ The variable 'N' is an integer that determines the number of elements of 'D' to use.
+ If 'N' is larger than the dimension along which the FFT is calculated,
+ then 'D' is resized and padded with zeros to match the required size.On the other hand,
+ if 'N' is smaller than the size of 'D', then 'D' is truncated to match the required size.
+ DIM is an integer specifying the dimension of the matrix along which the FFT is performed.
+Calling Sequence
+ fft1 (D)
+ fft1 (D, N)
+ fft1 (D, N, DIM)
+Parameters
+ D: input matrix
+ N: Specifies the number of elements of x to be used
+ DIM: Specifies the dimention of the matrix along which the FFT is performed
+Examples
+ D = [1 2 3; 4 5 6; 7 8 9]
+ N = 3
+ DIM = 2
+ fft1 (D,N,DIM)
+ ans =
+ 6.0000 + 0.0000i -1.5000 + 0.8660i -1.5000 - 0.8660i
+ 15.0000 + 0.0000i -1.5000 + 0.8660i -1.5000 - 0.8660i
+ 24.0000 + 0.0000i -1.5000 + 0.8660i -1.5000 - 0.8660i */
+function res = fft1 (D, N, DIM)
+ funcprot(0);
+ lhs = argn(1)
+ rhs = argn(2)
+ if (rhs < 1 | rhs > 3)
+ error("Wrong number of input arguments.")
+ end
+ dimension = size(D);
+ // first non-singleton dimension
+ nsdim = find(dimension >1,1)
+ if isempty(nsdim) then
+ nsdim = 1 // default to 1 to avoid error while calling fft
+ end
+ select(rhs)
+ case 1 then
+ res = fft(D, -1, nsdim);
+ case 2 then
+ if isempty(N) then
+ n = size(D, nsdim);
+ else
+ n = N;
+ end
+ new_size = size(D);
+ new_size(nsdim) = n;
+ D = resize_matrix(D, new_size);
+ res = fft(D, -1, nsdim);
+ case 3 then
+ if isempty(N) then
+ n = size(D, DIM);
+ else
+ n = N;
+ end
+ new_size = size(D);
+ new_size(DIM) = n;
+ D = resize_matrix(D, new_size);
+ res= fft(D, -1, DIM);
+ end
+endfunction