Digital Signal Processing Reference
In-Depth Information
f analysis [m] = mf sampling
N
:
6.3
Plotting the Spectrum
To get a spectral plot, we will start out with an example signal. The following code
sets up a signal, x.
>> % Set up an example signal
>> n = 0:99; % number of points
>> fs = 200; % sampling frequency
>> Ts = 1/fs; % sampling period
>> % x is our example signal
>> x = cos(2*pi*20*n*Ts + pi/4) + ...
3*cos(2*pi*40*n*Ts - 2*pi/5) + ...
2*cos(2*pi*60*n*Ts + pi/8);
>>
Now we need the frequency information from x, which we can get from the
Fourier transform. Also, we will establish the index m.
>> X = fft(x);
>> m = 0:length(X)-1;
It may be helpful to know the frequency resolution; the following code displays
it.
>> disp(sprintf(Freq resolution is every %5.2f Hz,...
fs/length(X)));
Freq resolution is every 2.00 Hz
>>
To see the spectrum, we will show both the frequency magnitude response and
a plot of the phase angles.
>> % Plot magnitudes
>> subplot(2,1,1);
>> stem(m*fs/length(X),abs(X), b);
>> ylabel(magnitude);
Search WWH ::




Custom Search