Last active
          September 24, 2023 13:44 
        
      - 
      
- 
        Save jshahbazi/5289503 to your computer and use it in GitHub Desktop. 
    A simple convolution of two 1D vectors (signals) done in Fortran
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function convolve(x, h) | |
| implicit none | |
| !x is the signal array | |
| !h is the noise/impulse array | |
| real, dimension(:), allocatable :: convolve, y | |
| real, dimension(:) :: x, h | |
| integer :: kernelsize, datasize | |
| integer :: i,j,k | |
| datasize = size(x) | |
| kernelsize = size(h) | |
| allocate(y(datasize)) | |
| allocate(convolve(datasize)) | |
| !last part | |
| do i=kernelsize,datasize | |
| y(i) = 0.0 | |
| j=i | |
| do k=1,kernelsize | |
| y(i) = y(i) + x(j)*h(k) | |
| j = j-1 | |
| end do | |
| end do | |
| !first part | |
| do i=1,kernelsize | |
| y(i) = 0.0 | |
| j=i | |
| k=1 | |
| do while (j > 0) | |
| y(i) = y(i) + x(j)*h(k) | |
| j = j-1 | |
| k = k+1 | |
| end do | |
| end do | |
| convolve = y | |
| end function convolve | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment