<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_fm_ext(self, freq, amplitude, peak_freq_dev=None, output_state=True):
 """Sets the func generator to frequency modulation with external modulation. freq is the carrier frequency in Hz."""


        if peak_freq_dev is None:
            peak_freq_dev = freq
        commands = ['FUNC SIN',  # set to output sine functions
                    'FM:STAT ON',
                    'FREQ {0}'.format(freq),
                    'FM:SOUR EXT',
                    # 'FM:FREQ {0}'.format(freq),
                    'FM:DEV {0}'.format(peak_freq_dev),
                    'VOLT {0}'.format(amplitude),
                    'VOLT:OFFS 0']   # set to frequency modulation
        if output_state is True:
            commands.append('OUTP ON')
        else:
            commands.append('OUTP OFF')
        command_string = '\n'.join(commands)
        print_string = '\n\t' + command_string.replace('\n', '\n\t')
        logging.info(print_string)
        self.instr.write(command_string)