DSPRelated.com
Forums

FFT Frequency plot

Started by Devil103 April 13, 2008
I'm having some problems with a simple spectrum analyzer I've been
designing in Matlab (with GUIDE). I'm trying to plot the single sided
Amplitude Spectrum in my GUI with some random data.

The problem is the frequency mismatch in the x-scale of my axes. When
I input a 1 kHz sine wave for example simulink sends an array of two
colums wide. The first colomn contains the time and the second the
corresponding value of the signal.

However when I transform the data into the frequency domain and plot
the single sided amplitude spectrum the frequency is off.

N = length(simData(:,1));
dt = (simData(2,1) - simData(1,1));%Determine sample time
freqOut = 1/ (N * dt);%Basic sample frequency multiplied by N
gainFFT = (1/N) * fft(simData(:,2));

for i = 1:(N/2 - 1)
FFTgain(i) = abs(gainFFT(i+1));%Single sided spectrum
FFTfrequency(i) = i * freqOut;
end

plot(FFTfrequency, FFTgain);

Any help would be appreciated.