Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [] = dft()
- % 1 sin-wave 10Hz, amp 15, phase angle -pi/4
- % 1 sin-wave 30Hz, amp 20
- % 1 sin-wave 70Hz, amp 35, phase angle 3pi/4
- Fs = 1000; % samples per second
- dT = 1/Fs; % seconds per sample
- stopTime = 0.2;
- t = (0:dT:stopTime-dT)';
- Fc1 = 10;
- Fc2 = 30;
- Fc3 = 70;
- amp1 = 15;
- amp2 = 20;
- amp3 = 35;
- phaseAngle1 = (-pi / 4);
- phaseAngle3 = ((3 * pi) / 4);
- y1 = amp1 * sin(2 * pi * Fc1 * t + phaseAngle1);
- y2 = amp2 * sin(2 * pi * Fc2 * t);
- y3 = amp3 * sin(2 * pi * Fc3 * t + phaseAngle3);
- % figure;
- % plot(t,y1);
- % xlabel('Time (s)');
- % title('First wave vs time');
- %
- % figure;
- % plot(t,y2);
- % xlabel('Time (s)');
- % title('Second wave vs time');
- %
- % figure;
- % plot(t,y3);
- % xlabel('Time (s)');
- % title('Third wave vs time');
- S = y1 + y2 + y3;
- figure;
- plot(t,S);
- xlabel('Time (s)');
- ylabel('Amplitude');
- title('Input wave vs time');
- S_fft = fft(S);
- for i = 1:length(S_fft)
- if (abs(S_fft(i)) < (10 ^ (-5)))
- S_fft(i) = 0;
- end
- end
- freq = ((0:length(S_fft)-1) * Fs) / length(S_fft);
- figure;
- plot(freq,abs(S_fft));
- xlabel('Frequency (Hz)');
- ylabel('Magnitude');
- title('FFT magnitude');
- figure;
- plot(freq,angle(S_fft));
- xlabel('Frequency (Hz)');
- ylabel('Phase');
- title('FFT phase');
- zoom xon;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement