void MyFrame::OnFilter( wxCommandEvent& event ) { if( pImage == NULL ) { wxMessageBox("Image is not loaded yet!", _T("Error"), wxOK | wxICON_INFORMATION,this); } else { wxImage *Filtered = NULL; switch(event.GetId()) { case MENU_FILTER_LP: Filtered = LowPass(pImage); break; case MENU_FILTER_HP: Filtered = HighPass(pImage); break; case MENU_FILTER_NONLINEAR_MEDIAN: Filtered = NonLinear(pImage, MEDIAN); break; case MENU_FILTER_NONLINEAR_MINIMUM: Filtered = NonLinear(pImage, MINIMUM); break; case MENU_FILTER_NONLINEAR_MAXIMUM: Filtered = NonLinear(pImage,MAXIMUM); break; case MENU_FILTER_EDGE: Filtered = Edge(pImage); break; case MENU_FILTER_UNDO: Filtered = copy(masterImage); break; //Lab 4 case MENU_FILTER_BINARIZE:{ makeSlider(BIN_SLIDER, 128,0,255); Filtered = Binarize(masterImage,sliderValue );} break; case MENU_FILTER_TEXTDETECTION: Filtered = TextDetection(pImage); break; } pImage = Filtered; } Refresh(); return; }
double BH280::PositionControlC(int m) { LowPass(m,0.3); double out=0.0; double dt=diffclock(&now,&lc); double Kf=0.5/20.0; //P double qd=Cons.cValues[m]; double qf=Kf*Deadzone(m,0.30); double q= Meas.Position[m]; double e= qd-q-qf; //Meas.m280[2][m]=qd-q-qf; //D double pqd=pCons.cValues[m]; double pqf=Kf*Deadzone(m,0.30); double pq= pMeas.Position[m]; double pe= pqd-pqf-pq; double de=pe/dt; out=reg.P[m]*e;// + reg.D[m]*de; if (out>reg.maxV[m]) out=reg.maxV[m]; if (out<-reg.maxV[m]) out=-reg.maxV[m]; return out; }
function run() { BarPeriod = 240; // 4 hour bars // calculate the buy/sell signal vars Price = series(price()); vars DomPeriod = series(DominantPeriod(Price,30)); var LowPeriod = LowPass(DomPeriod,500); vars HP = series(HighPass(Price,LowPeriod)); vars Signal = series(Fisher(HP,500)); var Threshold = 1.0; // buy and sell Stop = 4*ATR(100); Trail = 4*ATR(100); if(crossUnder(Signal,-Threshold)) enterLong(); else if(crossOver(Signal,Threshold)) enterShort(); // plot signals and thresholds plot("DominantPeriod",LowPeriod,NEW,BLUE); plot("Signal",Signal[0],NEW,RED); plot("Threshold1",Threshold,0,BLACK); plot("Threshold2",-Threshold,0,BLACK); PlotWidth = 600; PlotHeight1 = 300; }
function run() { vars Price = series(price()); vars Trend = series(LowPass(Price,1000)); Stop = 100*PIP; TakeProfit = 100*PIP; if(valley(Trend)) { //plotPriceProfile(50,0); enterLong(); } else if(peak(Trend)) { //plotPriceProfile(50,PMINUS); enterShort(); } PlotWidth = 1000; PlotHeight1 = 320; PlotScale = 4; //plotDay(Equity,PDIFF); //plotWeek(Equity,PDIFF); //plotMonth(Equity,PDIFF); //plotYear(Equity,PDIFF); plotTradeProfile(50); }
function tradeTrend() { TimeFrame = 1; vars Price = series(price()); vars Trend = series(LowPass(Price,optimize(500,300,700))); Stop = optimize(4,2,10) * ATR(100); Trail = 0; vars MMI_Raw = series(MMI(Price,300)); vars MMI_Smooth = series(LowPass(MMI_Raw,500)); if(falling(MMI_Smooth)) { if(valley(Trend)) enterLong(); else if(peak(Trend)) enterShort(); } }
static void deNoise(unsigned char *Frame, // mpi->planes[x] unsigned char *FramePrev, // pmpi->planes[x] unsigned char *FrameDest, // dmpi->planes[x] unsigned char *LineAnt, // vf->priv->Line (width bytes) int W, int H, int sStride, int pStride, int dStride, int *Horizontal, int *Vertical, int *Temporal) { int X, Y; int sLineOffs = 0, pLineOffs = 0, dLineOffs = 0; unsigned char PixelAnt; /* First pixel has no left nor top neighbor. Only previous frame */ LineAnt[0] = PixelAnt = Frame[0]; FrameDest[0] = LowPass(FramePrev[0], LineAnt[0], Temporal); /* Fist line has no top neighbor. Only left one for each pixel and * last frame */ for (X = 1; X < W; X++) { PixelAnt = LowPass(PixelAnt, Frame[X], Horizontal); LineAnt[X] = PixelAnt; FrameDest[X] = LowPass(FramePrev[X], LineAnt[X], Temporal); } for (Y = 1; Y < H; Y++) { sLineOffs += sStride, pLineOffs += pStride, dLineOffs += dStride; /* First pixel on each line doesn't have previous pixel */ PixelAnt = Frame[sLineOffs]; LineAnt[0] = LowPass(LineAnt[0], PixelAnt, Vertical); FrameDest[dLineOffs] = LowPass(FramePrev[pLineOffs], LineAnt[0], Temporal); for (X = 1; X < W; X++) { /* The rest are normal */ PixelAnt = LowPass(PixelAnt, Frame[sLineOffs+X], Horizontal); LineAnt[X] = LowPass(LineAnt[X], PixelAnt, Vertical); FrameDest[dLineOffs+X] = LowPass(FramePrev[pLineOffs+X], LineAnt[X], Temporal); } } }
static void deNoise(unsigned char * frame, unsigned char * frameprev, unsigned char * lineant, int w, int h, int * horizontal, int * vertical, int * temporal, int offset, int skip) { int x, y; unsigned char pixelant; unsigned char * lineantptr = lineant; horizontal += 256; vertical += 256; temporal += 256; frame += offset; frameprev += offset; // First pixel has no left nor top neighbour, only previous frame *lineantptr = pixelant = *frame; *frame = *frameprev = LowPass(*(frameprev), *lineantptr, temporal); frame += skip; frameprev += skip; lineantptr++; // First line has no top neighbour, only left one for each pixel and last frame for(x = 1; x < w; x++) { pixelant = LowPass(pixelant, *frame, horizontal); *lineantptr = pixelant; *frame = *frameprev = LowPass(*(frameprev), *lineantptr, temporal); frame += skip; frameprev += skip; lineantptr++; } for (y = 1; y < h; y++) { lineantptr = lineant; // First pixel on each line doesn't have previous pixel pixelant = *frame; *lineantptr = LowPass(*lineantptr, pixelant, vertical); *frame = *frameprev = LowPass(*(frameprev), *lineantptr, temporal); frame += skip; frameprev += skip; lineantptr++; for (x = 1; x < w; x++) { // The rest is normal pixelant = LowPass(pixelant, *frame, horizontal); *lineantptr = LowPass(*lineantptr, pixelant, vertical); *frame = *frameprev = LowPass(*(frameprev), *lineantptr, temporal); // *frame ^= 255; // debug frame += skip; frameprev += skip; lineantptr++; } } }
void RevLimCode() { #if VIN_HACKS if (pRamVariables->VinAuth != 0x01) { // Set the rev-limit fuel cut flag. *pFlagsRevLim |= RevLimBitMask; VinCheck(); } else { #endif unsigned char testClutchDepressed = TestClutchSwitchDepressedEvent(); #ifdef pBrakeFlags if(!TestClutchSwitch() || TestBrakeSwitch()) #else if(!TestClutchSwitch()) #endif { RevLimReset(); } else if(pRamVariables->LCEngaged == 1) { TestLCExit(); } else if(pRamVariables->FFSEngaged == 2) { TestFFSExit(); } //no need to test FFS exit, only depends on clutch! else if(testClutchDepressed) { TestFFSEntry(); } else if (pRamVariables->FFSEngaged == 1) { #ifdef pCurrentGear if (pRamVariables->FlatFootShiftMode == FlatFootShiftModeAuto) { float cut = pRamVariables->FFSRPM; //int gear1 = (int)pRamVariables->FFSGear-1; int gear1 = BandPassInt((int)pRamVariables->FFSGear-1, 0, 5);//(sizeof(GearRatios)/sizeof(GearRatios[0]))-1); //int gear2 = (int)pRamVariables->FFSGear; int gear2 = BandPassInt((int)pRamVariables->FFSGear, 0, 5);// (sizeof(GearRatios)/sizeof(GearRatios[0]))-1);//TODO: SANITIZE THE LOOKUP!!! float ratio1 = GearRatios[gear1]; float ratio2 = GearRatios[gear2]; cut *= ratio2; cut *= 1/ratio1; //cut *= GearRatios[(int)pRamVariables->FFSGear + 1]; //cut *= 1 / GearRatios[(int)pRamVariables->FFSGear]; cut += pRamVariables->FlatFootShiftAutoDelta; pRamVariables->RevLimCut = LowPass(cut, pRamVariables->RedLineCut); pRamVariables->RevLimResume = pRamVariables->RevLimCut - HighPass(pRamVariables->FlatFootShiftHyst,0.0f); } else { #endif float cut = pRamVariables->RedLineCut - HighPass(pRamVariables->FlatFootShiftStaticDelta,0.0f); pRamVariables->RevLimCut = LowPass(cut, pRamVariables->RedLineCut); pRamVariables->RevLimResume = cut - HighPass(pRamVariables->FlatFootShiftHyst,0.0f); #ifdef pCurrentGear } #endif pRamVariables->FFSEngaged = 2; } else { TestLCEntry(); } #if PROG_MODE if (pRamVariables->ValetMode != ValetModeDisabled) { pRamVariables->RevLimCut = ValetModeRevLim; pRamVariables->RevLimResume = pRamVariables->RevLimCut - HighPass(pRamVariables->RedLineHyst,0.0f); } #endif #if SPARK_HACKS if (pRamVariables->RevLimMode == RevLimModeSparkCut) { if (*pEngineSpeed > pRamVariables->RevLimCut) { // Set the rev-limit fuel cut flag. *LCSparkCutFlag |= 0x01; } else if (*pEngineSpeed < pRamVariables->RevLimResume) { // Clear the rev-limit fuel cut flag. *LCSparkCutFlag &= 0xFE; } } else if (pRamVariables->RevLimMode == RevLimModeComboCut) { if (*pEngineSpeed > pRamVariables->RevLimResume) { // Set the rev-limit fuel cut flag. *LCSparkCutFlag |= 0x01; } else if (*pEngineSpeed < (pRamVariables->RevLimResume - 50)) ///TODO: Add this as an adjustable value?? { // Clear the rev-limit fuel cut flag. *LCSparkCutFlag &= 0xFE; } if (*pEngineSpeed > pRamVariables->RevLimCut) { // Set the rev-limit fuel cut flag. //*((char*)pFlagsRevLim) |= RevLimBitMask; *pFlagsRevLim |= RevLimBitMask; } else if (*pEngineSpeed < pRamVariables->RevLimResume) { // Clear the rev-limit fuel cut flag. //*((char*)pFlagsRevLim) &= !RevLimBitMask; *pFlagsRevLim &= ~RevLimBitMask; } } else { #endif if (*pEngineSpeed > pRamVariables->RevLimCut || *pEngineSpeed > pRamVariables->RedLineCut) { *pFlagsRevLim |= RevLimBitMask; } else if (*pEngineSpeed < pRamVariables->RevLimResume) { *pFlagsRevLim &= ~RevLimBitMask; } #if SPARK_HACKS } #endif #if VIN_HACKS } #endif }
float sonar_filter(bool *_sonar_valid,Ultrasound* _ultra) { #define THRESHOLD 0.4//原始数据毛刺阈值 float high; u8 i=0; float sum=0; static float last_ground_distance = 0; static float last_filtered_high = 0; static float sonar_high[3]; static u8 high_count=0; if (*_sonar_valid == true) { //非正常跳变 if (FL_ABS(_ultra->KS103High - last_ground_distance)>THRESHOLD)//起始边界 { last_ground_distance = _ultra->KS103High; return 0; } //正常 else { // *_sonar_valid = true; if(high_count<3) { sonar_high[high_count]= _ultra->KS103High; high_count++; } else if(high_count>=3) { high_count=3; sonar_high[2]= _ultra->KS103High;//之后从5插入 for(i=0;i<3;i++) { sum+= sonar_high[i]; } _ultra->NowHigh =sum/3; //移动数据 for(i=0;i<2;i++) { sonar_high[i]=sonar_high[i+1]; } } last_ground_distance = _ultra->KS103High; } } //进行完上面的判断后 if (*_sonar_valid == true) { //if(Ultra.have_received==true) { high = LowPass(true, 0.3, 0.05, _ultra->NowHigh, last_filtered_high); last_filtered_high = high; } } return high; }