Code covered by the BSD License

# pseudo symbolic computation with anonymous functions

### Shalin Mehta (view profile)

20 Sep 2009 (Updated )

Using anonymous functions to compute instantaneous correlation with symbolic-looking code.

instcorrMATLAB.m
```%% See readme.txt for license (BSD).
set(0,'defaultaxesfontsize',18);
set(0,'defaulttextfontsize',18);
%% Define signal.
% sig=cos(10*pi*x.^2);
% Rather than creating the independent and dependent variables, create a
% function handle.
sigh=@(xi) (cos(10*pi*xi.^2).*(0<=xi & xi<=1));
figure(1);
subplot(311);
hplot=plot(linspace(-0.5,1.5,1024),sigh(linspace(-0.5,1.5,1024))); title('Signal');
set(hplot,'LineWidth',2);
%% First, Consider the signalto be a function of x.

x=linspace(-2,2,1024);

for c=-1:0.1:1
figure(2); %Just to show the animate.
plot(x,sigh(x+c/2),'b--',x,sigh(x-c/2),'g--',x,sigh(x+c/2).*sigh(x-c/2),'r');
legend({'Early','Late','Icorr'},'Location','West');
title(['c=' num2str(c)]);
pause(0.1);
if(c==0.5)
figure(1);
subplot(312);
hplot=plot(x,sigh(x+c/2),'b--',x,sigh(x-c/2),'g--',x,sigh(x+c/2).*sigh(x-c/2),'r');
title(['Signal assumed a function of x: c=' num2str(c)]);
legend({'Early','Late','Icorr'},'Location','West');
end
end
set(hplot,'LineWidth',2);
%% Consider the signalto be a function of c.
c=linspace(-2,2,1024);

for x=0:0.1:1
figure(2);
plot(c,sigh(x+c/2),'b--',c,sigh(x-c/2),'g--',c,sigh(x+c/2).*sigh(x-c/2),'r');
legend({'Early','Late','Icorr'},'Location','West');
title(['x=' num2str(x)]);
pause(0.1);
if(x==0.5)
figure(1);
subplot(313);
hplot=plot(c,sigh(x+c/2),'b--',c,sigh(x-c/2),'g--',c,sigh(x+c/2).*sigh(x-c/2),'r');
title(['Signal assumed a function of c: x=' num2str(x)]);
legend({'Early','Late','Icorr'},'Location','West');
end
end
set(hplot,'LineWidth',2);
%% Print the combined figure.
print('-f1','-dpng','icorrmatlab.png');

```