Advertisement
makispaiktis

FFT4 - FD plot when duration!=kT after windowing and padding - Spikes

Jul 9th, 2023
1,338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.63 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. %% D1. 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. %% D2. Signal parameters - Windowing BEFORE padding
  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.  
  22. s = s .* hanning(N)';
  23. figure();
  24. plot(t, s);
  25. xlabel('Time [sec]');
  26. ylabel('Amplitude');
  27. title('Time-domain plot - Signal after windowing');
  28.  
  29.  
  30.  
  31.  
  32. %% C3. Plotting in time-domain - Zero-padding signal 's'
  33. s = [s zeros(1, 2000)];
  34. t_extra = duration : Ts : duration + 1999*Ts;
  35. t = [t t_extra];
  36.  
  37. figure();
  38. plot(t, s);
  39. xlabel('Time [sec]');
  40. ylabel('Amplitude');
  41. title('Time-domain plot - Windowing and padding');
  42.  
  43.  
  44. %% C4. Fast Fourier Transform - Samples
  45. S = fft(s);                     % Also 'N' samples
  46. figure();
  47. plot(abs(S));
  48. xlabel('Samples');
  49. ylabel('Magnitude');
  50. title('Samples-domain plot');
  51.  
  52.  
  53. %% C5. Convert samples into frequencies by keeping the LHS of plot
  54. % Side lobes will disappear after having windowed and padded our signal
  55. N2 = length(s);
  56. S_oneside = S(1 : N2/2);
  57. f = Fs * (0 : N2/2 - 1) / N2;
  58. S_meg = abs(S_oneside) / (N2/2);
  59. figure();
  60. plot(f, S_meg);
  61. xlabel('Frequency [Hz]');
  62. ylabel('Amplitude');
  63. title('Frequency-domain plot (Side lobes disappeared with windowing and padding)');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement