{"id":19266994,"url":"https://github.com/mljs/fft","last_synced_at":"2025-04-21T19:32:28.196Z","repository":{"id":28220535,"uuid":"31724857","full_name":"mljs/fft","owner":"mljs","description":null,"archived":false,"fork":false,"pushed_at":"2020-10-27T10:19:42.000Z","size":65,"stargazers_count":7,"open_issues_count":4,"forks_count":2,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-12T13:17:21.724Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mljs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-05T16:55:36.000Z","updated_at":"2022-09-27T01:57:57.000Z","dependencies_parsed_at":"2022-09-04T16:51:09.010Z","dependency_job_id":null,"html_url":"https://github.com/mljs/fft","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Ffft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Ffft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Ffft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Ffft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/fft/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250120062,"owners_count":21378131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T20:08:57.807Z","updated_at":"2025-04-21T19:32:28.191Z","avatar_url":"https://github.com/mljs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ml-fft\n\n  [![NPM version][npm-image]][npm-url]\n  [![build status][travis-image]][travis-url]\n  [![David deps][david-image]][david-url]\n  [![npm download][download-image]][download-url]\n\nfft library for the ml libraries.\n\nThe idea of this, another flavor of the FFT library, is to perform, Real and Complex matrix FFT and IFFT, by using only the 1D FFT algorithm.\nThe 1D FFT and IFFT was taken and adapted from this project: [https://github.com/wellflat/javascript-labs/tree/master/cv/fft]\n\n## Installation\n\n`$ npm install ml-fft`\n\n### Import in node\n\n```js\nvar lib = require(\"ml-fft\");\nvar FFT = lib.FFT;\nvar FFTUtils = lib.FFTUtils\n```\n\n### 1D FFT and IFFT\n\n```js\nvar nCols = 16; \nFFT.init(nCols);\nvar re = new Array(nCols);\nvar im = new Array(nCols);\n\nfor(var i=0; i\u003cnCols; i++){\n   re[i] = i;\n   im[i] = nCols - i - 1;\n}\n\nFFT.fft(re, im);\nFFT.ifft(re, im);\n```\n\n### 2D FFT and 2D IFFT\n\ndata contains the matrix. The even rows contain the real part, the odd rows contain the imaginary part.\n\n\n```js\nvar n = 4;\nvar nRows = n;\nvar nCols = n;\nvar data = new Array(nRows*nCols);\nfor(var i=0;i\u003cnRows;i++){\n    for(var j=0;j\u003cnCols;j++){\n        data[i*nCols+j]=i+j;\n    }\n}\nvar ftData = FFTUtils.fft2DArray(data, nCols, nCols);\nvar ftRows = nRows * 2;\nvar ftCols = nCols / 2 + 1;\nvar iftData =  FFTUtils.ifft2DArray(ftData, ftRows, ftCols);\n```\n\n### Matrix-Matrix convolution. \n\nIt performs the convolution in the Fourier space(multiplication) and then makes an inverse transformation of the result. The difference in performance can be tested in the BenchMark script.\n\n```js\nvar n=1024;\nvar data = new Uint32Array(n*n);\nfor(var i=0;i\u003cn;i++){\n    for(var j=0;j\u003cn;j++){\n        data[i*n+j]=i+j;\n    }\n}\n\nvar kn = 21;\nvar kernel = new Array(kn);\nfor(var i=0;i\u003ckn;i++){\n  kernel[i]=new Array(kn);\n  for(var j=0;j\u003ckn;j++){\n      kernel[i][j]=i+j;\n  }\n}\n\nvar convolutedData = FFTUtils.convolute(data, kernel, n, n);\n```\n### toRadix2\n\nConvert the data matrix to a radix2 2D matrix. The input data is a a single vector containing all the values of the matrix\n\n```js\nFFTUtils.toRadix2(data, nRows, nCols);\n```\n\n## License\n\n  [MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/ml-fft.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ml-fft\n[travis-image]: https://img.shields.io/travis/mljs/fft/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/mljs/fft\n[david-image]: https://img.shields.io/david/mljs/fft.svg?style=flat-square\n[david-url]: https://david-dm.org/mljs/fft\n[download-image]: https://img.shields.io/npm/dm/ml-fft.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ml-fft\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Ffft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Ffft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Ffft/lists"}