Exemplo n.º 1
0
while c < 11:
    while not h.is_prime(x):
        x += 2
    for ch in str(x):
        if int(ch) % 2 == 0 and ch != '2':
            x += 2
    number = x
    skip = False
    while number > 0:
        if not h.is_prime(number):
            skip = True
            break
        number /= 10
    if skip:
        x += 2
        continue
    number = x % (10**int(h.log10(x)))
    while number > 0:
        if not h.is_prime(number):
            skip = True
            break
        number = number % (10**int(h.log10(number)))
    if skip:
        x += 2
    else:
        c += 1
        print x
        r += x
        x += 2
print r
Exemplo n.º 2
0
def dft_analysis(_input, window, N):
    """
    Analysis of a signal using the discrete Fourier transform
    inputs:
    _input: tensor of shape [batch_size, N]
    window: analysis window, tensor of shape [N]
    N: FFT size
    returns:
    Tensors m, p: magnitude and phase spectrum of _input
    m of shape [batch_size, num_coefficients]
    p of shape [batch_size, num_coefficients]
    """

    if not (is_power2(N)):
        raise ValueError("FFT size is not a power of 2")

    _, input_length = _input.get_shape()
    _input_shape = tf.shape(_input)

    if (int(input_length) > N):
        raise ValueError("Input length is greater than FFT size")

    if (int(window.get_shape()[0]) != N):
        raise ValueError("Window length is different from FFT size")

    if int(input_length) < N:
        with tf.name_scope('DFT_Zero_padding'):
            zeros_left = tf.zeros(_input_shape)[:, :int((N -
                                                         (int(input_length)) +
                                                         1) / 2)]
            zeros_right = tf.zeros(_input_shape)[:, :int(
                (N - (int(input_length))) / 2)]
            _input = tf.concat([zeros_left, _input, zeros_right], axis=1)
            assert (int(_input.get_shape()[1]) == N)

    positive_spectrum_size = int(N / 2) + 1
    with tf.name_scope('Windowing'):
        window_norm = tf.div(window, tf.reduce_sum(window))
        # window the input
        windowed_input = tf.multiply(_input, window_norm)

    with tf.name_scope('Zero_phase_padding'):
        # zero-phase window in fftbuffer
        fftbuffer_left = tf.slice(windowed_input, [0, int(N / 2)], [-1, -1])
        fftbuffer_right = tf.slice(windowed_input, [0, 0], [-1, int(N / 2)])
        fftbuffer = tf.concat([fftbuffer_left, fftbuffer_right], axis=1)
        fft = tf.spectral.rfft(fftbuffer)

    with tf.name_scope('Slice_positive_side'):
        sliced_fft = tf.slice(fft, [0, 0], [-1, positive_spectrum_size])

    with tf.name_scope('Magnitude'):
        # compute absolute value of positive side
        abs_fft = tf.abs(sliced_fft)

        # magnitude spectrum of positive frequencies in dB
        magnitude = 20 * log10(tf.maximum(abs_fft, 1E-06))

    with tf.name_scope('Phase'):
        # phase of positive frequencies
        phase = angle(sliced_fft)

    return magnitude, phase