Coder Social home page Coder Social logo

fftpack's Introduction

FFTPack

FFTPack aims to provide an easily usable package of functions using FFTPack library (Fortran 77).

Two libraries

This repo contains two libraries:

  1. FFTpack library
    Contains FFT functions.
  2. Forlab library
    Forlab is a Fortran module that provides a lot of functions for scientific computing mostly inspired by Matlab and Python's package NumPy.

Getting started

git clone https://github.com/zoziha/FFTPack.git
cd FFTPack

Compilation method 1: make & test

Requirements

To build this library you need

  • gfortran version > 10 (better or you need to modify the makefile: remove the '-fallow-argument-mismatch' flag)
  • gnu make
  • terminal bash

make

# executable program
make
make test

# fftpack lib and its includes
make fftpack

When you make this repo, you will get a executable program example_fft.exe in the "./bin" folder, you type make test to run it automatically.

When you type make fftpack, you will get two compiled library files (dynamic and static versions availabe: dll.a/.a) in the "./bin" folder and header files in the "./bin/include" folder. That you can distribute them (fftpack and forlab libraries).

Compilation method 2: fpm

Requirements

To build this library you need

To use fftpack within your fpm project, add the following to fpm.toml file:

[dependencies]
fftpack = {git = "https://github.com/keurfonluu/FFTPack.git" }

Fpm build

# gfortran version < 10
fpm build

# gfortran version > 10
fpm build --flag '-fallow-argument-mismatch' 

According to your gfortran version, select and type the above corresponding command line, you will find your compiled results in the "./build" folder.

Fpm test

# gfortran version < 10
fpm test

# gfortran version > 10
fpm test --flag '-fallow-argument-mismatch' 

According to your gfortran version, select and type the above corresponding command line, you can run the test program.

Or you copy the the executable program example_fft from the "./build" folder to the "./example" folder, then you type ./example_fft to run it linking the "*.bin" files.

example_fft

program example_fft

  use fftpack, only: fft, ifft, czt, conv, xcorr, hilbert, filter, &
                     freq2ind, ind2freq, fftshift, ifftshift
  use forlab, only: disp, ones, loadbin, savebin

  implicit none

  integer(kind = 4) :: i, k
  real(kind = 8) :: toc_time
  real(kind = 8), dimension(:), allocatable :: x, y, w, signal, fsignal
  complex(kind = 8), dimension(:), allocatable :: cfft

  ! 1D Fast Fourier transform
  !===========================
  print *, "1D Fast Fourier transform:"

  x = [ 1., 1., 1., 1., 0., 0., 0., 0., 0. ]

  call disp(fft(x))

  ! 1D Fast Fourier transform using CZT
  !=====================================
  print *; print *, "1D Fast Fourier transform using CZT:"

  call disp(czt(x))

  print *; print *, "1D Inverse Fourier transform:"

  call disp(ifft(fft(x, 10)))

  ! Convolution
  !=============
  print *; print *, "Convolution:"

  call disp(conv(dble([ 1., 2., 3., 4., 5., 6. ]), dble([ 6., 7., 8., 1., 2., 4. ])))

  ! Correlation
  !=============
  print *; print *, "Correlation:"

  call disp(xcorr(dble([ 1., 2., 3., 4., 5., 6. ]), dble([ 6., 7., 8., 1., 2., 4. ])))

  ! Hilbert transform
  !===================
  print *; print *, "Hilbert transform:"

  call disp(hilbert(dble([ 1., 2., 3., 4., 5., 6. ])))

  ! Smooth data using convolution
  !===============================
  print *; print *, "Smooth data using convolution:"

  x = [ -2., 3., 5., -8., 8., 7., -8., -5., 2. ]
  k = 3
  y = conv(dble(x), ones(k))
  y = y(k/2+1:k/2+size(x)) / k

  call disp(y)

  ! Convert frequency to index
  !============================
  print *; print *, "Convert frequency to index:"

  print *, freq2ind(250., 500., 1200)

  ! Convert index to frequency
  !============================
  print *; print *, "Convert index to frequency:"

  print *, ind2freq(600, 500., 1200)

  ! Shift the Fourier transform
  !=============================
  print *; print *, "Shift the Fourier transform:"

  cfft = fft(x, 10)
  cfft = fftshift(cfft)

  call disp(cfft)

  ! Inverse shift the Fourier transform
  !=====================================
  print *; print *, "Inverse shift the Fourier transform:"

  cfft = ifftshift(cfft)

  call disp(cfft)

  ! Filter a signal
  !=================
  print *; print *, "Filter a real seismic signal between 1 and 10 Hz:"

  signal = loadbin("utils/signal.bin")
  fsignal = filter(signal, 100.0d0, 3, dble([ 1., 10. ]), 2, dble(0.5))

  call system("rm -rf utils/fsignal.bin")
  call savebin("utils/fsignal.bin", fsignal)
  print *, "Filtered signal saved in utils/fsignal.bin"

  print *
  stop
end program example_fft

Link

keurfonluu/FFTPack
keurfonluu/Forlab
NCAR/ncl#123

fftpack's People

Contributors

keurfonluu avatar zoziha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fftpack's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.