This repository was archived by the owner on Sep 27, 2024. It is now read-only.
forked from hadizand/DL_CS_ECG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest0.py
More file actions
52 lines (38 loc) · 1.17 KB
/
test0.py
File metadata and controls
52 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Tests:
# 1. sparseSignal
import matplotlib.pyplot as plt
import numpy as np
from sparseSignalGenerator import sparseSignal
from sparseDictionaries import generate_DCT_dictionary
from measurementMatrix import generate_DBDD_matrix
from SL0 import SL0
from evaluation import plot_signals
# TO test let's do a compressive sensing without blocks (whole signal)
DIM = 2 ** 10
K = int(DIM * 0.34)
# Generate sparse Signal
signal, active_indices = sparseSignal(DIM, K=K, sigma_inactive=0., sigma_active=0., fixedActiveValue=1)
plt.title("Sparse signal")
plt.plot(signal)
plt.show()
# Find "non sparse" representation of signal
Dict_DCT = generate_DCT_dictionary(DIM)
x = Dict_DCT @ signal
plt.title("Non sparse signal")
plt.plot(x)
plt.show()
# Generate measurement matrix
CR = 1/4 # Compression ratio
DIM_comp = int(DIM * CR)
Phi = generate_DBDD_matrix(DIM_comp, DIM)
# Compress signal
y = Phi @ x
# Reconstruct signal
sigma_min = 0.001
s_d_f = 0.5
mu = 2
l = 3
Phi_pinv = np.linalg.pinv(Phi)
s_hat = SL0(y, Phi, sigma_min=sigma_min, sigma_decrease_factor=s_d_f, mu_0=mu, L=l, A_pinv=Phi_pinv, showProgress=True)
# evaluation
plot_signals(signal, s_hat, "Original", "After processing")