# Plot Magnitude of a Sequence in Matlab

Not what you're looking for? Search our solutions OR ask your own Custom question.

Consider a sequence x[n]={1,-1,1,-1}.

Please help in determining how to use the function fft to find the DFT coefficients X[k] of x[n] in Matlab. Also, how would you plot the magnitude of X[k] in Matlab?

https://brainmass.com/engineering/electrical-engineering/plot-magnitude-sequence-matlab-153515

## SOLUTION This solution is **FREE** courtesy of BrainMass!

The DFT in Matlab is done by function fft (see a reference page from Matlab Help in the attached Word file).

The Fourier transform is in general an array of complex numbers, however in the particular case you wrote it just happens accidentally to be real, as you can see when you execute the attached Matlab script xx.m

The magnitude of a complex number is just its absolute value, calculated as

abs(x) = sqrt( (real(x)^2 + (imag(x)) )^2

However you do not have to write all this as Matlab has function abs(x) which does it all for you.

Â© BrainMass Inc. brainmass.com December 24, 2021, 6:58 pm ad1c9bdddf>https://brainmass.com/engineering/electrical-engineering/plot-magnitude-sequence-matlab-153515