0
$\begingroup$

let us consider following code

function [ x ] = generate1(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))'; %'
wn = randn(length(t),1); %zero mean variance 1
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*wn;
%[pks,locs] = findpeaks(x);
 %plot(x);
end

as i know peaks in Fourier domain represent at this frequency,which are present in signal,for example let us take plot of Fourier transform of this signal let us run this signal

y=generate1(3,500,1);

and plot

plot(abs(fft(y)))

enter image description here

but clearly it does not shows me peaks at frequency given in signal,what is problem?please help me

$\endgroup$
  • $\begingroup$ Hi, I provided an answer, hope it helps. Can I ask you a question? I encounter very many questions in which people assume that in order to do a spectral analysis you just need a Fourier transform (which is not correct, as explained at the end of my answer). I'm wondering where this assumption comes from. Is this actually teached in time series analyis classes, or in textbooks? $\endgroup$ – A. Donda Jan 4 '14 at 16:18
  • $\begingroup$ generally fourier is considered as a elegant way to analyse signal in frequency domain $\endgroup$ – dato datuashvili Jan 4 '14 at 16:22
  • $\begingroup$ thanks for help and happy new year and merry christmas $\endgroup$ – dato datuashvili Jan 4 '14 at 16:29
  • $\begingroup$ You're welcome! :-) $\endgroup$ – A. Donda Jan 4 '14 at 17:22
1
$\begingroup$

Well, first off, you haven't given plot any specific values for the x-axis, so it just uses the array indices – why should these correspond to frequencies? The frequencies corresponding to Fourier coefficients can be computed like this:

f = (0 : numel(y) - 1) / numel(y) * fs;

where fs is the sampling frequency of your signal y. You don't specify the sampling frequency, but from looking at your code it is clear it is the inverse of N*T/m. Extending your function to return this information:

function [x, fs] = generate1(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))';
fs = m/(N*T);
wn = randn(length(t),1);
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*wn;
end

Putting this together,

[y, fs] = generate1(3,500,1);
f = (0 : numel(y) - 1) / numel(y) * fs;
plot(f, abs(fft(y)))

you get

If you zoom in, you will see that you have two peaks at the correct frequencies, 100 and 200. But you also have two peaks at 16467 and 16567.

That's because the Fourier transform of a real-valued signal is always symmetric. Usually this symmetry is stated to be around 0, which you get with a different interpretation of the frequencies attached to the Fourier coefficients:

f = (0 : numel(y) - 1) / numel(y) * fs;
f(f > fs/2) = f(f > fs/2) - fs;

These two interpretations are equivalent with respect to the reconstructed signal. The result:

Since the frequency vector f is no longer increasing, it is better to use fftshift for plotting:

plot(fftshift(f), fftshift(abs(fft(y))))

Zoomed in view on the result:

Please note that a simple Fourier transform is in general not a good way to assess the spectral content of a signal, for two reasons:

  1. The discrete Fourier transform treats the signal effectively as periodic, i.e. it assumes the signal continues after the end by repeating the beginning. This assumption will in many cases introduce a discontinuity, which distorts the spectral content. This problem can be solved e.g. by using a taper or window function.

  2. Especially for noisy signals, the absolute square of Fourier coefficients is a very imprecise estimate of the signal's power. It is better to cut the signal into shorter windows, and average the different estimates from the different windows. See Welch's method, or in Matlab, pwelch.

$\endgroup$
  • $\begingroup$ but for windowed method,it is also problem to choose correct width of window,otherwise there could be poor frequency resolution $\endgroup$ – dato datuashvili Jan 4 '14 at 16:24
  • $\begingroup$ That is true, there's always a trade-off. $\endgroup$ – A. Donda Jan 4 '14 at 17:22
  • $\begingroup$ that why i have started to learn wavelet transform to know some facts about it $\endgroup$ – dato datuashvili Jan 4 '14 at 17:23
  • $\begingroup$ You have the same trade-off between time- and frequency resolution there, only that it is adapted to the frequency. And you also have the problem that time-frequency power estimated from the absolute-square of wavelet coefficients from one wavelet transform can be very noisy. $\endgroup$ – A. Donda Jan 4 '14 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.