MATLAB Answers

Why does signal still contain a large number of spikes after FFT

55 views (last 30 days)
crixus
crixus on 7 Oct 2016
Commented: dpb on 13 Oct 2016
I have perform FFT on my signal but due to the dc offset my amplitude peaks at 0 hz so i use x = x - mean(x) to remove the dc offset before fft but this time round after fft although I can see the difference but it still contains a lot of spikes. It is as if the signal has yet to go through FFT. Is there a reason for this ?

  0 Comments

Sign in to comment.

Accepted Answer

dpb
dpb on 7 Oct 2016
Well, if your original signal is full of a large number of frequency components, the spectrum will be, too. This looks like a few dominants with a large number of what may be sidebands and harmonics/subharmonics. You might see what a dB scale (log) looks like instead of just linear.
What is the signal? Knowing something of the system might let somebody here expound at depth; ya' never knows, but there's a "veritable plethora" of backgrounds/experience.
One issue that could be a problem depending -- was the data collected with analog anti-aliasing filters or some other way to ensure sampling was fast enough to avoid aliasing? If there were components in the original signal higher than or very near the Nyquist, they will fold back into the computed frequency range. If that is the case, once the data are sampled, there's no way to remove that source of contamination.

  13 Comments

Image Analyst
Image Analyst on 10 Oct 2016
Raspberry Pi and BeagleBoard are more sophisticated than Arduino (or so I've heard) so maybe you might need to switch to one of those.
crixus
crixus on 13 Oct 2016
Hi guys, thanks for the feedback ! truly appreciate it ! what i'm planning to do is to speed up the data saving portion and see what rate is can achieve, if there's a need i'll eliminate one of the board to lessen the data communicate between the microcontroller. otherwise I will just have to buy a real daq :( which i hope not (am a poor part time student)
dpb
dpb on 13 Oct 2016
Remember that for spectral analysis, besides the rate the consistency of that rate is important, too...sampling at 1 kHz a few fractions of a msec owing to OS task-swapping or garbage collection or whatever is a significant error in terms of the sample interval.

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 8 Oct 2016
What are you listening to? It looks like white noise. Is it? If so, I would not be surprised to see basically random energy in any of the wavelengths, which is what I see in your FFT. Like dpb said, we need to know what sound you expect your signal to be, and what you expect the noise to be, to best figure out what kind of filter you need to separate the two.

  7 Comments

Show 4 older comments
dpb
dpb on 9 Oct 2016
"Does that mean you are taking one reading every second? Does that mean that every second you are taking thousands of readings..."
I actually hadn't thought about of the latter, IA, but it is possible...if that were the case, then the likelihood of my supposition is markedly reduced, indeed.
And, whatever the "thruster" is, I suspect it is indeed likely to have a very rich output spectrum so OP's result may be what it actually is...not way to know certainly w/ the info given but I was presuming was just taking a sample once a second as initially written. I'd've thought the high-speed acquisition just downloaded once/sec. would be described differently; but who's to say???
crixus
crixus on 9 Oct 2016
Actually, this is my first time trying FFT and from the examples that I read, I thought i'm "supposed" to see only one or two spikes within a signal after FFT which is why i thought i'm wrong at this.
dpb
dpb on 9 Oct 2016
The code itself looks ok; it's the data-collection that is the issue as you've now recognized it seems. I'll simply note the "richness" of the FFT is simply dependent upon what the input content is; there are going to be as many peaks as there are discernible frequency components in the input signal; probably the examples in texts you've looked at were selected precisely to illustrate some principles from "clean" systems that had well-defined peaks of given frequencies.
In your particular case here, the system undoubtedly is very rich in energy content from the process and then by drastically under-sampling as your collection process did, that compounded the problem immensely by all of those various actual frequencies getting folded into the spectrum over a number of different times and so it ended up looking essentially as white noise as IA noted.

Sign in to comment.


crixus
crixus on 8 Oct 2016
Edited: crixus on 8 Oct 2016
Hi both, thanks for your replies. The code that i used to perform the FFT is as follow
x = xlsread('test.csv');
x = x(~any(isnan(data1),2),:);
x = x(1:1500,:);
x = x-mean(x);
fs=1000; % sampling freq
xmax = max(abs(x)); % find the maximum value
x = x/xmax; % scaling the signal so the largest value(xmax) is 1
% time & discretisation parameters
N = length(x);
t = (0:N-1)/fs;
% spectral analysis
win = hanning(N); % sin window
% default is symmetric, periodic start at 0 at
% point 1, periodic Hann window is constructed by extending
% the desired window length by one sample, constructing a
% symmetric window, and removing the last sample
% symmetric starts at very close to zero ends at very close to zero
% hamming will being points slightly above 0, hanning starts at 0
K = sum(win)/N; % coherent amplification of the window
X = abs(fft(x.*win))/N; % Without abs it will give complex number
% abs will give the complex magnitude
% FFT of the windowed signal
NUP = ceil((N+1)/2); % calculate the number of unique points
% ceil = round off to nearest positive infinity
X = X(1:NUP); % FFT is symmetric, throw away second half
phase = unwrap(angle(fft(x.*win)));
phase = phase(1:NUP);
if rem(N, 2) % odd nfft excludes Nyquist point
% rem = reminder after division
X(2:end) = X(2:end)*2;
else % even nfft includes Nyquist point
% The DC component and Nyquist component,
% if it exists, are unique and should not be multiplied by 2
X(2:end-1) = X(2:end-1)*2;
end
f = (0:NUP-1)*fs/N; % frequency vector
%X = 20*log10(X); % spectrum magnitude
% plotting of the spectrum
figure()
plot(f, X, 'r') % Create a plot with a logarithmic scale for the x-axis and a linear scale for the y-axis
hold on
xlim([0 max(f)]) % set the limit for x axis
grid on
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
title('Amplitude Spectrum of the Signal')
xlabel('Frequency (Hertz)')
ylabel('Magnitude')
spectralcentroid = sum(X .* f')/sum(f);
plot(spectralcentroid,'*','MarkerSize',14)
hold off
%%Plotting amplitude against phase
figure()
plot(f,phase/180*pi)
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
title('Phase Spectrum of the Signal')
xlabel('Frequency (Hertz)')
ylabel('Phase (Radian)')
plotting of the spectrogram
figure()
len_seg=512; %window size 1024;
spectrogram(x, len_seg, 3/4*len_seg, [], fs, 'yaxis') % S = spectrogram(X,WINDOW,NOVERLAP,NFFT,Fs)
h = colorbar;
set(h, 'FontName', 'Times New Roman', 'FontSize', 14)
ylabel(h, 'Magnitude (Decibels)');
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14)
xlabel('Time (Seconds)')
ylabel('Frequency (Hertz)')
title('Spectrogram of the Signal')

  3 Comments

Image Analyst
Image Analyst on 8 Oct 2016
You forgot to attach "data" and the code to read it in, so no one can try your code.
dpb
dpb on 8 Oct 2016
Doesn't make any difference; the problem is in the fundamental data collection and can't be cured except by sampling the input at (at least) 100 Hz, and probably preferably 2-3X times that.

Sign in to comment.