Advertisement
Guest User

Untitled

a guest
Nov 29th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.82 KB | None | 0 0
  1. A = 2; %Амплитуда
  2. T = 6; %Период
  3. tau = 5; %Длительность сигнала
  4. N = 10; %Число ненулевых гармоник
  5. t = -T:0.1 :T;% вектор моментов времени
  6. subpl_row = 6;
  7. subpl_colums = 3;
  8. Fs = 100;
  9. L = 150;    
  10.  
  11. %Последовательность прямоугольных импульсов
  12. q = T/tau;
  13. sum = A/q;
  14. for k = 1:N
  15.     figure(1)
  16.     subplot(subpl_row, subpl_colums, k);
  17.     S = (2*A/(pi*k))*sin(pi*k/q)*cos(((2*pi*k)/T)*t);
  18.     sum = sum + S;
  19.     plot(t, sum);
  20.    
  21.     figure(2)
  22.     subplot(subpl_row, subpl_colums, k)
  23.     Y = fft(sum);
  24.     P2 = abs(Y/L);
  25.     P1 = P2(1:L/2+1);
  26.     P1(2:end-1) = 2*P1(2:end-1);
  27.  
  28.     f = Fs*(0:(L/2))/L;
  29.     plot(f,P1)
  30.     title('Spectrum of S(t)')
  31.     xlabel('f (Hz)')
  32.     ylabel('|P1(f)|')
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement