Chris Hills
/
2017_11_28_ELEC347_Coursework
Test
Fork of ELEC347_CourseWork by
Diff: main.cpp
- Revision:
- 7:6cb27cce4c50
- Parent:
- 6:a2737b51424c
- Child:
- 8:192b376a6da7
--- a/main.cpp Tue Nov 28 13:06:24 2017 +0000 +++ b/main.cpp Tue Nov 28 14:37:13 2017 +0000 @@ -9,41 +9,77 @@ //MBED Class Instances follows DigitalOut SampLED(LED1); //Digital Output (GREEN LED is PB_3, D13 You can use an Oscilloscope on This pin to confirm sample rate) +//Analog Inputs +AnalogIn QDEF(PA_2); +AnalogIn BDEF(PA_7); +AnalogIn FDEF(PA_6); AnalogIn Ain(PA_1); //Analog Input (Signal Input 0 to +3 Volts) AnalogOut Aout(PA_4); //Analog Output (Signal Input 0 to +3 Volts) +//Declare Tickers Ticker sample_timer; +Ticker coeff_change; +//Declare Ticker Rates +float sample_rate = (1.0/35000); //Rate of sampling +float coeff_rate = (1.0 / 20); //Rate of updating coefficients +//Initial Input Value float input = 0.0; -FILTER BP_filter(48000,10000,16,2); //Create object of type Filter(Fs,Fo,Boost,Q) + +//Declare Filter +FILTER BP_filter(48000,10000,-16,2); //Create object of type Filter(Fs,Fo,Boost,Q) +//Declare Fixed Variables +float Fo = 1; +float Boost = 0; +float Q = 1; +//Declare Temporary Coefficient Values +float Fo_Current; +float Boost_Current; +float Q_Current; + +//Forward Declarations void sampler(void); - +void coeff_update(void); int main() { - BP_filter.Define_Filter(); - BP_filter.Print_Filter(); - float sample_rate = (1.0/35000); //sample_timer.attach(&sampler,sample_rate); - - while(1) { - } + coeff_change.attach(&coeff_update,coeff_rate); + printf("Hello"); } +void coeff_update(void) +{ + Fo_Current = FDEF * 39999 + 1; + if (abs(Fo_Current - BP_filter.Get_Fo()) > 50) //If Centre Frequency has changed significantly + { + BP_filter.Update_Fo(Fo_Current); //Update Centre Frequency + } + Boost_Current = BDEF * 100 - 50; + if (abs(Boost_Current - BP_filter.Get_Boost()) > 2) //If Boost has changed significantly + { + BP_filter.Update_Boost(Boost_Current); //Update Boost + } + Q_Current = QDEF * 49 + 1; + if (abs(Q_Current - BP_filter.Get_Q()) > 2) //If Q has changed significantly + { + BP_filter.Update_Q(Q_Current); //Update Q + } + BP_filter.Define_Filter(); //Calculate the coefficients + //BP_filter.Print_Filter(); //Print the ceofficients +} void sampler(void) { - printf("H"); SampLED = 1; //LED Indicates start of sampling input = Ain; - BP_filter.setvalue(input); //Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!! + BP_filter.setvalue(input); //Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!! Aout = BP_filter.getvalue(); SampLED = 0; //LED Indicates end of sampling -} - +} \ No newline at end of file