对开关量滤波器进行补偿

问题描述

我尝试为我的过滤器实现偏移量,但是使用mplab进行c编码比使用matlab软件更困难。这是程序: 如果您有任何想法或想法,将非常有帮助。我有一个不和谐的频道,很长一段时间以来我一直想弄清楚这个问题,这是关于:

的项目

使用2个线圈的维护或强制维护模式是一种允许通过发送信号连续测量谐振频率和弦的激励的模式,通过保持激励信号使其振动而称为自振荡组件。在连续运行的情况下,读取站可以读取500到3000 Hz之间的频率。 振动弦传感器具有两个线圈:激励线圈被提供一个正弦电压,其频率等于和弦的共振频率,从而产生正弦变化的磁场,而另一个允许检测和弦的共振。 。这些线圈之间的磁耦合随后通过琴弦的运动而改变,这在测量线圈中暗示了取决于琴弦的运动及其共振频率的信号。 由于琴弦的基本谐振频率约为1 kHz,因此微控制器会向激励线圈发送方波电压。然后,在放大和A / D转换之后,调整激励信号的频率,并测量传感器输出端的信号幅度。最后,当测得的振幅达到最大值(160 mv)时,将测量琴弦的共振频率,并通过另一个线圈将其显示在屏幕上。

问题解决: 因此,设备可以通过向传感器发送信号来读取传感器的频率。我实际上使用2个传感器。第一个称为SG,此传感器设置为ON结构,因此不会有偏差,但对于另一个传感器,则为INSIDE结构,因此可能会有偏差。因此,当我切换回去时,它会再次发送信号,但没有返回正确的频率,这会引起问题,我真的需要让我的设备为此传感器做这件事

int lccv_RecenterFrequency( float* aM1TargetGain,float aFrequencyMean,float* aCenterFrequency )
{
    
    
    int retCode;

    int i,j;
    float centerFrequency;
    float driftFrequency;
    float frequencyGap;

    int isStarted = LCCV_NO;
    int isStabilised = LCCV_NO;

    float m1CurrentGain;
    float m1TargetGain;
    float gainTable[ 10 ];
    int gainIndex;
    float maGainTable[ 5 ];
    float frequencyTable[ 5 ];
    
    int maGainIndex;
    float maGainValue;
    float lowestGainValue;
    float lowestGainFilterFrequency;

    float regressionSlope;
    float frequencyMean;
    int indexMean = 0;

    int progressBar = 0;
    int loopNb;
    int nbFrequencyChange = 0;
    ST_GAIN_CONTROL gainData;

    char buffer[LCD_CHAR_BY_LINE + 1];

/*

 TODO ...  TODO ...  TODO ...  TODO ...

 Do an offset on the high pass frequency (instead of center frequency)
 Find the best gain value

 Do the same with the low pass value
   */

    // Initial center frequency
    centerFrequency = *aCenterFrequency;
    driftFrequency = centerFrequency * MODE4_FREQUENCY_DRIFT_FACTOR;

    // Update Fo frequency of the high pass filter
    HAL_TMR_ChangeHighPassFilter( centerFrequency - driftFrequency );
    // Update Fo frequency of the low pass filter
    HAL_TMR_ChangeLowPassFilter( centerFrequency + driftFrequency );


    // Set initial gain
    retCode = CAL_SetM1GainValue( *aM1TargetGain,&m1CurrentGain );
    
    // Initialise the target gain
    m1TargetGain = m1CurrentGain;
    gainData.targetGain = m1TargetGain;
    gainData.mostRecentDeviationIdx = 0;
    gainData.maxGain = gainData.targetGain;
    gainData.previousTargetGain = gainData.targetGain;
    gainData.previousDeviation = 0;
    

    for( i=0; i<10; i++ )
        gainTable[i] = m1TargetGain;

    for( i=0; i<5; i++ )
        maGainTable[i] = m1TargetGain;

    for( i=0; i<5; i++ )
        frequencyTable[i] = centerFrequency;
 

    gainIndex = 0;
    maGainIndex = 0;
    j = 0;

    int degressiveSweep;
    if( gainData.frequency < centerFrequency )
        degressiveSweep = 1;
    else
        degressiveSweep = 0;

    do
    {
        //

        // Gain controller
        lccv_GainController( &gainData );

        // For the next loop
        gainData.previousTargetGain = gainData.targetGain;
        gainData.previousDeviation = gainData.currentDeviation;
        m1TargetGain = gainData.targetGain;

        gainTable[gainIndex++] = m1TargetGain;

        if( gainIndex > 10 - 1 )
            gainIndex = 0;

        // Change the M1 gain
        CAL_SetM1GainValue( m1TargetGain,&m1CurrentGain );

        frequencyGap = gainData.frequency - centerFrequency;

        if( j > 10 )
        {
            // Compute the moving average for gains
            maGainValue = 0;
            for( i=0; i<10; i++ )
                maGainValue += gainTable[i];
            maGainValue /= 10;

            maGainTable[maGainIndex] = maGainValue;

            // Keep the current center frequency
            frequencyTable[maGainIndex++] = centerFrequency;

            if( maGainIndex > 5 - 1 )
                maGainIndex = 0;

            LCCV_RegressionLineSlope( 5,frequencyTable,maGainTable,&regressionSlope );

#ifdef _TRACE_MODE_4
    sprintf(buffer,"G0: %.1f  %.1f",maGainTable[0],frequencyTable[0] );
//    _DEBUG_TRACE( strlen(buffer),buffer )
    sprintf(buffer,"G1: %.1f  %.1f",maGainTable[1],frequencyTable[1] );
//    _DEBUG_TRACE( strlen(buffer),"G2: %.1f  %.1f",maGainTable[2],frequencyTable[2] );
//    _DEBUG_TRACE( strlen(buffer),"G3: %.1f  %.1f",maGainTable[3],frequencyTable[3] );
//    _DEBUG_TRACE( strlen(buffer),"G4: %.1f  %.1f",maGainTable[4],frequencyTable[4] );
//    _DEBUG_TRACE( strlen(buffer),"Slope %d: %.1f",nbFrequencyChange,regressionSlope );
//    _DEBUG_TRACE( strlen(buffer),buffer )
#endif

            // Change frequency sweep direction
            //      The gain are increasing
            if( degressiveSweep == 1 && regressionSlope < 0 )
                degressiveSweep = 0;
            if( degressiveSweep == 0 && regressionSlope > 0 )
                degressiveSweep = 1;

            // Gain stabilisation
            if(     nbFrequencyChange > 5
                 && regressionSlope < 0.5
                 && regressionSlope > -0.5)
            {
                 break;
            }

            // Filter centered on the fundamental frequency
            if(     frequencyGap < 10
                &&  frequencyGap > -10 )
            {
                break;
            }

            // Change center frequency
            if( degressiveSweep == 1 )
                centerFrequency -= 10;
            else
                centerFrequency += 10;
            if(  frequencyGap >= 0 )
            {
                if( frequencyGap * 0.03 < 5 )
                    centerFrequency += 5;
                else
                centerFrequency += (frequencyGap * 0.03);

            }
            else
            {
                if( frequencyGap * 0.03 > -5 )
                    centerFrequency -= 5;
                else
                centerFrequency += (frequencyGap * 0.03);
            }

            driftFrequency = centerFrequency * MODE4_FREQUENCY_DRIFT_FACTOR;

            // Update Fo frequency of the high pass filter
            HAL_TMR_ChangeHighPassFilter( centerFrequency - driftFrequency );
            // Update Fo frequency of the low pass filter
            HAL_TMR_ChangeLowPassFilter( centerFrequency + driftFrequency );

            j = 0;
            nbFrequencyChange++;
        }
        else
        {
            j++;
        }


sprintf( buffer,"  RECENTER   " );
ihm_LCD_DisplayStringFromAddress( LCD_LINE_1_ADDRESS,strlen(buffer),buffer);
sprintf( buffer,"         F: %.1f ",centerFrequency );
ihm_LCD_DisplayStringFromAddress( LCD_LINE_2_ADDRESS,buffer); 
sprintf( buffer," Sl: %.2f  ",regressionSlope );
 ihm_LCD_DisplayStringFromAddress( LCD_LINE_3_ADDRESS,buffer);
 sprintf( buffer," A: %.3f V  G: %.1f ",gainData.amplitude,gainData.targetGain );
 ihm_LCD_DisplayStringFromAddress( LCD_LINE_4_ADDRESS,buffer);

  
    }
    while( nbFrequencyChange < 100 );


    *aCenterFrequency = centerFrequency;
    *aM1TargetGain = m1TargetGain;

    return RC_OK;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...