Example #1
0
 def test_09(self):
     rho = 1e-1
     N = 32
     M = 16
     K = 8
     D = complex_randn(N, N, 1, 1, M)
     X = complex_randn(N, N, 1, K, M)
     S = np.sum(D*X, axis=4, keepdims=True)
     Z = (D.conj()*np.sum(D*X, axis=4, keepdims=True) + \
          rho*X - D.conj()*S) / rho
     Xslv = linalg.solvedbi_sm(D, rho, D.conj()*S + rho*Z)
     assert linalg.rrs(D.conj()*np.sum(D*Xslv, axis=4, keepdims=True) +
                       rho*Xslv, D.conj()*S + rho*Z) < 1e-11
Example #2
0
    def test_15(self):
        rho = 1e-1
        N = 32
        M = 16
        K = 8
        D = complex_randn(N, N, 1, 1, M)
        X = complex_randn(N, N, 1, K, M)
        S = np.sum(D*X, axis=4, keepdims=True)

        Xop = lambda x: np.sum(X * x, axis=4, keepdims=True)
        XHop = lambda x: np.sum(np.conj(X) * x, axis=3, keepdims=True)
        Z = (XHop(Xop(D)) + rho*D - XHop(S)) / rho
        Dslv, cgit = linalg.solvemdbi_cg(X, rho, XHop(S)+rho*Z, 4, 3, tol=1e-6)
        assert linalg.rrs(XHop(Xop(Dslv)) + rho*Dslv, XHop(S) + rho*Z) <= 1e-6
Example #3
0
 def test_10(self):
     N = 32
     M = 16
     K = 8
     D = complex_randn(N, N, 1, 1, M)
     X = complex_randn(N, N, 1, K, M)
     S = np.sum(D*X, axis=4, keepdims=True)
     d = 1e-1 * (np.random.randn(N, N, 1, 1, M).astype('complex') +
         np.random.randn(N, N, 1, 1, M).astype('complex') * 1.0j)
     Z = (D.conj()*np.sum(D*X, axis=4, keepdims=True) +
          d*X - D.conj()*S) / d
     Xslv = linalg.solvedbd_sm(D, d, D.conj()*S + d*Z)
     assert linalg.rrs(D.conj()*np.sum(D*Xslv, axis=4, keepdims=True) +
                       d*Xslv, D.conj()*S + d*Z) < 1e-11
Example #4
0
    def test_14(self):
        rho = 1e-1
        N = 64
        M = 32
        C = 3
        K = 8
        D = complex_randn(N, N, C, 1, M)
        X = complex_randn(N, N, 1, K, M)
        S = np.sum(D*X, axis=4, keepdims=True)

        Xop = lambda x: np.sum(X * x, axis=4, keepdims=True)
        XHop = lambda x: np.sum(np.conj(X) * x, axis=3, keepdims=True)
        Z = (XHop(Xop(D)) + rho*D - XHop(S)) / rho
        Dslv = linalg.solvemdbi_rsm(X, rho, XHop(S) + rho*Z, 3)
        assert linalg.rrs(XHop(Xop(Dslv)) + rho*Dslv, XHop(S) + rho*Z) < 1e-11
Example #5
0
t = np.linspace(-2, 2, N, endpoint=False)

#the first element is the length of signal, the fourth one is how

s_noise = np.zeros((N,K), dtype=complex)
s_clean = np.zeros((N,K), dtype=complex)
Dtemp = np.zeros((N,K), dtype=complex)

# delta matrix to shift the Gaussian pulses
delta = np.zeros((N, K), dtype=complex)

# construct sine/cosine signal
for i in range(K):

    sigma = 0.05  # noise level
    noise = sigma * si.complex_randn(N)
    delta[np.random.randint(0, 32), i] = 1

    real,imag,e = signal.gausspulse(t, 5, retquad=True, retenv=True)
    temp = real + complex(0, 1) * imag
    temp = np.convolve(temp,delta[:,i],'same')

    s_clean[:,i] = temp
    s_noise[:,i] = s_clean[:,i] + noise
    Dtemp[:,i] = s_clean[:,i] + 10*noise

D0 =Dtemp[:,0:M]
# Function computing reconstruction error at lmbda
Maxiter = 400
opt_par = comcbpdn.ComplexConvBPDN.Options({'FastSolve': True, 'Verbose': True, 'StatusHeader': False,
                                            'MaxMainIter': Maxiter,'RelStopTol': 5e-5, 'AuxVarObj': True,
#     onion_complex = pickle.load(f)
#     f.close()

np.seterr(divide='ignore')

N = 128  # signal length

A = 5  # amplitude
M = 10  # filter number
fd = np.linspace(5, 20, M)
fs = 128  # sampling frequency must be higher enough to eliminate cutoff
dimN = 1  # spatial dimension 1

# create a complex gaussian noise using sporco.signal.complex_randn,
# same length as input signal
noise = si.complex_randn(N)

D0 = np.zeros((N, M), dtype=complex)
# construct a complex sine dictionary
for i in range(len(fd)):
    D0[:, i] = sinesignal.generate_sine_wave_no(N, A, fd[i], fs, 0) + \
               complex(0, 1) * sinesignal.generate_sine_wave_no(N, A, fd[i], fs, 0)

lmbda_0 = M * abs(noise.max())

# construct a 5Hz sine signal
s_clean = np.zeros(N)

s_clean = sinesignal.generate_sine_wave_no(N, A, 5, fs, 0) \
          + complex(0, 1) * sinesignal.generate_sine_wave_no(N, A, 5, fs, 0)