Advertisement
makispaiktis

FFT3 - FD plot when duration!=kT with padding - Main and side lobes

Jul 9th, 2023 (edited)
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.35 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. %% C1. New duration != integer number of signal cycles
  6. Fs = 500;                   % Sampling Frequency   [Hz]
  7. duration = 0.64;            % Signal time duration [sec]
  8. Ts = 1 / Fs;                % Sampling period      [sec]
  9. t = 0 : Ts : duration - Ts;
  10. N = length(t);              % Num of samples
  11.    
  12.  
  13. %% C2. Signal parameters - Zero padding signal 's'
  14. A1 = 3;     f1 = 30;    phase1 = 0.6;
  15. A2 = 2;     f2 = 45;    phase2 = -0.8;
  16. A3 = 1;     f3 = 70;    phase3 = 2;
  17. s1 = A1*cos(2*pi*f1*t + phase1);
  18. s2 = A2*cos(2*pi*f2*t + phase2);
  19. s3 = A3*cos(2*pi*f3*t + phase3);
  20. s = s1 + s2 + s3;
  21. s = [s zeros(1, 2000)];
  22. t_extra = duration : Ts : duration + 1999*Ts;
  23. t = [t t_extra];
  24.  
  25. %% C3. Plotting in time-domain
  26. figure();
  27. plot(t, s);
  28. xlabel('Time [sec]');
  29. ylabel('Amplitude');
  30. title('Time-domain plot - After zero-padding');
  31.  
  32.  
  33. %% C4. 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. %% C5. Convert samples into frequencies by keeping the LHS of plot
  43. N2 = length(s);
  44. S_oneside = S(1 : N2/2);
  45. f = Fs * (0 : N2/2 - 1) / N2;
  46. S_meg = abs(S_oneside) / (N2/2);
  47. figure();
  48. plot(f, S_meg);
  49. xlabel('Frequency [Hz]');
  50. ylabel('Amplitude');
  51. title('Frequency-domain plot (Main and side lobes)');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement