Advertisement
makispaiktis

FFT1 - TD and FD plots when duration=kT - Sharp spikes

Jul 9th, 2023 (edited)
1,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.31 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. %% A1. Basics
  6. Fs = 500;                   % Sampling Frequency   [Hz]
  7. duration = 2;               % Signal time duration [sec]
  8. Ts = 1 / Fs;                % Sampling period      [sec]
  9.  
  10. t = 0 : Ts : duration - Ts;
  11. N = length(t);              % Num of samples
  12.    
  13.  
  14. %% A2. Signal parameters
  15. A1 = 3;     f1 = 30;    phase1 = 0.6;
  16. A2 = 2;     f2 = 45;    phase2 = -0.8;
  17. A3 = 1;     f3 = 70;    phase3 = 2;
  18.  
  19. s1 = A1*cos(2*pi*f1*t + phase1);
  20. s2 = A2*cos(2*pi*f2*t + phase2);
  21. s3 = A3*cos(2*pi*f3*t + phase3);
  22. s = s1 + s2 + s3;
  23.  
  24.  
  25. %% A3. Plotting in time-domain
  26. figure();
  27. plot(t, s);
  28. xlabel('Time [sec]');
  29. ylabel('Amplitude');
  30. title('Time-domain plot');
  31.  
  32.  
  33. %% A4. Fast Fourier Transform - Samples
  34. S = fft(s);                     % Also 'N' samples
  35. figure();
  36. plot(abs(S));
  37. xlabel('Samples');
  38. ylabel('Magnitude');
  39. title('Samples-domain plot');
  40.  
  41.  
  42. %% A5. Convert samples into frequencies by keeping the LHS of plot
  43. S_oneside = S(1 : N/2);
  44. f = Fs * (0 : N/2 - 1) / N;
  45. S_meg = abs(S_oneside) / (N/2);
  46.  
  47. figure();
  48. plot(f, S_meg);
  49. xlabel('Frequency [Hz]');
  50. ylabel('Amplitude');
  51. title('Frequency-domain plot (Sharp Spikes)');
  52.  
  53.  
  54. %% A6. Discover the sinus phases
  55. ph1 = angle(S_oneside(f1*duration+1))
  56. ph2 = angle(S_oneside(f2*duration+1))
  57. ph3 = angle(S_oneside(f3*duration+1))
  58.  
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement