Error when calling function
Afficher commentaires plus anciens
Im trying to calculate the 'Zero Crossings' in a sample signal with the below code.
When I try calling the function in the command window using 'zc = ZeroCrossing(t,emg6);' i get an error that says "Attempt to execute SCRIPT ZeroCrossing as a function."
I'd be grateful if someone can shed some insight on this.
Fs=200;
samples=0:2186; %number of data points in matrix
t = samples/Fs; % Time Vector (seconds)
t(:,[1]) = [];
function zc_idx = ZeroCrossing(t,emg6)
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0);
zx = zci(emg6);
zc_idx = zeros(numel(zx),1); % initialise the zero crossing indices
for i = 1:numel(zx)
idx = max([1 zx(i)-1]):min([zx(i)+1 numel(emg6)]);
x_range = t(idx);
y_range = emg6(idx);
zc_idx(i) = interp1( y_range(:), x_range(:), 0, 'linear', 'extrap' ); % returns the approximate zero crossing Indices of argument vector
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Descriptive Statistics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!