Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Init.
- clear all;
- clf;
- hold all;
- %% Data Gen
- for O=1:8
- N = O*10^3;
- B = gausswin(N); %arbitrary data
- k = 100*chebwin(N); %arbitrary data
- x{O} = linspace(-1,1,N); %arbitrary data
- %initialize
- I{O} = zeros(1,N);
- %sum the cosines
- tic
- for ai = 1:N
- I{O} = I{O} + B(ai)*cos(k(ai)*x{O});
- end
- plot(x{O},I{O});
- end
- save reddit x I;
- %% Analysis.
- clear all;
- load reddit;
- close all;
- figure(1);hold all
- In=1;
- Out=2;
- plot(x{Out},I{Out}./spline(x{In},I{In},x{Out}),x{Out},I{Out}./interp1(x{In},I{In},x{Out}));
- In=1;
- Out=3;
- plot(x{Out},I{Out}./spline(x{In},I{In},x{Out}),x{Out},I{Out}./interp1(x{In},I{In},x{Out}));
- In=2;
- Out=3;
- plot(x{Out},I{Out}./spline(x{In},I{In},x{Out}),x{Out},I{Out}./interp1(x{In},I{In},x{Out}));
- %%
- close all;
- n=2;
- for i=[1 3:8]
- figure(i);
- S=i./n; % Scaling factor.
- % Resampling. Taking 'i' points and matching to 'n' points.
- Rs=spline(x{n},I{n}.*S,x{i}); % Resample spline.
- Ri=interp1(x{n},I{n}.*S,x{i}); % Resample interp1
- subplot(2,1,1);
- plot(x{n},I{n}.*S,x{i},Rs,x{i},Ri,x{i},I{i}); hold all;
- legend(sprintf('Data %d scaled',n),sprintf('Data %d Spline Fit',n),sprintf('Data %d Interp1 Fit',n),sprintf('Data %d',i));
- Ares=abs(Rs-I{i}); % Absolute resample error spline
- Arei=abs(Ri-I{i}); % Absolute resample error interp1
- Prea=Ares./I{i}; % Percent ...
- Prei=Arei./I{i};
- SSEs=sqrt(sum(Ares.^2));
- SSEi=sqrt(sum(Arei.^2));
- subplot(2,1,2);
- plot(x{i},Ares,x{i},Arei);
- legend(sprintf('Spline SSE=%f',SSEs),sprintf('Interp1 SSE=%f',SSEi));
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement