Why am I getting an error 'Execution of script cosamp as a function is not supported'

10 vues (au cours des 30 derniers jours)
%% Generate signal, DCT of signal
n = 4096; % points in high resolution signal
t = linspace(0, 1, n);
x = cos(2* 97 * pi * t) + cos(2* 777 * pi * t);
xt = fft(x); % Fourier transformed signal
PSD = xt.*conj(xt)/n; % Power spectral density
% Randomly sample signal
p = 128; % num. random samples, p=n/32
perm = round(rand(p, 1) * n);
y = x(perm); % compressed measurement
% Solve compressed sensing problem
Psi = dct(eye(n, n)); % build Psi
Theta = Psi(perm, :); % Measure rows of Psi
s = cosamp(Theta,y,10,1.e-10,10); % CS via matching pursuit
xrecon = idct(s); % reconstruct full signal
  2 commentaires
Sabian Hibbs
Sabian Hibbs le 1 Nov 2021
Cosamp has been added to my matlab suit
Chris
Chris le 1 Nov 2021
What is cosamp? If it's a FileExchange function, are you capitalizing letters appropriately? If it's something you made, is it a function that accepts inputs and returns an output?

Connectez-vous pour commenter.

Réponses (2)

Elghandouri Mohammed
Elghandouri Mohammed le 25 Jan 2022
Hi.
Please, have you solved this problem or not? I have the same problem, I don’t know how I can solve it.
Thank you.
  3 commentaires
Elghandouri Mohammed
Elghandouri Mohammed le 25 Jan 2022
You can copy the code below in your script and saved it like a function under the name 'cosamp'
%%
function Sest = cosamp(Phi,u,K,tol,maxiterations)
% Cosamp algorithm
% Input
% K : sparsity of Sest
% Phi : measurement matrix
% u: measured vector
% tol : tolerance for approximation between successive solutions.
% Output
% Sest: Solution found by the algorithm
%
% Algorithm as described in "CoSaMP: Iterative signal recovery from
% incomplete and inaccurate samples" by Deanna Needell and Joel Tropp.
%
% This implementation was written by David Mary,
% but modified 20110707 by Bob L. Sturm to make it much clearer,
% and corrected multiple times again and again.
% To begin with, see: http://media.aau.dk/null_space_pursuits/2011/07/ ...
% algorithm-power-hour-compressive-sampling-matching-pursuit-cosamp.html
%
% This script/program is released under the Commons Creative Licence
% with Attribution Non-commercial Share Alike (by-nc-sa)
% http://creativecommons.org/licenses/by-nc-sa/3.0/
% Short Disclaimer: this script is for educational purpose only.
% Longer Disclaimer see http://igorcarron.googlepages.com/disclaimer
% Initialization
Sest = zeros(size(Phi,2),1);
v = u;
t = 1;
numericalprecision = 1e-12;
T = [];
while (t <= maxiterations) && (norm(v)/norm(u) > tol)
y = abs(Phi'*v);
[vals,z] = sort(y,'descend');
Omega = find(y >= vals(2*K) & y > numericalprecision);
T = union(Omega,T);
b = pinv(Phi(:,T))*u;
[vals,z] = sort(abs(b),'descend');
Kgoodindices = (abs(b) >= vals(K) & abs(b) > numericalprecision);
T = T(Kgoodindices);
Sest = zeros(size(Phi,2),1);
b = b(Kgoodindices);
Sest(T) = b;
v = u - Phi(:,T)*b;
t = t+1;
end;
Elghandouri Mohammed
Elghandouri Mohammed le 25 Jan 2022
You should verify the dimension of your matrix theta and the vector y.
May be you have also another script called cosamp.m somewhere in your Matlab path, which Matlab is attempting to run, then you should rename this script or move it.

Connectez-vous pour commenter.


Chris
Chris le 25 Jan 2022
Modifié(e) : Chris le 25 Jan 2022
Using the function provided by @Elghandouri Mohammed and the original script, the error I get is:
Error using _*_
Incorrect dimensions for matrix multiplication. ...
That can be remedied by transposing y, so that its dimensions correlate with Theta's dimensions:
s = cosamp(Theta,y',10,1.e-10,10);
If you are still getting 'Execution of script cosamp as a function is not supported'
Then there is a script called cosamp.m somewhere in your Matlab path, which Matlab is attempting to run.
type which cosamp in the Matlab Command Window to locate it, and rename it or remove it from Matlab's path.
  1 commentaire
Elghandouri Mohammed
Elghandouri Mohammed le 25 Jan 2022
Modifié(e) : Elghandouri Mohammed le 25 Jan 2022
The function is working good for me, maybe you should close your Matlab map and open it again.
You should also save the function cosmap.m in the folder where your script program is saved, and remove the old function named cosmap.m

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Signal Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by