In case a off-nominal signal is processed using nominal frequency based fft algorithm, the peak value of the magnitude of fft is still at the frequency index or bin pertaining to the nominal value (though the amplitude is different and the side lobes also have an amplitude which is not seen when the signal has a nominal value of frequency). Why does the frequency index not change even though the frequency is no longer the nominal value. How can i visualize this in matlab using the fft function.
MATLAB: DFT using matlab function
digital image processingfftfrequencysignal processing
Related Solutions
Hello Komal,
The whole point of using fftshift is to put zero frequency at the center of the resulting frequency array. If you zero-pad fft_puretone on one side only, it messes up that symmetry. So fft_puretone needs to be zero-padded equally on each side.
An an N-point fft with time array spacing of delt and frequency array spacing of delf always obeys delt*delf = 1/N. That remains true after subsequent zero-padding.
For the correct frequency domain amplitude, you need to multiply the fft by a factor of 1/N.
You did not specify what puretone looks like in the time domain, but I am speculating that the time record was 5 seconds, and the amplitude of the wave = 1/sqrt(2) (peak), = 1/2 (rms).
Here is an example of how this would work. The resulting arrays have 1105920 elements and show a peak at 1kHz and another at -1kHz. After ffting a real function, people often double the positive frequency peak and ignore the negative frequency peak, which is all right as long as you keep in mind what the fft is actually doing.
hmax = 1105920fs = 44100% 1k puretone in time domain
delt = 1/fs; f0 = 1000; T = 5; % time record (sec)
N = T*44100; t = (0:N-1)*delt; puretone = (1/sqrt(2))*sin(2*pi*f0*t); % back to fft code
fft_puretone = abs(fftshift(fft(puretone)/N)); Npad = hmax-N; fft_puretone = [zeros(1,Npad/2) fft_puretone zeros(1,Npad/2)]; delf = 1/(N*delt); % fundamental rule for fft
freq = (-hmax/2:hmax/2-1)*delf; figure(1) plot(freq,fft_puretone)
Hi John,
This concerns fft only; psd is a different animal.
For a continuous oscillation, most people do not seem to be concerned about fft output that spills into adjacent frequencies, but it's worth looking at as you are doing. With the fft you can get sharp one-point frequency peaks with a varying number of points and a varying amplitude, but not for time windows of arbitrary width. With fft It's required that there be an exact integral number of oscillations in the time window. And, using a single oscillation of a sine wave as an example, the last point in the array can't repeat the first point. The last point has to be "one point short" of a full oscillation
So
y = sin(2*pi*(0:9)/10) % correct but y = sin(2*pi*(0:10)/10) % incorrect
The code below gives two peaks, one at +160 kHz and one at -160 kHz for any number of fft points (above a minimum number), any number of complete oscillations in the time window and any amplitude. The abs(amplitude) of each peak is A/2, consistent with cos(w*t) = (1/2)(exp(i*w*t)+exp(-i*w*t)). If you want, as is common for plotting purposes, you could ignore the negative freqencies and double the height of the positive frequency peak.
f0 = 160e3;ncyc = 23; % number of cycles in time window
A = 6; % amplitude
psi = pi/6; % arbitrary phase angle
N = 1299; % need N >2*ncyc to avoid aliasing
t0 = 1/f0;T = ncyc*t0; % time window
delt = T/N;t = (0:N-1)*delt;y = A*cos(2*pi*f0*t+psi);figure(1)plot(t,y);grid ondelf = 1/(delt*N); % golden rule for fft
if rem(N,2) ==0 f = (-N/2:N/2-1)*delf;else f = (-(N-1)/2:(N-1)/2)*delf; endz = fftshift(fft(y))/N; % fftshift to put f=0 in the middle
figure(2)stem(f,abs(z),'o-');grid on
Best Answer