Asked by David
on 19 Jun 2013

Hello all

I'm quite new to Matlab, and I'm trying to use it to find the frequencies in a signal.

The signal is sampled at 30Hz, and is about 3 seconds long (88 samples in all). Looking at the signal there seems to be a periodic oscillation at around 6-8Hz, which is what I expected to see in the fourier transform. But the Fourier transform did not look like what I expected (I had hoped for a spike at around 6-8Hz and noise elsewhere).

I'm also new to fourier transforms, so I used an example from the Matlab turorials here http://www.mathworks.co.uk/help/matlab/ref/fft.html

The signal looks like this

http://img801.imageshack.us/img801/6610/vud.png

and the FT looks like this

http://img405.imageshack.us/img405/531/c12l.png

Here is a minimal working example of the code

y=[207 206 177 203 204 203 183 201 173 208 207 194 205 207 176 206 198 ... 205 208 207 191 184 201 206 208 185 193 205 204 202 189 205 207 198 ... 185 194 209 210 197 201 208 208 191 204 209 209 199 205 210 211 203 ... 194 196 206 194 194 208 208 212 196 203 210 204 192 193 209 210 207 ... 202 209 206 194 194 197 205 197 197 207 201 206 192 192 196 196 196 ... 199 205 205];

samplingRate = 30; samples = 88; timeSeries = (0:samples-1)./samplingRate;

%plot ths signal plot(timeSeries, y); xlabel('time') ylabel('signal value')

% find the FT NFFT = 2^nextpow2(samples); % Next power of 2 from length of signal spectrum = fft(y, NFFT)/samples; freqs = samplingRate/2*linspace(0,1,NFFT/2+1);

% plot the FT plot(freqs, 2*abs(spectrum(1:NFFT/2+1))) title('Single-Sided Amplitude Spectrum of pixelSeries(t)') xlabel('Frequency (Hz)') ylabel('FFT(pixelSeries)')

I'm not sure if there's a problem with the code, or whether the signal is just too short and noisy for an FT to find anything?

Many thanks for your help

Dave

*No products are associated with this question.*

Answer by Wayne King
on 19 Jun 2013

Accepted answer

Hi, You are correct. There is a peak around 7 Hz. A couple things, the signal has a nonzero mean, which results in the DC (zero frequency component) obscuring the plot.

Also, the signal is short, so I've padded it to twice its length with zeros to help visualize the peak.

y=[207 206 177 203 204 203 183 201 173 208 207 194 205 207 176 206 198 ... 205 208 207 191 184 201 206 208 185 193 205 204 202 189 205 207 198 ... 185 194 209 210 197 201 208 208 191 204 209 209 199 205 210 211 203 ... 194 196 206 194 194 208 208 212 196 203 210 204 192 193 209 210 207 ... 202 209 206 194 194 197 205 197 197 207 201 206 192 192 196 196 196 ... 199 205 205]; y = detrend(y,0); npad = 2*length(y); ydft = fft(y,npad); freq = 0:30/npad:15; plot(freq,abs(ydft(1:npad/2+1))) xlabel('Hz'); ylabel('Magnitude');

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments