%% Magnitude of Discrete Fourier Transform
% Compute the discrete Fourier transform (DFT) of a signal composed of two sinusoids sampled at 100 Hz with frequencies of 15 and 40 Hz. Use the abs function to compute the magnitude of the DFT.

t = (0:99)/100;                        % Time vector
x = sin(2*pi*15*t) + sin(2*pi*40*t);   % Signal
y = fft(x);                            % DFT of x
m = abs(y);                            % Magnitude

% Plot the magnitude of the DFT.

f = 0:50;                              % Frequency vector
m = m(1:51);                           % Unique magnitudes
stem(f,m)
ylabel 'DFT magnitude'
xlabel 'Frequency (Hz)'

% Copyright 2018 The MathWorks, Inc.