Advertisement
makispaiktis

FFT2 - FD plot when duration!=kT - Spectral spread

Jul 9th, 2023 (edited)
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.21 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. %% B1. Change duration
  6. % New duration != integer number of signal cycles
  7.  
  8. Fs = 500;                   % Sampling Frequency   [Hz]
  9. duration = 0.64;            % Signal time duration [sec]
  10. Ts = 1 / Fs;                % Sampling period      [sec]
  11. t = 0 : Ts : duration - Ts;
  12. N = length(t);              % Num of samples
  13.    
  14.  
  15. %% B2. Signal parameters
  16. A1 = 3;     f1 = 30;    phase1 = 0.6;
  17. A2 = 2;     f2 = 45;    phase2 = -0.8;
  18. A3 = 1;     f3 = 70;    phase3 = 2;
  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. %% B3. 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. %% B4. 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. %% B5. 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. figure();
  47. plot(f, S_meg);
  48. xlabel('Frequency [Hz]');
  49. ylabel('Amplitude');
  50. title('Frequency-domain plot (Spectral Spread)');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement