Advertisement
Guest User

Untitled

a guest
Jul 13th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.73 KB | None | 0 0
  1. %% Init.
  2. clear all;
  3. clf;
  4. hold all;
  5. %% Data Gen
  6. for O=1:8
  7.     N           =   O*10^3;
  8.     B           =   gausswin(N);        %arbitrary data
  9.     k           =   100*chebwin(N);     %arbitrary data
  10.     x{O}        =   linspace(-1,1,N);   %arbitrary data
  11.    
  12.     %initialize
  13.     I{O}           =   zeros(1,N);
  14.    
  15.     %sum the cosines
  16.     tic
  17.     for ai  = 1:N
  18.         I{O}       =   I{O}    + B(ai)*cos(k(ai)*x{O});
  19.     end
  20.     plot(x{O},I{O});
  21. end
  22. save reddit x I;
  23. %% Analysis.
  24. clear all;
  25. load reddit;
  26. close all;
  27. figure(1);hold all
  28. In=1;
  29. Out=2;
  30. plot(x{Out},I{Out}./spline(x{In},I{In},x{Out}),x{Out},I{Out}./interp1(x{In},I{In},x{Out}));
  31.  
  32. In=1;
  33. Out=3;
  34. plot(x{Out},I{Out}./spline(x{In},I{In},x{Out}),x{Out},I{Out}./interp1(x{In},I{In},x{Out}));
  35.  
  36. In=2;
  37. Out=3;
  38. plot(x{Out},I{Out}./spline(x{In},I{In},x{Out}),x{Out},I{Out}./interp1(x{In},I{In},x{Out}));
  39.  
  40. %%
  41. close all;
  42. n=2;
  43. for i=[1 3:8]
  44.     figure(i);
  45.     S=i./n; % Scaling factor.
  46.    
  47.    
  48.     %         Resampling. Taking 'i' points and matching to 'n' points.
  49.     Rs=spline(x{n},I{n}.*S,x{i}); % Resample  spline.
  50.     Ri=interp1(x{n},I{n}.*S,x{i}); % Resample interp1
  51.     subplot(2,1,1);
  52.     plot(x{n},I{n}.*S,x{i},Rs,x{i},Ri,x{i},I{i}); hold all;
  53.     legend(sprintf('Data %d scaled',n),sprintf('Data %d Spline Fit',n),sprintf('Data %d Interp1 Fit',n),sprintf('Data %d',i));
  54.    
  55.     Ares=abs(Rs-I{i}); % Absolute resample error spline
  56.     Arei=abs(Ri-I{i}); % Absolute resample error interp1
  57.    
  58.     Prea=Ares./I{i}; % Percent ...
  59.     Prei=Arei./I{i};
  60.    
  61.     SSEs=sqrt(sum(Ares.^2));
  62.     SSEi=sqrt(sum(Arei.^2));
  63.    
  64.     subplot(2,1,2);
  65.     plot(x{i},Ares,x{i},Arei);
  66.     legend(sprintf('Spline SSE=%f',SSEs),sprintf('Interp1 SSE=%f',SSEi));
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement