声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2723|回复: 0

[Fortran] 直接按定义求序列x(n),h(n) 的线性卷积y(n)

[复制链接]
发表于 2006-8-11 07:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
直接按定义求序列x(n),h(n) 的线性卷积y(n)

主程序:
  1. C----------------------------------------------------------------------
  2. C main program HCONVO1:To test subroutine CONVO1
  3. c Please link subroutine CONVO1
  4. C----------------------------------------------------------------------
  5.         dimension h(0:7),x(0:7),y(0:7)
  6.         data m/4/,n/4/
  7.         l=n+m-1
  8. C
  9.         do 10 i=0,3
  10.            h(i)=1.
  11.            x(i)=i+1.
  12. 10      continue
  13.         call convo1(x,h,y,n,m,l,Ierror)
  14.         write(*,*)'   Ierror=',Ierror
  15.         do 2 k=0,l-1
  16. 2          write(*,*)k,y(k)
  17.         stop
  18.         end
复制代码


子程序:
  1.         subroutine convo1(x,h,y,n,m,L,Ierror)
  2. c--------------------------------------------------------------------
  3. c Routine CONVO1: To implement Linear Convolution y(n)=x(n)*h(n)
  4. c input parameters:
  5. c x(n):L dimensioned real array,signal data is stored in x(0) to x(n-1).
  6. c h(n):L dimensioned real array,impulse response is stored in h(0) to h(m-1).
  7. c n   : the data length of x.
  8. c m   : the data length of h.
  9. c L   : the data length of y, L must be >=n+m-1
  10. c output parameters:
  11. c y(n):L dimensioned real array, y(n)=x(n)*h(n),n=0,...L-1.
  12. c                                      in Chapter 1
  13. c--------------------------------------------------------------------
  14.         dimension x(0:L-1),h(0:L-1),y(0:L-1)
  15.         Ierror=0
  16.         if(l.ge.(m+n-1))goto 1
  17.         Ierror=1
  18.         return
  19. 1       do 2 i=n,L-1
  20. 2          x(i)=0.0
  21.         do 3 i=m,L-1
  22. 3          h(i)=0.0
  23. c
  24.         do 11 k=0,L-1
  25.            sum=0.0
  26.            do 12 i=0,k
  27.               sum=sum+x(i)*h(k-i)
  28. 12          continue
  29.            y(k)=sum
  30. 11       continue
  31.         return
  32.         end
复制代码
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-30 03:22 , Processed in 0.058663 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表