library(pracma) # library(SynchWave) # Importing the libraries for (f in list.files(path="nt_toolbox/toolbox_general/", pattern="*.R")) { source(paste("nt_toolbox/toolbox_general/", f, sep="")) } for (f in list.files(path="nt_toolbox/toolbox_signal/", pattern="*.R")) { source(paste("nt_toolbox/toolbox_signal/", f, sep="")) } for (f in list.files(path="nt_toolbox/toolbox_graph/", pattern="*.R")) { source(paste("nt_toolbox/toolbox_graph/", f, sep="")) } N = 1024 s = 5 t = c(-(N/2) : ((N/2) - 1)) h = (1-t**2/s**2)*exp(-(t**2)/(2*s**2)) h = h - mean(h) fftshift = SynchWave::fftshift h1 = fftshift(h) # Recenter the filter for fft use. Phi = function (u) {Re(ifft(fft(h1) * fft(c(u))))} # Fourier transform (normalized) hf = Re(pracma::fftshift(fft(h1))) / sqrt(N) options(repr.plot.width=5, repr.plot.height=3.5) q = 200 plot(t, h, type="l", main="Filter, Spacial (zoom)", col="blue", xlim=c(-200,200), ylab="") plot(t, hf, type="l", main="Filter, Fourrier (zoom)", col="blue", xlim=c(-200,200), ylab="") s = round(N * 0.03) set.seed(1) sel = sample(c(1 : N)) sel = sel[0:s] x0 = zeros(1, N) x0[sel] = 1. x0 = x0 * sign(randn(1, N)) * (1 - .3 * rand(1, N)) sigma = 0.06 y = Phi(x0) + sigma * randn(1, N) stemplot(x0, col="blue", ylab="", xlab="", main="Signal") plot(c(1:N), y, xlab="", ylab="", col="blue", main="Measurements y", type="l") Lambda = 1. proxg = function(x, gamma, Lambda) {x * pmax(1 - ((Lambda * gamma) / abs(x)), 0)} source("nt_solutions/optim_2_condat_fb/exo1.R") # Insert your code here. L = max(abs(fft(h)))**2 gamma = 1.95 / L source("nt_solutions/optim_2_condat_fb/exo2.R") # Insert code here. # Insert code here. # Insert code here. gamma = 1 / L source("nt_solutions/optim_2_condat_fb/exo3.R") # Insert code here. source("nt_solutions/optim_2_condat_fb/exo4.R") # Insert code here.