0

I was trying to calculate the Fourier series coefficients for a raw data (random signal).

I succeeded to calculate the FFT of the signal, but I couldn't calculate the Fourier series coefficients. My main idea is to generate a score or a number which represents how many cos and sin waves can generate my signal. For example, if the signal is a sine wave this means it is 100% pure as it can be generated by only one sine signal, if it consists of two sine waves, this means it is not a pure wave, and if it consists 100 sine waves it is really unpure and so on.

So my solution was to calculate the FFT of the signal and then generate another signal using the IFFT (inverse FFT) with smaller number of FFT samples and check the correlation between the original and the generated signal. If it is the same this means that it has a small number of sine waves. I am not sure I am right or wrong... What is the answer?

My code:

x = fft(s); %s is 2000 sample points
y = ifft(x(1:400), 2000);
c =  real(corr(s', y'));
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SMH
  • 1,276
  • 3
  • 20
  • 40
  • You have to learn how fft works (http://www.mathworks.com/help/matlab/ref/fft.html). You didn't post the size of `s` in your code. But If you are not using `fftshift`, then by writing `x(1:400)` you probably cut only negative part of the spectra – Mikhail Genkin Feb 16 '15 at 05:04
  • First and foremost, you need to read Paul R's answer in the duplicate post I have marked. That is fundamental reading on interpreting how the FFT components are read. Secondly, your observation about a pure cosine and sine tone where it has one component in the FFT is true... provided that you specify a sampling frequency and length of your FFT so that it can give you a bin that is (more or less) equal to the frequency of that sine/cosine. BTW, increasing and decreasing the total number of points for the FFT has implications in how you interpret each frequency bin. Read the duplicate post. – rayryeng Feb 16 '15 at 06:48
  • @MikhailGenkin - Not true. If you don't `fftshift`, the first half of the signal represents the positive frequencies, while the second half of the signal represents the negative frequencies. If you `fftshift`, **then** you will get the negative frequencies first. Specifically, you will make the DC component centred at the middle of the signal, while the negative spectra is to the left of the centre and the positive to the right. This is a consequence of the Cooley-Tukey FFT algorithm, which is what MATLAB uses (They actually use FFTW: http://fftw.org). – rayryeng Feb 16 '15 at 06:50
  • @rayryeng Thanks for your comment but the other question is not related to what I need. I tried FFT but I think it is wrong (as the limit is from -pi to pi)so we need to get the fourier series components. It would be great if you have a simple way to extract the number of cos and sine wave in the signal, could you please help me? – SMH Feb 16 '15 at 07:01
  • The limit from `-pi` to `pi` is the **normalized** frequency. You need to scale it so that `pi` matches the Nyquist frequency of your system, or `fs / (2*pi)` in order to obtain the frequencies at each bin. BTW, the DC component is when `n = 0`, the first Fourier "series" coefficient is when `n = 1` or `fs / N`, the second FS coefficient is when `n = 2` or `2*fs/N` and so on. I'm still maintaining that it's a duplicate. – rayryeng Feb 16 '15 at 07:26
  • @rayryeng I am wondering how the value of the coeff doesn't depend on the values of the signal itself, I am wondering how could I know the number of sine and cos waves in the signal? Could you please help me? all what I need is a value like n which means n sin and cos waves in the signal. – SMH Feb 16 '15 at 11:33

0 Answers0