Facebook
From dsad, 9 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 751
  1. function y = conv(x, p, q)
  2. f = fft(x);
  3.  
  4. % --- resize in the FFT domain ---
  5. % add/remove the highest frequency components such that len(f) = len2
  6. len1 = length(f);
  7. len2 = round(len1*p/q);
  8. lby2 = 1+len1/2;
  9. if len2 < len1
  10.   % remove some high frequency samples
  11.   d = len1-len2;
  12.   f = f(:);
  13.   f(floor(lby2-(d-1)/2:lby2+(d-1)/2)) = [];
  14. elseif len2 > len1
  15.   % add some high frequency zero samples
  16.   d = len2-len1;
  17.   lby2 = floor(lby2);
  18.   f = f(:);
  19.   f = [f(1:lby2); zeros(d,1); f(lby2+1:end)];
  20. end
  21.  
  22.  
  23.  
  24. end