summaryrefslogtreecommitdiff
path: root/macros/dftmtx.sci
blob: 68c00aa13d71eb5cbd8ef6f08f3a7ba34227ec71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2018 - IIT Bombay - FOSSEE
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
// Original Source : https://octave.sourceforge.io/signal/
// Modifieded by:Sonu Sharma, RGIT Mumbai
// Organization: FOSSEE, IIT Bombay
// Email: toolbox@scilab.in

function [d]=dftmtx(n)
    // Computes n-by-n Discrete Fourier transformation matrix

    //Calling Sequence
    //d=dftmtx(n)

    //Parameters
    //n: Real positive scalar number

    // Description
    //This fuction gives a complex matrix of values whose product with a vector produces the discrete Fourier transform. This can also be achieved by directly using the fft function i.e. y=fft(x) is same as y=A*x where A=dftmtx(n).

    // Examples
    //d = dftmtx(4)
    //Output:
    // d  =
    //
    //    1.    1.     1.    1.
    //    1.  - i    - 1.    i
    //    1.  - 1.     1.  - 1.
    //    1.    i    - 1.  - i

    funcprot(0);
    [nargout nargin] = argn();
    if (nargin ~= 1)
        error("dftmtx: invalid number of inputs")
    elseif (~isscalar(n))
        error ("dftmtx: argument must be scalar");
    end

    c = eye(n, n);
    d = [];
    for i = 1:n
        d = [d fft(c(:, i))]
    end

endfunction