Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs = 20;
- Ts = 1/fs
- L = 10- Ts;
- t = 0:Ts:L;
- f = zeros(1,200);
- f(1:100) = 2;
- f(101:200) = 5;
- signal = sin(2*pi*f.*t);
- N = length(signal);
- X_mags = abs(fftshift(fft(signal)));
- bin_vals = [0 : N-1];
- N_2 = ceil(N/2);
- fax_Hz = (bin_vals-N_2)*fs/N;
- subplot(2,1,1)
- plot(fax_Hz, X_mags)
- xlabel('Frequency (Hz)')
- ylabel('Magnitude');
- title('Double-sided Magnitude spectrum (Hertz)');
- axis tight
- subplot(2,1,2)
- plot(t,signal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement