疑似的な脈波・呼吸・いびきを出力するプログラムです。

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
woodbed
Date:
Thu Jan 26 09:33:27 2017 +0000
Parent:
3:2f4d9f3a4618
Commit message:
AM???????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 2f4d9f3a4618 -r 17cfeca0673c main.cpp
--- a/main.cpp	Tue Dec 13 08:44:01 2016 +0000
+++ b/main.cpp	Thu Jan 26 09:33:27 2017 +0000
@@ -25,10 +25,10 @@
 int   sample_dt             = 100;                  //microsec 10kHz
 float hb_carr_freq          = 8.7;                  //Hz       
 float hb_mod_freq           = 1;                    //Hz
-float hb_carr_level         = 0.083;                //min=0 max=0.5 0.5以上ではMOD 50%以上で振幅が飽和する 
-float hb_mod_ratio          = 63;                   //0-100 %
+float hb_carr_level         = 0.5;                //min=0 max=0.5 0.5以上ではMOD 50%以上で振幅が飽和する 0.083
+float hb_mod_ratio          = 100;                   //0-100 % 63%
 float resp_freq             = 0.3;                  //Hz
-float resp_level            = 0.56;                 //min=0 max=1 
+float resp_level            = 0.56;                 //min=0 max=1  0.56
 float snore_freq            = 150;                  //Hz
 float snore_level           = 0.23;                 //min=0 max=1 
 int snore_oncycle           = 10000;                //On Time = snore_oncycle * sample_dt, snore_oncycle < snore_allcycle;
@@ -48,28 +48,19 @@
 float hb_carr_v_samplepoint = 0;
 
 //HB_mod
-float hb_modp_period        = 1000000*1/(hb_carr_freq + hb_mod_freq);
-float hb_modp_n             = 0;
-float hb_modp_n_sample      = 0;                    //The maximum number of sampling points in the signal
-float hb_modp_tend          = 0;                    //The remainder of sampling points in the signal
-float hb_modp_tstart        = 0;                    //start offset of sampling time
-float hb_modp_t_samplepoint = 0;        
-float hb_modp_table_dt      = hb_modp_period/256;
-float hb_modp_n_samplepoint = 0;
-float hb_modp_v_samplepoint = 0;
-
-float hb_modm_period        = 1000000*1/(hb_carr_freq - hb_mod_freq);
-float hb_modm_n             = 0;
-float hb_modm_n_sample      = 0;                    //The maximum number of sampling points in the signal
-float hb_modm_tend          = 0;                    //The remainder of sampling points in the signal
-float hb_modm_tstart        = 0;                    //start offset of sampling time
-float hb_modm_t_samplepoint = 0;        
-float hb_modm_table_dt      = hb_modm_period/256;
-float hb_modm_n_samplepoint = 0;
-float hb_modm_v_samplepoint = 0;
+float hb_mod_period        = 1000000*1/hb_mod_freq;
+float hb_mod_n             = 0;
+float hb_mod_n_sample      = 0;                    //The maximum number of sampling points in the signal
+float hb_mod_tend          = 0;                    //The remainder of sampling points in the signal
+float hb_mod_tstart        = 0;                    //start offset of sampling time
+float hb_mod_t_samplepoint = 0;        
+float hb_mod_table_dt      = hb_mod_period/256;
+float hb_mod_n_samplepoint = 0;
+float hb_mod_v_samplepoint = 0;
 
 float hb_mod_ra             = hb_mod_ratio * 0.01;
 float hb_signal             = 0;
+float mod_signal            = 0;
 
 //RESP
 float resp_period           = 1000000*1/resp_freq;  //microSec      
@@ -100,6 +91,11 @@
 int   pwidth_2 = 0;
 int   pwidth_3 = 0;
 
+// Debug use only   ----
+int dbcount = 0;
+
+// End of debug use ----
+
 //Signal Culcurate
 void signal_culc(){
        
@@ -124,48 +120,40 @@
             hb_carr_n++;           
             }
 //HB_mod
-//Acosωct+(Ama/2)cos(ωc+ωm)t+(Ama/2)cos(ωc-ωm)t     Acosωct = fcarr(t),ma = modulation ratio,
-        hb_modp_n_sample = (hb_modp_period - hb_modp_tstart) / sample_dt;
-        hb_modp_tend = fmod((hb_modp_period - hb_modp_tstart) , sample_dt); 
-        if(hb_modp_tend == 0){
-            hb_modp_n_sample = hb_modp_n_sample-1;
+//A(1+macosωmt)*cosωct     Acosωct = fcarr(t),ma = modulation ratio,
+        hb_mod_n_sample = (hb_mod_period - hb_mod_tstart) / sample_dt;
+        hb_mod_tend = fmod((hb_mod_period - hb_mod_tstart) , sample_dt); 
+        if(hb_mod_tend == 0){
+            hb_mod_n_sample = hb_mod_n_sample-1;
             }    
-        hb_modp_t_samplepoint = hb_modp_tstart + sample_dt * hb_modp_n; //time of sampling point    
-        hb_modp_n_samplepoint = hb_modp_t_samplepoint / hb_modp_table_dt;
-        if(hb_modp_n_samplepoint >= 256){
-            hb_modp_n_samplepoint = 0;
+        hb_mod_t_samplepoint = hb_mod_tstart + sample_dt * hb_mod_n; //time of sampling point    
+        hb_mod_n_samplepoint = hb_mod_t_samplepoint / hb_mod_table_dt;
+        if(hb_mod_n_samplepoint >= 256){
+            hb_mod_n_samplepoint = 0;
             }
-        hb_modp_v_samplepoint = hb_mod_ra*(coswave[(int)hb_modp_n_samplepoint]);
-        if(hb_modp_n > (int)hb_modp_n_sample) {
-            hb_modp_n =0;
-            hb_modp_tstart = sample_dt - hb_modp_tend;
+        hb_mod_v_samplepoint = hb_mod_ra*(coswave[(int)hb_mod_n_samplepoint]);  
+        if(hb_mod_n > (int)hb_mod_n_sample) {
+            hb_mod_n =0;
+            hb_mod_tstart = sample_dt - hb_mod_tend;
             }
         else {
-            hb_modp_n++;           
-            }
-                        
-        hb_modm_n_sample = (hb_modm_period - hb_modm_tstart) / sample_dt;
-        hb_modm_tend = fmod((hb_modm_period - hb_modm_tstart) , sample_dt); 
-        if(hb_modm_tend == 0){
-            hb_modm_n_sample = hb_modm_n_sample-1;
-            } 
-        hb_modm_t_samplepoint = hb_modm_tstart + sample_dt * hb_modm_n; //time of sampling point    
-        hb_modm_n_samplepoint = hb_modm_t_samplepoint / hb_modm_table_dt;
-        if(hb_modm_n_samplepoint >= 256){
-            hb_modm_n_samplepoint = 0;
-            }
-        hb_modm_v_samplepoint = hb_mod_ra*(coswave[(int)hb_modm_n_samplepoint]);
-        if(hb_modm_n > (int)hb_modm_n_sample) {
-            hb_modm_n =0;
-            hb_modm_tstart = sample_dt - hb_modm_tend;
-            }
-        else {
-            hb_modm_n++;           
+            hb_mod_n++;           
             }
         
-//HB_AM MOD   
-        hb_signal = hb_carr_level*(hb_carr_v_samplepoint + (0.5*hb_modp_v_samplepoint)+(0.5*hb_modm_v_samplepoint))+0.5;//0-1 -> 0V-3.3V
-
+//HB_AM MOD 
+        
+        hb_signal = 0.5*(hb_carr_level*(1+hb_mod_v_samplepoint)*hb_carr_v_samplepoint)+0.5;//0-1 -> 0V-3.3V
+ 
+//debug part      
+/*
+        if(dbcount>=100){
+            pc.printf("%f, %f, %f\n",hb_signal,mod_signal,hb_mod_v_samplepoint);
+            dbcount = 0;
+            }
+        dbcount++;
+*/     
+//end debug part
+        
 //RESP section
         resp_n_sample = (resp_period - resp_tstart) / sample_dt;
         resp_tend = fmod((resp_period - resp_tstart) , sample_dt);
@@ -178,7 +166,7 @@
             resp_n_samplepoint = 0;
             }
         resp_v_samplepoint = resp_level*(coswave[(int)resp_n_samplepoint]);
-        resp_signal = resp_v_samplepoint+0.5;     //0-1 -> 0V-3.3V
+        resp_signal = 0.5*resp_v_samplepoint+0.5;     //0-1 -> 0V-3.3V
         if(resp_n > (int)resp_n_sample) {
             resp_n =0;
             resp_tstart = sample_dt - resp_tend;
@@ -222,7 +210,7 @@
                 snore_cycle = 0;
                 }
             }    
-        snore_signal = snore_v_samplepoint+0.5;   //0-1 -> 0V-3.3V
+        snore_signal = 0.5*snore_v_samplepoint+0.5;   //0-1 -> 0V-3.3V
             
 //PWM Output Pulse width
         pwidth_1 = hb_signal * sample_dt;
@@ -297,47 +285,29 @@
         hb_carr_n_samplepoint = 0;
         hb_carr_v_samplepoint = 0;
         pc.printf("carrf = %f\n",hb_carr_table_dt);
-        hb_modp_period        = 1000000*1/(hb_carr_freq + hb_mod_freq);
-        hb_modp_n             = 0;
-        hb_modp_n_sample      = 0;                  //The maximum number of sampling points in the signal
-        hb_modp_tend          = 0;                  //The remainder of sampling points in the signal
-        hb_modp_tstart        = 0;                  //start offset of sampling time
-        hb_modp_t_samplepoint = 0;        
-        hb_modp_table_dt      = hb_modp_period/256;
-        hb_modp_n_samplepoint = 0;
-        hb_modp_v_samplepoint = 0;
-        hb_modm_period        = 1000000*1/(hb_carr_freq - hb_mod_freq);
-        hb_modm_n             = 0;
-        hb_modm_n_sample      = 0;                  //The maximum number of sampling points in the signal
-        hb_modm_tend          = 0;                  //The remainder of sampling points in the signal
-        hb_modm_tstart        = 0;                  //start offset of sampling time
-        hb_modm_t_samplepoint = 0;        
-        hb_modm_table_dt      = hb_modm_period/256;
-        hb_modm_n_samplepoint = 0;
-        hb_modm_v_samplepoint = 0;
+        hb_mod_period        = 1000000*1/hb_mod_freq;
+        hb_mod_n             = 0;
+        hb_mod_n_sample      = 0;                  //The maximum number of sampling points in the signal
+        hb_mod_tend          = 0;                  //The remainder of sampling points in the signal
+        hb_mod_tstart        = 0;                  //start offset of sampling time
+        hb_mod_t_samplepoint = 0;        
+        hb_mod_table_dt      = hb_mod_period/256;
+        hb_mod_n_samplepoint = 0;
+        hb_mod_v_samplepoint = 0;
         }
     else if(strcmp(scan,"modf")==0){    
         pc.scanf("%f",&para);  
         hb_mod_freq           = para;
-        hb_modp_period        = 1000000*1/(hb_carr_freq + hb_mod_freq);
-        hb_modp_n             = 0;
-        hb_modp_n_sample      = 0;                  //The maximum number of sampling points in the signal
-        hb_modp_tend          = 0;                  //The remainder of sampling points in the signal
-        hb_modp_tstart        = 0;                  //start offset of sampling time
-        hb_modp_t_samplepoint = 0;        
-        hb_modp_table_dt      = hb_modp_period/256;
-        hb_modp_n_samplepoint = 0;
-        hb_modp_v_samplepoint = 0;
-        hb_modm_period        = 1000000*1/(hb_carr_freq - hb_mod_freq);
-        hb_modm_n             = 0;
-        hb_modm_n_sample      = 0;                  //The maximum number of sampling points in the signal
-        hb_modm_tend          = 0;                  //The remainder of sampling points in the signal
-        hb_modm_tstart        = 0;                  //start offset of sampling time
-        hb_modm_t_samplepoint = 0;        
-        hb_modm_table_dt      = hb_modm_period/256;
-        hb_modm_n_samplepoint = 0;
-        hb_modm_v_samplepoint = 0;
-        pc.printf("modf = %f\n",hb_modm_table_dt);
+        hb_mod_period        = 1000000*1/hb_mod_freq;
+        hb_mod_n             = 0;
+        hb_mod_n_sample      = 0;                  //The maximum number of sampling points in the signal
+        hb_mod_tend          = 0;                  //The remainder of sampling points in the signal
+        hb_mod_tstart        = 0;                  //start offset of sampling time
+        hb_mod_t_samplepoint = 0;        
+        hb_mod_table_dt      = hb_mod_period/256;
+        hb_mod_n_samplepoint = 0;
+        hb_mod_v_samplepoint = 0;
+        pc.printf("modf = %f\n",hb_mod_table_dt);
         hb_carr_n             = 0;
         hb_carr_n_sample      = 0;                  //The maximum number of sampling points in the signal
         hb_carr_tend          = 0;                  //The remainder of sampling points in the signal
@@ -422,7 +392,7 @@
 //Make cos wave
     int i;
     for(i=0;i<=255;i++){                         
-        coswave[i]=0.5*(cos(2.0*3.1415*i/256));                                     
+        coswave[i]=cos(2.0*3.1415*i/256);           //2017/1/5  0.5*(cos(2.0*3.1415*i/256));                         
     }
     i = 0;