title: implement low pass filter in matlab
body: <p>I want to implement a filter that eliminates higher frequencies. In this example I want to eliminate the sin curve and keep the linear curve.</p>
  
  <p>EDIT:</p>
  
  <p>I corrected my code, however the function that I implemented for filtering changes the edges of the data significantly which is not acceptable.</p>
  
  <pre><code>clc; clear all;
  xaxis = linspace(1, 10, 1000);
  data = xaxis + sin(xaxis*3);
  Nf = 2^12;
  xAxisf = linspace(-10,10,Nf);
  % plot(xaxis, data);
  
  % FFT
  
  xsize = numel(data);    
  Xf = zeros([1 Nf]);
  indices = Nf/2-floor(xsize/2):Nf/2-floor(xsize/2)+xsize - 1;
  Xf(indices) = data;
  
  % Xf = fftshift(Xf);
  Xf = fft(Xf);
  Xf = fftshift(Xf);
  
  % plot 
  Xfa = abs(Xf); plot(xAxisf, Xfa);
  
  % generate super-gaussian filter function
  Nf = numel(Xf);    
  widthfilter = 0.12;
  filterpower = 2;
  filter = exp(-(xAxisf.^2./widthfilter^2).^filterpower);
  
  % filter
  filtertimes = 20;
  Xf = Xf .* filter.^filtertimes;
  
  % plot 
  Xfa = abs(Xf); plot(Xfa);
  
  % iFFt
  Xfs = ifftshift(Xf);
  Xif = ifft(Xfs);
  % Xif = ifftshift(Xif);
  result = abs(Xif);
  
  plot(result(indices))
  </code></pre>