Facebook
From Baby Lemur, 1 Year ago, written in Plain Text.
This paste is a reply to Untitled from Tacky Curlew - view diff
Embed
Download Paste or View Raw
Hits: 170
  1. clear all
  2. close all
  3.  
  4. f0=250;
  5. f1=500;
  6. fs = 2000;
  7. Nf = 50
  8.  
  9. M = Nf;
  10. nx = 0:M-1;
  11. dt = 1/fs;
  12. t = dt*nx;
  13.  
  14. h = fir1(Nf, ((f0+f1)/2)  /  (2*fs));
  15. x = cos(2*pi*f0*t) + cos(2*pi*f1*t);
  16. tic;
  17. y1 = conv(h, x);
  18. toc;
  19.  
  20.  
  21.  
  22. tic;
  23. xp = [x zeros(1, Nf-1)];
  24. L=ceil(log2(length(xp)));
  25. xp=[xp zeros(1, 2^L-length(xp))];
  26.  
  27. bp=[h zeros(1, M-1)];
  28. bp=[bp zeros(1,2^L-length(bp))];
  29.  
  30. Xp=myFFT(xp');
  31. Bp=myFFT(bp');
  32. Y=Xp.*Bp;
  33. y3=real(ifft(Y));
  34. toc;
  35. plot(1:500, y1(1:500), 1:1024, y3(1:1024));
  36. title('Splot');
  37. xlabel('Pr├│bki');
  38. ylabel('Warto┼Ť─ç splotu');
  39. legend('Splot z funkcji conv', 'Splot przy pomocy myFFT', 'Location', 'se');
  40.  
  41.  
  42. figure(2)
  43. plot(20*log10(abs(fft(y3))));
  44. title('Widmo sygna┼éu wyj┼Ťciowego')
  45. xlabel('Pr├│bki')
  46.