Did you ever tried to follow example from MATLAB help? Result of the FFT is complex, containing information both for magnitude and phase. Thus in order to extract the magnitude you must take the absolute value of your result -
abs function. What you are doing currently is plotting complex values.
Please refer to basics of DFT if you have any doubts (i.e. to understand why DFT spectrum is mirrored) and mentioned example for MATLAB fft. Here is one of ways to create frequency vector for magnitude response.
% fs --> sampling frequency to be defined.
N = length(data);
X = abs(fft(data))/N;
f = (0:N-1).*(fs/N);
If you wish to show your results in decibel scale, then convert the values with usage of
ref is your reference value - can be
I am sure that having the frequency vector and magnitude values you can take it from here in order to calculate the mean value in appropriate range.
Extra things you might want to consider:
- Apply the windowing to your signal if it is necessary (probably it is). When windowing is applied, scale not by
N, but use the sum of window samples.
- Use the Power Spectral Density estimation instead of FFT. Second figure you provided is the example of PSD - in fact this is copied from MATLAB help regarding PSD estimates using FFT. I believe you have all necessary info in there regarding