Skip to content
TheChatArchiveThe Chat Archive
Mistralmagistral-medium-2506· Mistral AIHugging Face LMArena Human Preference 140K

zaproponuj kod pytgon funkcji RRC (oot raised cos) filter dla sampli bpsk. argumentem…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash’s answer.
  1. User

    zaproponuj kod pytgon funkcji RRC (oot raised cos) filter dla sampli bpsk. argumentem funkcji beda symbole bpsk sps beta i span. zwracane beda sample filtered. chce aby funkcje lub funkcja obslugiwala sample tx i rx.

  2. Mistral Assistant

    Oto funkcja w Pythonie, która implementuje filtr RRC dla sygnału BPSK:

    import numpy as np
    
    def generate_rrc_filter(sps, beta, span):
        """
        Generate Root Raised Cosine filter coefficients.
    
        Parameters:
        - sps: samples per symbol
        - beta: roll-off factor
        - span: filter span in symbols
    
        Returns:
        - h: filter coefficients
        """
        num_taps = int(span * sps) + 1
        t = np.arange(-span/2, span/2 + 1/sps, 1/sps)
    
        def rrc(t, beta, T=1.0):
            eps = 1e-10
            t = t + eps
            t_normalized = t / T
            term1 = np.cos((1 + beta) * np.pi * t_normalized)
            term2 = np.sin((1 - beta) * np.pi * t_normalized) / (4 * beta * t_normalized)
            denominator = 1 - (4 * beta * t_normalized)**2
            h = (term1 + term2) / denominator
            h[t == 0] = (1 + beta * (4/np.pi - 1)) / T
            return h
    
        h = rrc(t, beta)
        h = h / np.sum(h)  # normalize
        return h
    
    def rrc_filter(symbols, sps, beta, span, mode='tx'):
        """
        Apply Root Raised Cosine filter to BPSK symbols.
    
        Parameters:
        - symbols: array of BPSK symbols (+1 or -1)
        - sps: samples per symbol
        - beta: roll-off factor
        - span: filter span in symbols
        - mode: 'tx' for transmit filter, 'rx' for receive filter
    
        Returns:
        - filtered_samples: filtered samples
        """
        h = generate_rrc_filter(sps, beta, span)
    
        # Upsample symbols to sps samples per symbol
        upsampled = np.zeros(len(symbols) * sps)
        upsampled[::sps] = symbols
    
        # Apply filter
        filtered_samples = np.convolve(upsampled, h, mode='same')
    
        return filtered_samples
    
    # Example usage
    symbols = np.array([1, -1, 1, 1, -1])  # example BPSK symbols
    sps = 8  # samples per symbol
    beta = 0.35  # roll-off factor
    span = 10  # filter span in symbols
    
    filtered_tx = rrc_filter(symbols, sps, beta, span, mode='tx')
    print("Filtered TX samples:", filtered_tx)
    
    filtered_rx = rrc_filter(symbols, sps, beta, span, mode='rx')
    print("Filtered RX samples:", filtered_rx)
    

    Funkcja generate_rrc_filter generuje współczynniki filtra RRC na podstawie parametrów sps, beta i span. Następnie funkcja rrc_filter stosuje ten filtr do sygnału BPSK, który został wcześniej podpróbkowany do odpowiedniej liczby próbek na symbol. Wynikiem są próbki po filtracji, które mogą być używane zarówno do nadawania (tx) jak i odbioru (rx).

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.