How could i synchronize 2 signals
Given that only the falling edge of your input is sharp and well
defined, I suggest the following approach:


Use the input-capture feature of Timer 1 to get a timestamp on the
falling edge and trigger an interrupt.
In the ISR, start by toggling the output in order to set it low. Then
compute the period of the signal (timestamp of this falling edge minus
timestamp of the previous one) and program a compare register to
trigger a compare match event after half a period.
The compare match would automatically toggle the output pin again, by
using the “toggle on compare match” timer output mode.


The following program attempts to implement this approach. Note that it
is completely untested. Input is on pin 8 (i.e. PB0 and ICP1). Output is
on pin 9 (i.e. PB1 and OC1A). The timer is set to run at F_CPU/8 in
order to accommodate frequencies as low as about 30.1&nbsp;Hz. A
different prescaler should be used if lower frequencies are needed. The
program does not rely on the Arduino core, and thus defines its own
main() instead of setup() and loop().

ISR(TIMER1_CAPT_vect)
{
    TCCR1C = _BV(FOC1A);  // force output compare -&gt; toggle output
    static uint16_t last_capture;
    uint16_t capture = ICR1;
    uint16_t period = capture - last_capture;
    last_capture = capture;
    OCR1A = capture + period/2;  // compare match after 1/2 period

    // If output is high, toggle again.
    if (bit_is_set(PINB, PB0))
        TCCR1C = _BV(FOC1A);
}

int main()
{
    // Set OC1A = PB1 = digital 9 as output.
    DDRB = _BV(PB1);

    // Configure Timer 1.
    TCCR1A = _BV(COM1A0);  // toggle OC1A on compare match
    TCCR1B = _BV(CS11);    // clock at F_CPU/8
    TCCR1C = _BV(FOC1A);   // force output compare -&gt; toggle output
    TIFR1  = _BV(ICF1);    // clear capture flag
    TIMSK1 = _BV(ICIE1);   // enable capture interrupt
    sei();

    for (;;) {}
}