Experimental implementation of the adaptive filter of "Interface" magazine in 2016-2017
Dependencies: amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746
Fork of skeleton_unzen_nucleo_f746 by
ハードウェアおよびソフトウェアはskelton_unzen_nucleo_f746を基本にしています。
Revision 16:d4ea3e6a0bce, committed 2017-01-31
- Comitter:
- shorie
- Date:
- Tue Jan 31 12:52:59 2017 +0000
- Parent:
- 15:de22b9d147e0
- Child:
- 17:728ffc633179
- Commit message:
- update the VFO.
Changed in this revision
signal_processing.h | Show annotated file Show diff for this revision Revisions of this file |
vfo.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/signal_processing.h Mon Jan 30 15:01:29 2017 +0000 +++ b/signal_processing.h Tue Jan 31 12:52:59 2017 +0000 @@ -22,15 +22,19 @@ void set_wave_style( wave_style style ); private: - // internal variables.. + // control variables. int frequency; // VFO frequency [Hz] int Fs; // sampling Frequency [Hz] float duty_cycle; // VFO duty cycle. 0 ... 0.5 wave_style style; // style of the wave form. int current_phase; // internal variable of VFO. - int half_way; // change point by duty cycle. ( period * duty_cycle ). - void update_parameter(); // call one of the parameter is changed. + // internal variable. + int half_way; // change point by duty cycle. ( period * duty_cycle ). + float rising_rate; + float falling_rate; + + void update_parameters(void); // call one of the parameter is changed. };
--- a/vfo.cpp Mon Jan 30 15:01:29 2017 +0000 +++ b/vfo.cpp Tue Jan 31 12:52:59 2017 +0000 @@ -8,6 +8,8 @@ this->Fs = 48000; this->frequency = 440; this->duty_cycle = 0.5; + + this->update_parameters(); } // End of constructor() @@ -24,12 +26,17 @@ if ( this->style == square ) { if ( this->current_phase < this->half_way ) - out_buffer[i] = 0.5; + out_buffer[i] = 1.0; else out_buffer[i] = 0.0; } - - // to do, triangle. + else // style == triangle + { + if ( this->current_phase < this->half_way ) + out_buffer[i] = this->rising_rate * this->current_phase; + else + out_buffer[i] = 1 + this->falling_rate * ( this->current_phase - this->half_way ); + } // update phase this->current_phase += this->frequency; @@ -46,13 +53,17 @@ if ( Fs != 32000 && Fs != 44100 && Fs != 96000 && Fs != 48000 ) Fs = 48000; this->Fs = Fs; + + this->update_parameters(); } void VFO::set_frequency( int freq ) { if ( freq > this->Fs / 4 ) - freq = Fs/4; + freq = Fs / 4; this->frequency = freq; + + this->update_parameters(); } void VFO::set_duty_cycle( float duty ) @@ -62,6 +73,8 @@ if ( duty < 0.01f ) // low limit duty = 0.01f; this->duty_cycle = duty; + + this->update_parameters(); } void VFO::set_wave_style( wave_style style ) @@ -70,4 +83,19 @@ } - + // update the internal parameter by given parameters +void VFO::update_parameters(void) +{ + // calc the half_way; + this-> half_way = this->frequency * this-> duty_cycle; + + // forbid to be zero. + if ( this-> half_way < this->frequency ) + half_way = this->frequency; + + // for triangle wave; + this->rising_rate = 1.0 / this->half_way; + + this->falling_rate = - 1.0 / ( this->Fs - this->half_way ); +} +