This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Absolute value (magnitude)


abs is a MATLAB® function.


collapse all

Generate a signal composed of two sinusoids sampled at 100 Hz. Specify the sinusoid frequencies as 15 and 40 Hz. Compute the DFT of the sequence.

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
ylabel 'DFT magnitude'
xlabel 'Frequency (Hz)'

Introduced before R2006a

Was this topic helpful?