! 平均处理 do i=1, n-2*(window1-1)/2 Xout1_average(i)=0. do j=i, i+window1-1 Xout1_average(i)=Xout1_average(i)+Xin(j) enddo Xout1_average(i)=Xout1_average(i)/window1 enddo
do i=1, n-2*(window2-1)/2 Xout2_average(i)=0. do j=i, i+window2-1 Xout2_average(i)=Xout2_average(i)+Xin(j) enddo Xout2_average(i)=Xout2_average(i)/window2 enddo
! 加权平均1 do i=1, window1 wn=(window1+1)/2 if(i.le.wn) then w1(i) = i/(wn**2) else w1(i) = (2*wn-i)/(wn**2) endif enddo
do i=1, n-2*(window1-1)/2 Xout1_weighted(i)=0. do j=i, i+window1-1 Xout1_weighted(i)=Xout1_weighted(i)+Xin(j)*w1(j-i+1) enddo enddo ! 加权平均2 do i=1, window2 wn=(window2+1)/2 if(i.le.wn) then w2(i) = i/(wn**2) else w2(i) = (2*wn-i)/(wn**2) endif enddo
do i=1, n-2*(window1-1)/2 Xout2_weighted(i)=0. do j=i, i+window1-1 Xout2_weighted(i)=Xout2_weighted(i)+Xin(j)*w2(j-i+1) enddo enddo
! 中值滤波1 do i=1, n-2*(window1-1)/2
do j=i, i+window1-1 input1(j-i+1) = Xin(j) enddo call sort(input1,Xout1_middle(i),window1) enddo
! 中值滤波2 do i=1, n-2*(window2-1)/2 do j=i, i+window2-1 input2(j-i+1) = Xin(j) enddo call sort(input2,Xout2_middle(i),window2) enddo
do i=1, 132 write(2, 100) i, Xin(i+10), Xout1_average(i+7), Xout2_average(i+4), Xout1_weighted(i+7), Xout2_weighted(i+4), & Xout1_middle(i+7), Xout2_middle(i+4) enddo 100 format(I4, 7(x, F15.4)) end program ch1_filter
SUBROUTINE sort(a,b,n) dimension :: a(n) real b real temp do i=1,n-1 do j=i+1,n if (a(i).gt.a(j)) then temp = a(i) a(i) = a(j) a(j) = temp endif enddo enddo b=a((n+1)/2) return end