| 
									
										
										
										
											2016-02-23 02:48:27 +00:00
										 |  |  | program msksim
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use, intrinsic :: iso_c_binding
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-27 06:51:40 +00:00
										 |  |  | ! To change to a new code, edit the following line and the filenames
 | 
					
						
							|  |  |  | ! that contain the parity check and generator matrices.
 | 
					
						
							| 
									
										
										
										
											2016-04-01 03:47:17 +00:00
										 |  |  | parameter (N=198, M=126, K=72) ! M and N are global variables on the C side.
 | 
					
						
							| 
									
										
										
										
											2016-02-27 06:51:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 03:04:07 +00:00
										 |  |  | character(50) pchk_file,gen_file
 | 
					
						
							| 
									
										
										
										
											2016-02-27 06:20:08 +00:00
										 |  |  | integer(1) codeword(1:N), decoded(1:K), message(1:K)
 | 
					
						
							|  |  |  | real*8 lratio(N), rxdata(N)
 | 
					
						
							| 
									
										
										
										
											2016-02-23 02:48:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 03:47:17 +00:00
										 |  |  | pchk_file="./jtmode_codes/peg-198-72-irreg-8x3-2x4.pchk"
 | 
					
						
							|  |  |  | gen_file="./jtmode_codes/peg-198-72-irreg-8x3-2x4.gen"
 | 
					
						
							| 
									
										
										
										
											2016-02-23 02:48:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-27 06:20:08 +00:00
										 |  |  | rate=real(K)/real(N)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 03:04:07 +00:00
										 |  |  | call init_ldpc(trim(pchk_file)//char(0),trim(gen_file)//char(0))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-26 02:47:07 +00:00
										 |  |  | message(1:K/2)=1
 | 
					
						
							|  |  |  | message((K/2+1):K)=0
 | 
					
						
							| 
									
										
										
										
											2016-02-23 02:48:27 +00:00
										 |  |  | call ldpc_encode(message,codeword)
 | 
					
						
							| 
									
										
										
										
											2016-02-25 03:04:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 03:47:17 +00:00
										 |  |  | max_iterations=50
 | 
					
						
							| 
									
										
										
										
											2016-02-25 03:04:07 +00:00
										 |  |  | ntrials=1000000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | write(*,*) "Eb/N0   ngood    nundetected"
 | 
					
						
							|  |  |  | do idb = 0, 11
 | 
					
						
							|  |  |  |   db=idb/2.0-0.5
 | 
					
						
							|  |  |  |   sigma=1/sqrt( 2*rate*(10**(db/10.0)) )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ngood=0
 | 
					
						
							|  |  |  |   nue=0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   do itrial=1, ntrials
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     do i=1,N
 | 
					
						
							| 
									
										
										
										
											2016-02-27 06:20:08 +00:00
										 |  |  |       rxdata(i) = 2.0*(codeword(i)-0.5) + sigma*gran()
 | 
					
						
							|  |  |  |     enddo
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! correct signal normalization is important for this decoder.
 | 
					
						
							|  |  |  |     rxav=sum(rxdata)/N
 | 
					
						
							|  |  |  |     rx2av=sum(rxdata*rxdata)/N
 | 
					
						
							|  |  |  |     rxsig=sqrt(rx2av-rxav*rxav)
 | 
					
						
							|  |  |  |     rxdata=rxdata/rxsig
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! s can be tuned to trade a few tenth's dB of threshold 
 | 
					
						
							|  |  |  | ! for an order of magnitude in UER 
 | 
					
						
							|  |  |  |     do i=1,N
 | 
					
						
							|  |  |  |       s=0.75
 | 
					
						
							|  |  |  |       lratio(i)=exp(2.0*rxdata(i)/(s*s))
 | 
					
						
							| 
									
										
										
										
											2016-02-25 03:04:07 +00:00
										 |  |  |     enddo
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     call ldpc_decode(lratio, decoded, max_iterations, niterations)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if( niterations .ge. 0 ) then
 | 
					
						
							|  |  |  |       nueflag=0
 | 
					
						
							|  |  |  |       do i=1,K
 | 
					
						
							|  |  |  |         if( message(i) .ne. decoded(i) ) then
 | 
					
						
							|  |  |  |           nueflag=1
 | 
					
						
							|  |  |  |         endif
 | 
					
						
							|  |  |  |       enddo
 | 
					
						
							|  |  |  |       if( nueflag .eq. 1 ) then
 | 
					
						
							|  |  |  |         nue=nue+1
 | 
					
						
							|  |  |  |       else
 | 
					
						
							|  |  |  |         ngood=ngood+1;
 | 
					
						
							|  |  |  |       endif
 | 
					
						
							|  |  |  |     endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   write(*,"(f4.1,1x,i8,1x,i8)") db,ngood,nue
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-24 01:50:57 +00:00
										 |  |  | enddo
 | 
					
						
							| 
									
										
										
										
											2016-02-25 03:04:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-23 02:48:27 +00:00
										 |  |  | end program msksim
 |