Escolar Documentos
Profissional Documentos
Cultura Documentos
MFx = abs(Fx);
Frequency analysis of an even number of samples give the Nyqvist frequency at N/2 Hz and
the frequency resolution is df = 1/T = 1 Hz.
On the horizontal axis, the positive frequencies occupy the left half of the axis and the
negative frequencies occupy the right half. The figure shows how MatLab plots the
spectrum.
140
120
100
80
60
Nyqvist frequency
40
20
Positive frequencies
50
100
Negative frequencies
150
200
250
The frequency with index n = 1 is zero. The numbers will be displaced by 1 step by plotting
the spectrum. We have to introduce a positive frequency axis numbered fro 0 to N/2 - 1.
We can use the earlier defined variable n to number the frequency axis.
x=signal(f,N)
% sinusoid
% f=frequency, N=number of samples
% Total sampling time = 1 second
n = 0:N-1; % numbering the samples
x = sin(2*pi*f*n/N);
plot(x)
MFx = abs(fft(x));
plot(n(1:N/2),MFx(1:N/2)) % plot positive frequencies
120
100
80
60
40
20
Negative frequencies
50
Positive frequencies
100
150
200
250
The signal and the spectrum can be plotted together with the commands:
subplot(2,1,1); plot(x)subplot(2,1,2);
plot(n(1:N/2),MFx(1:N/2))
1
0.5
0
-0.5
-1
50
100
150
200
250
50
100
150
200
250
150
100
50
If we want to study the real- and imaginary part of the spectrum, we can extract these parts
by the commands:
RFX = real(Fx);
IFX = imag(Fx);
In the example we have been sampling during 1 sec and the frequency resolution is 1 Hz.
If we specify the sampling frequency to fs, which frequency resolution will we have?
With N sample the total sampling period is T = N/fs.
The frequency resolution df = 1/T = fs/N. Due to the symmetrical properties of the spectrum
we only use the positive frequencies.
The signal will be: x = sin(2*pi*f*n/fs);
The frequency scale is: frek = (0:N/2-1)*fs/N;
and we can plot the positive frequencies with:
plot(frek,MFx(1:N/2))
A function that generates a sinusoid with the sampling frequency fs can look like this:
function
%
%
%
%
x=signal(f,fs,N)
sinusoid
f=frequency, N=number of samples
fs=sampling frequency
Total sampling time = 1 second
you can add amplitude and phase angle to the function, and also determine how many
samples that will be plotted:
Function sinewave(N,f,fs,np)
% sinwave calculate and plot a sinusoid with N sample
% sampling frequency fs, frequency f and plot np
% samples
t=(0:N-1)/fs;
x = sin(2*pi*t*f);
plot(t(1:np),x(1:np))