Advertisement
Guest User

Matlab FFT Code

a guest
Dec 24th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. close all;
  2. clear all;
  3. clc;
  4. ct = 1;
  5. for i = 0.030:.00400000000000000000:0.150
  6. format = '%#0.3f\n';
  7. str = num2str(i, format);
  8. modstr = str(2:end);
  9. ez = h5read(sprintf('hsli%s.h5',modstr),'/ez');
  10. N = length(ez);
  11. res = 5; % Samples per unit length
  12. dx = 1/res; % Length increment per sample
  13. x = (0:N-1) * dx; % Position vector
  14. NFFT = 2^nextpow2(N); % Next power of 2 from length of y
  15. Y = fft(ez,NFFT) / (N * max(ez));
  16. kfft = res / 2 * linspace(0, 1, NFFT / 2 + 1);
  17. ABSY = 2 * abs(Y(1:NFFT / 2 + 1));
  18. % plot(kfft, ABSY);
  19. title('Amplitute Spectrum', 'fontweight', 'bold');
  20. xlabel('Wavevector(k)', 'fontweight', 'bold');
  21. ylabel('|Y(f)|', 'fontweight', 'bold');
  22. ind(ct,1) = find(ABSY == max(ABSY));
  23. k(ct,1) = kfft(ind(ct,1));
  24. w(ct,1) = i;
  25. ct = ct + 1;
  26. end
  27. plot(w, k * 2 * pi, '-r', 'linewidth', 3);
  28. title('Dispersion Graph', 'fontweight', 'bold');
  29. xlabel('Wavevector(k)', 'fontweight', 'bold');
  30. ylabel('Angular Frequency(w)', 'fontweight', 'bold');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement