Диссертация (1105240), страница 19
Текст из файла (страница 19)
f i r s t198<<"␣"<<c a l c u l a t e M e a n S t d d e v ( c o s i n u s , c s a m p l e s ) . f i r s t ;199}200}201}202203204FREE_POINTER( amplTmpFile ) ;205FREE_POINTER( phaseTmpFile ) ;206FREE_POINTER( f f i l t T m p F i l e ) ;207FREE_POINTER( sinTmpFile ) ;208FREE_POINTER( cosTmpFile ) ;209return true ;210}А.4. Реализация выделения сигнала на заданной частотеметодом гетеродинирования на языкепрограммирования Matlab12f u n c t i o n e x t r a c t a m p l i t u d e ( f i l e , Fmain , g a i n c o r r e c t , lumin , noprompt ,forcefmain , Fres )34i f n a r g i n == 45noprompt =0;6f o r c e f m a i n =0;7Fres =63.124;8e l s e i f n a r g i n == 5f o r c e f m a i n =0;9Fres =63.124;1011e l s e i f n a r g i n == 6Fres =63.124;1213end1301415load ( f i l e ) ;161718%Fix timei f e x i s t ( ’ EpochTime ’ , ’ var ’ ) == 0EpochTime=0;1920end21EpochTime=h o u r s f r o m u t c ( EpochTime ) ;2223i f e x i s t ( ’ T s t a r t ’ , ’ var ’ ) == 0Tstart = 0;2425end2627%F i l t e r s i n i t28IIROrder =4;29IIRF3dB=1;30I I R s p e c s=f d e s i g n .
l o w p a s s ( ’N, F3dB ’ , IIROrder , IIRF3dB , FS ) ;31I I R f i l t e r=d e s i g n ( I I R s p e c s , ’ b u t t e r ’ ) ;32f p r i n t f ( ’ Butterworth ␣ f i l t e r : \ n ’ ) ;33measure ( I I R f i l t e r )34f p r i n t f ( ’ - - - - - - - - - - - - - - - - - - -\n ’ ) ;353637reset ( IIRfilter ) ;%s e t ( I I R f i l t e r , ’ PersistentMemory ’ , t r u e ) ;3839F i r F r e q =1000;40downRate=(FS/ F i r F r e q ) ;41i f downRate ~= f l o o r ( downRate )42f p r i n t f ( ’ Sampling ␣ f r e q u e n c y ␣must␣ be ␣a␣ m u l t i p l e ␣ o f ␣ 1000\ n ’ ) ;43return ;44end4546i f e x i s t ( ’ F i r E q u i r i p p l e 1 0 0 0 . mat ’ , ’ f i l e ’ ) == 047FIRspecs=f d e s i g n .
l o w p a s s ( ’ Fp , Fst , Ap , Ast ’ , 0 . 1 , 0 . 3 , 0 . 2 , 5 0 , 1 0 0 0 ) ;48F I R f i l t e r=d e s i g n ( FIRspecs , ’ e q u i r i p p l e ’ ) ;131s a v e ( ’ F i r E q u i r i p p l e 1 0 0 0 . mat ’ , ’ F I R f i l t e r ’ ) ;4950elsel o a d ( ’ F i r E q u i r i p p l e 1 0 0 0 . mat ’ ) ;5152end53Vals=measure ( F I R f i l t e r ) ;54f p r i n t f ( ’ E q u i r i p p l e ␣␣ f i l t e r : \ n ’ ) ;55d i s p ( Vals ) ;56f p r i n t f ( ’ - - - - - - - - - - - - - - - - - - -\n ’ ) ;57FIRgain = 4 . 9 2 3 7 6 4 4 / 5 ;585960%Main s i g n a l s p l i t61MainStep =120*FS ;6263%Averaging params64Nwind=FS ;65N h al f=f l o o r ( Nwind /2 ) ;66Nstep=f l o o r ( Nwind /20 ) ;6768%S c a l i n g i n i t69Lambda=633E - 9 ;70XtoRad=1E - 2 ;717273%Get output f i l e[ path , name , ~ ] = f i l e p a r t s ( f i l e ) ;7475i f e x i s t ( ’Uhv ’ , ’ var ’ ) ~= 1Uhv= -1;7677end7879params=s t r u c t ( ’ I I R f i l t e r ’ , I I R f i l t e r , ’ F I R f i l t e r ’ , F I R f i l t e r , ’ FIRgain ’ ,FIRgain , .
. .80’ Nstep ’ , Nstep , ’ Nhalf ’ , Nhalf , ’ Lambda ’ , Lambda , ’ XtoRad ’ , XtoRad , . . .81’ path ’ , path , ’ name ’ , name , ’ FS ’ , FS , ’ Fmain ’ , Fmain , ’ T s t a r t ’ , Tstart , . . .132’ MainStep ’ , MainStep , ’ EpochTime ’ , EpochTime , ’ g a i n c o r r e c t ’ ,82gaincorrect , . . .’ downRate ’ , downRate , ’ lumin ’ , lumin , ’ f o r c e f m a i n ’ , f o r c e f m a i n , ’ F r e s ’ ,83Fres , ’Uhv ’ ,Uhv) ;8485i f e x i s t ( ’ S i g ’ , ’ var ’ ) == 1p r o c e s s A m p l i t u d e F r o m S i g n a l ( Sig , 1 0 0 , params ) ;8687end8889i n d =0;90w h i l e e x i s t ( s p r i n t f ( ’ S i g%d ’ , in d ) , ’ var ’ ) == 191p r o c e s s A m p l i t u d e F r o m S i g n a l ( e v a l ( s p r i n t f ( ’ S i g%d ’ , i n d ) ) , ind , params ) ;92i n d=in d +1;93end9495end9697f u n c t i o n SPart=f i r s t N s e c ( Sig , FS ,T)98Nret = T*FS ;99i f l e n g t h ( S i g ) > NretSPart=S i g ( 1 : Nret ) ;100else101SPart=S i g ;102end103104end105106f u n c t i o n p r o c e s s A m p l i t u d e F r o m S i g n a l ( Sig , SigNumber , params )107108n e w f i l e=s p r i n t f ( ’%s/%s - l - ampl%d - a t%g .
praw ’ , params . path , params .name , SigNumber , params . Fmain ) ;109110%I n i t header111%r e a l s t a r t time - params . EpochTime+f l o o r ( params . T s t a r t ) ;112i f SigNumber~=100133113h eader = s p r i n t f ( ’#Time␣ Theta%d_%g␣M\n#FS:%d␣ MainFreq:%g␣Uhv:%g\n#S t a r t e d : ␣%s ’ , . . .SigNumber , params . Fmain , params . FS , params . Fmain , params . Uhv ,114...d a t e s t r ( datenum ( [ 1 9 7 0 1 1 0 0 ( params . EpochTime ) ] ) ) ) ;115116else117h eader = s p r i n t f ( ’#Time␣Theta_%g␣M\n#FS:%d␣ MainFreq:%g\n#S t a r t e d : ␣%s ’ , . .
.118params . Fmain , params . FS , params . Fmain , . . .119d a t e s t r ( datenum ( [ 1 9 7 0 1 1 0 0 ( params . EpochTime ) ] ) ) ) ;120end121122%Write header123fID = f o p e n ( n e w f i l e , ’w ’ ) ;124f p r i n t f ( fID , ’%s \n ’ , header ) ;125126i f params . lumin >0 && params . lumin <1127S i g = S i g / params .
lumin ;128end129130i f params . lumin > -1131Sig = asin ( Sig ) ;132end133134TimeStart=params . T s t a r t + 0 . 5 ;135136Fmain = params . Fmain ;137FSnew=params . FS/ params . downRate ;138139140i f params . f o r c e f m a i n == 0i f ( 2 * params . MainStep ) > l e n g t h ( S i g )[ SigCos , S i g S i n ]= s i g h e t e r ( Fmain , params . FS , S i g ) ;141142143else[ SigCos , S i g S i n ]= s i g h e t e r ( Fmain , params . FS , S i g ( 1 : ( 2 * params .MainStep ) ) ) ;134144end145Fmain=f r e q c o r r e c t ( Fmain , SigCos , S i g S i n , params . FS) ;146f p r i n t f ( ’ Real ␣ Frequency : ␣%g\n ’ , Fmain ) ;147c l e a r SigCos S i g S i n ;148elsef p r i n t f ( ’ Using ␣ s u p p l i e d ␣ f r e q u e n c y ␣%g\n ’ , Fmain ) ;149150end151152[ X1 , X2]= s i g h e t e r ( Fmain , params . FS , S i g ) ;153154r e s e t ( params . I I R f i l t e r ) ;155s e t ( params .
I I R f i l t e r , ’ PersistentMemory ’ , t r u e ) ;156[~]= f i l t e r ( params . I I R f i l t e r , f i r s t N s e c (X1 , params . FS , 1 5 ) ) ;157X1= f i l t e r ( params . I I R f i l t e r , X1) ;158r e s e t ( params . I I R f i l t e r ) ;159s e t ( params . I I R f i l t e r , ’ PersistentMemory ’ , t r u e ) ;160[~]= f i l t e r ( params . I I R f i l t e r , f i r s t N s e c (X2 , params .
FS , 1 5 ) ) ;161X2= f i l t e r ( params . I I R f i l t e r , X2) ;162163X1=downsample (X1 , params . downRate ) ;164X2=downsample (X2 , params . downRate ) ;165166%r e s e t ( F I R f i l t e r ) ;167%s e t ( F I R f i l t e r , ’ PersistentMemory ’ , t r u e ) ;168169r e s e t ( params . F I R f i l t e r ) ;170s e t ( params . F I R f i l t e r , ’ PersistentMemory ’ , t r u e ) ;171[~]= f i l t e r ( params .
F I R f i l t e r , f i r s t N s e c (X1 , FSnew , 1 5 ) ) ;172X1= f i l t e r ( params . F I R f i l t e r , X1) / params . FIRgain ;173r e s e t ( params . F I R f i l t e r ) ;174s e t ( params . F I R f i l t e r , ’ PersistentMemory ’ , t r u e ) ;175[~]= f i l t e r ( params . F I R f i l t e r , f i r s t N s e c (X2 , FSnew , 1 5 ) ) ;176X2= f i l t e r ( params . F I R f i l t e r , X2) / params .
FIRgain ;177178Y=s q r t ( 4 . * ( X1 . * X1+X2 . * X2) ) ;135179c l e a r X1 X2 ;180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%181182%Averaging183i f params . g a i n c o r r e c t >= 0184c o r r e c t =(params . Lambda /(8* p i * params . XtoRad ) ) / . . .185a m p l i f g a i n ( Fmain , params . g a i n c o r r e c t ) ;186f p r i n t f ( ’ Gain ␣ m u l t i p l i e r : ␣%g , ␣ t o t a l ␣ c o e f f : ␣%g\n ’ , . . .187188a m p l i f g a i n ( Fmain , params . g a i n c o r r e c t ) , . .
.189correct ) ;else190correct = 1;191192end193Y=downsampleaverage (Y, FSnew ) * c o r r e c t ; %Sampling Freq == 1 ;194Mn=Y* ampltomcoeff ( Fmain , params . F r e s ) ;195f o r i =1: l e n g t h (Y)196197f p r i n t f ( fID , ’ %.8 e ␣%.8 e ␣%.8 e \n ’ , TimeStart , Y( i ) , Mn( i ) ) ;198TimeStart=TimeStart +1;end199200f c l o s e ( fID ) ;201202end203204f u n c t i o n [ XCos , XSin]= s i g h e t e r ( f r e q , Fsamp ,X)205dt=1/Fsamp ;206N=l e n g t h (X) ;207T=l i n s p a c e ( 0 , (N- 1 ) * dt ,N) . ’ ;208XCos=X. * mcos ( f r e q ,T) ;209XSin=X.
* msin ( f r e q ,T) ;210end.