Ejemplo n.º 1
0
    def __init__(self,
                 channel,
                 snr,
                 n_antennas_BS,
                 n_antennas_MS,
                 transform,
                 n_samples,
                 n_pilots,
                 name=None):
        self.n_antennas_BS = n_antennas_BS
        self.n_antennas_MS = n_antennas_MS
        self.snr = snr
        self.n_pilots = n_pilots
        self.rho = 10**(0.1 * snr)
        self.transform = transform
        self.channel_config = channel.get_config()
        self.sigma2_all = np.zeros(n_samples)

        X = pilot_matrix(n_pilots, n_antennas_BS, n_antennas_MS)
        Xprod = X.conj().T @ X
        Q_BS = transform(np.eye(n_antennas_BS), False)
        Q_MS = transform(np.eye(n_antennas_MS), False)
        Q = np.kron(Q_MS, Q_BS)

        Q = Q.T @ X.conj().T
        A = np.linalg.pinv(np.abs(Q.dot(Q.conj().T))**2)

        self.W = np.zeros((n_samples, Q.shape[0]))
        self.W_scaled = np.zeros(self.W.shape)
        self.bias = np.zeros(n_samples)

        for i in range(n_samples):
            _, t_BS, t_MS = channel.generate_channel(1, 1, n_antennas_BS,
                                                     n_antennas_MS)
            C_BS = toeplitz(t_BS)
            C_MS = toeplitz(t_MS)
            C = np.kron(C_MS, C_BS)
            sigma2 = np.real(
                np.trace(C @ Xprod) /
                (n_antennas_BS * n_pilots * 10**(self.snr * 0.1)))
            self.sigma2_all[i] = sigma2
            W = C @ X.conj().T @ np.linalg.pinv(
                X @ C @ X.conj().T + sigma2 * np.eye(n_antennas_BS * n_pilots))

            self.W[i, :] = A.dot(np.real(np.diag(Q @ X @ W @ Q.conj().T, 0)))
            self.bias[i] = np.real(
                np.linalg.slogdet(
                    np.eye(n_antennas_BS * n_pilots) -
                    Q.conj().T.dot(np.diag(self.W[i, :])).dot(Q))[1])
            #multiply directly with sample-based noise-cov
            self.W_scaled[i, :] = self.W[i, :] * (1 / sigma2)

        if name is None:
            self.name = 'SE_' + transform.__name__ + '_' + str(
                StructuredMMSE._object_counter)
            StructuredMMSE._object_counter += 1
        else:
            self.name = name
Ejemplo n.º 2
0
            def func(a):
                import tensorflow as tf
                #import numpy as np
                if a.dtype not in [tf.complex64, tf.complex128]:
                    a = tf.cast(a, dtype=complexx(K.floatx()))
                X = K.constant(pilot_matrix(n_pilots, n_antennas_BS, n_antennas_MS),dtype=complexx(K.floatx()))
                a = tf.matmul(a , X)
                a_shape = tf.shape(a)
                fft = tf.signal.fft(tf.concat([a, tf.zeros(a_shape, dtype=a.dtype)], -1)) / tf.sqrt(tf.cast(2 * a_shape[-1], dtype=a.dtype))

                return fft
Ejemplo n.º 3
0
    def __init__(self,
                 channel,
                 snr,
                 n_antennas_BS,
                 n_antennas_MS,
                 n_pilots,
                 name=None):
        self.snr = snr
        self.n_pilots = n_pilots
        self.n_antennas_BS = n_antennas_BS
        self.n_antennas_MS = n_antennas_MS
        self.channel_config = channel.get_config()
        self.rho = []

        F_BS = np.fft.fft(np.eye(n_antennas_BS))
        F_MS = np.fft.fft(np.eye(n_antennas_MS))
        self.F = 1 / np.sqrt(n_antennas_BS * n_antennas_MS) * np.kron(
            F_MS, F_BS)

        _, t_BS, t_MS = scm_channel(np.array([0.0]),
                                    np.array([0.0]),
                                    np.array([1.0]),
                                    1,
                                    n_antennas_BS,
                                    n_antennas_MS,
                                    sigma_BS=channel.path_sigma_BS,
                                    sigma_MS=channel.path_sigma_MS)
        C_BS = toeplitz(t_BS)
        C_MS = toeplitz(t_MS)
        C = np.kron(C_MS, C_BS)

        c_BS = best_circulant_approximation(t_BS)
        c_MS = best_circulant_approximation(t_MS)
        c = np.kron(c_MS, c_BS)

        self.X = pilot_matrix(n_pilots, n_antennas_BS, n_antennas_MS)
        Xprod = self.X.conj().T @ self.X
        sigma2 = np.real(
            np.trace(C @ Xprod) /
            (n_antennas_BS * n_pilots * 10**(self.snr * 0.1)))
        self.rho.append(1 / sigma2)

        self.w = c / (c + 1 / self.rho[-1])  # MMSE filter at sample i
        self.v = mat2vec(
            np.fft.fft2(vec2mat(self.w, n_antennas_BS, n_antennas_MS)))
        self.bias = np.sum(np.log(np.abs(1 - self.w)))

        if name is None:
            self.name = 'FE_' + str(FastMMSE._object_counter)
            FastMMSE._object_counter += 1
        else:
            self.name = name
Ejemplo n.º 4
0
    def estimate(self, y, n_pilots, n_antennas_MS, t_BS, t_MS):
        n_batches, n_coherence, mn = y.shape
        n_antennas_BS = int(mn / n_pilots)
        y_n = np.zeros([n_batches, n_coherence, n_antennas_BS * n_antennas_MS],
                       dtype=complex)
        X = pilot_matrix(n_pilots, n_antennas_BS, n_antennas_MS)

        for i in range(n_batches):
            y_i = X.conj().T @ y[i, :, :].T
            y_n[i, :, :] = y_i.reshape(
                [1, n_coherence, n_antennas_BS * n_antennas_MS])

        z = mat2vec(np.fft.fft2(vec2mat(y_n, n_antennas_BS,
                                        n_antennas_MS))) / np.sqrt(
                                            n_antennas_MS * n_antennas_BS)
        #z = self.transform(y_n,False)

        (n_batches, n_coherence,
         n_antennas) = z.shape  # input data in transformed domain
        if n_antennas_MS == n_pilots:
            Xprod = X @ X.conj().T
            x = np.real(Xprod[0, 0])
            self.rho = (n_pilots * 10**(self.snr * 0.1)) / (x * n_antennas_MS)
            cest = np.sum(np.abs(z)**2, axis=1) - n_coherence / self.rho
            cest[cest < 0] = 0
            cest = np.reshape(cest, (n_batches, n_antennas))

            W = cest / (cest + n_coherence / self.rho)
        else:
            W = np.zeros((n_batches, n_antennas))
            for n_b in range(n_batches):
                Xprod = X.conj().T @ X
                C = np.kron(toeplitz(t_MS[n_b, :]), toeplitz(t_BS[n_b, :]))
                sigma2 = np.real(
                    np.trace(C @ Xprod) /
                    (n_antennas_BS * n_pilots * 10**(self.snr * 0.1)))
                self.rho = (1 / sigma2)
                cest_batch = np.sum(np.abs(z[n_b, :, :])**2,
                                    axis=0) - n_coherence / self.rho
                cest_batch[cest_batch < 0] = 0
                cest_batch = np.reshape(cest_batch, (1, n_antennas))
                W[n_b, :] = cest_batch / (cest_batch + n_coherence / self.rho)

        W = np.reshape(W, (n_batches, 1, n_antennas))

        hest = mat2vec(
            np.fft.ifft2(vec2mat(W * z, n_antennas_BS,
                                 n_antennas_MS))) * np.sqrt(
                                     n_antennas_BS * n_antennas_MS)
        return hest
Ejemplo n.º 5
0
    def __init__(self,
                 channel,
                 snr,
                 n_antennas_BS,
                 n_antennas_MS,
                 n_samples,
                 n_pilots,
                 name=None):
        self.n_antennas_BS = n_antennas_BS
        self.n_antennas_MS = n_antennas_MS
        self.snr = snr
        self.n_pilots = n_pilots
        self.rho = 10**(0.1 * snr)
        self.W = list()
        self.bias = list()
        self.channel_config = channel.get_config()
        self.X = pilot_matrix(n_pilots, n_antennas_BS, n_antennas_MS)
        self.Xprod = self.X.conj().T @ self.X
        self.sigma2_all = np.zeros(n_samples)

        for i in range(n_samples):
            _, t_BS, t_MS = channel.generate_channel(1, 1, n_antennas_BS,
                                                     n_antennas_MS)
            C_BS = toeplitz(t_BS)
            C_MS = toeplitz(t_MS)
            C = np.kron(C_MS, C_BS).T
            sigma2 = np.real(
                np.trace(C @ self.Xprod) /
                (n_antennas_BS * n_pilots * 10**(self.snr * 0.1)))
            self.sigma2_all[i] = sigma2
            self.W.append(
                C @ self.X.T.conj()
                @ (np.linalg.inv(self.X @ C @ self.X.T.conj() +
                                 sigma2 * np.eye(n_antennas_BS * n_pilots)))
            )  # MMSE filter at sample i
            self.bias.append(
                np.real(
                    np.linalg.slogdet(
                        np.eye(n_antennas_BS * n_pilots) -
                        self.X @ self.W[-1]))[1])  # bias term at sample i

        if name is None:
            self.name = 'GE_' + str(DiscreteMMSE._object_counter)
            DiscreteMMSE._object_counter += 1
        else:
            self.name = name
Ejemplo n.º 6
0
    def estimate(self, y, n_pilots, n_antennas_MS):
        (n_batches, n_coherences, mn) = y.shape
        n_antennas_BS = int(mn / n_pilots)
        X = pilot_matrix(n_pilots, n_antennas_BS, n_antennas_MS)
        y_n = np.zeros(
            [n_batches, n_coherences, n_antennas_BS * n_antennas_MS],
            dtype=complex)
        for i in range(n_batches):
            y_i = X.conj().T @ y[
                i, :, :].T  #reshape([n_antennas*n_pilots,n_coherences])
            y_n[i, :, :] = y_i.reshape(
                [1, n_coherences, n_antennas_BS * n_antennas_MS])
        z = fft_2d(y_n,
                   first_dim=n_antennas_MS,
                   sec_dim=n_antennas_BS,
                   transpose=False)
        (n_batches, n_coherence, n_antennas) = z.shape
        n_samples = self.W.shape[0]

        cest = np.sum(np.abs(z)**2, axis=1)
        cest = np.reshape(cest, (n_batches, n_antennas))

        exps = cest.dot(self.W_scaled.T
                        ) + self.bias * n_coherence  # note cest sum not mean
        exps = exps - np.tile(
            np.reshape(np.amax(exps, axis=-1), (n_batches, 1)), [1, n_samples])

        weights = np.exp(exps)
        weights = weights / np.tile(
            np.reshape(np.sum(weights, axis=-1),
                       (n_batches, 1)), [1, n_samples])

        F = weights.dot(self.W.conj())
        F = np.reshape(F, (n_batches, 1, n_antennas_BS * n_antennas_MS))

        hest = fft_2d(F * z,
                      first_dim=n_antennas_MS,
                      sec_dim=n_antennas_BS,
                      transpose=True)
        return hest
Ejemplo n.º 7
0
    def estimate(self, h, t_BS, t_MS, y, n_antennas_MS):
        hest = np.zeros(h.shape, dtype=h.dtype)
        (n_batches, n_coherence, n_antennas) = h.shape
        mn = y.shape[-1]
        n_antennas_BS = int(n_antennas / n_antennas_MS)
        n_pilots = int(mn / n_antennas_BS)
        X = pilot_matrix(n_pilots, n_antennas_BS, n_antennas_MS)
        Xprod = X.conj().T @ X
        for b in range(n_batches):
            C_BS = toeplitz(t_BS[b, :])  # get full cov matrix#
            C_MS = toeplitz(t_MS[b, :])  # get full cov matrix
            C = np.kron(C_MS, C_BS)

            sigma2 = np.real(
                np.trace(C @ Xprod) /
                (n_antennas_BS * n_pilots * 10**(self.snr * 0.1)))
            noise_cov = np.identity(n_antennas_BS * n_pilots) * sigma2
            Cr = X @ C @ X.conj().T + noise_cov

            hest[b, :, :] = y[b, :, :].dot(np.linalg.inv(Cr).T).dot(
                X.conj()).dot(C.T)

        return hest
Ejemplo n.º 8
0
    def omp_genie_mse(self, y, h, A=None):
        if A is None:
            #A = np.eye(h.shape[-1])
            A = pilot_matrix(self.n_pilots, self.n_antennas_BS,
                             self.n_antennas_MS)
        n_batches, n_coherence, n_antennas = h.shape

        D = self._dft_matrix(self.n_antennas_BS,
                             4 * self.n_antennas_BS)  # dictionary
        #Aeff = A.dot(D) # effective sensing matrix
        D_mimo = np.kron(np.eye(self.n_antennas_MS), D)
        Aeff = A @ D_mimo  # effective sensing matrix
        hest = np.zeros(h.shape, dtype=np.complex)

        for b in range(n_batches):
            evaluate_cost = lambda xhat: np.sum(
                np.abs(h[b, :, :].T - D_mimo.dot(xhat))**2
            )  # cost measured in "channel space"
            #hest[b, :,:] = D.dot(self._omp_genie(Aeff,y[b, :, :].T, evaluate_cost)[0]).T
            hest[b, :, :] = (D_mimo @ self._omp_genie(Aeff, y[b, :, :].T,
                                                      evaluate_cost)[0]).T

        return hest
Ejemplo n.º 9
0
            def func(a):
                import tensorflow as tf
                if a.dtype not in [tf.complex64, tf.complex128]:
                    a = tf.cast(a, dtype=complexx(K.floatx()))
                X = K.constant(pilot_matrix(n_pilots, n_antennas_BS, n_antennas_MS),dtype=complexx(K.floatx()))
                #a = tf.matmul(a , X)
                #X = tf.transpose(X, conjugate=True)
                X = tf.math.conj(X)
                a = tf.matmul(a, X)
                #a = tf.scan(lambda _, x: tf.matmul(x, X), a)
                #a = tf.matmul(X,a)
                #a = tf.reshape(a, [-1, tf.shape(a)[2]])
                #a = tf.matmul(a, X)
                #a = tf.reshape(a, [-1, tf.shape(a)[1], tf.shape(X)[1])

                a_shape = tf.shape(a)
                a = tf.reshape(a, shape=(-1, tf.shape(a)[1], n_antennas_MS, n_antennas_BS), name='a')
                a = tf.transpose(a, perm=[0,1,3,2])

                fft = tf.signal.fft2d(a) / tf.sqrt(tf.cast(a_shape[-1],a.dtype))

                fft = tf.transpose(fft,perm=[0,1,3,2])
                fft = tf.reshape(fft, shape=(-1,tf.shape(fft)[1],n_antennas_BS*n_antennas_MS))
                return fft