# גרפים

(הבדל) → הגרסה הקודמת | הגרסה האחרונה (הבדל) | הגרסה הבאה ← (הבדל)
קפיצה אל: ניווט, חיפוש

# גרף הדגמת FFT ו-THD

1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2. %%% FFT with THD example                                        %%%
3. %%% based on https://www.mathworks.com/help/matlab/ref/fft.html %%%
4. %%% with a few modifications                                    %%%
5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6. Fs = 1000; % Sampling frequency
7. T = 1/Fs; % Sampling period
8. L = 300; % Length of signal
9. t = (0:L-1)*T; % Time vector
10. freq = 50; % frequency
11. S1 = 5*sin(2*pi*freq*t); % 1st (base) harmony
12. S2 = 2*sin(2*pi*3*freq*t); % 2nd harmony distortion
13. S = S1 + S2;
14. f = Fs*(0:(L/2))/L;
15. Y = fft(S);
16. P2 = abs(Y/L);
17. P1 = P2(1:L/2+1);
18. P1(2:end-1) = 2*P1(2:end-1);
19. 
20. figure('Name','THD example');
21. subplot(311);
22. plot(t,S1,t,S2);
23. title('Two pure sine waves');
24. ylabel('Amplitude [V]');
25. xlabel('Time [S]');
26. legend(['1st harmony: ',num2str(freq),' Hz'],['2nd harmony: ',num2str(3*freq),' Hz']);
27. subplot(312);
28. plot(t,S);
29. title(['Addition of the above two sine waves with frequencies of ',num2str(freq),' and ',num2str(3*freq),' Hz']);
30. ylabel('Amplitude [V]');
31. xlabel('Time [S]');
32. subplot(313);
33. plot(f,P1);
34. title('Single-Sided Amplitude Spectrum of 1st (base) harmony + 2nd harmony');
35. xlabel('f (Hz)');
36. ylabel('Amplitude [V]');
37. 
38. set(gcf, 'Position', [600, 80, 800, 900]);