symmetric FFT in matlab - matlab

I'm going to implement OFDM system in matlab. I need to take IFFT symmetric from data and then again FFT from results. the IFFT goes right, but the FFT doesn't, fisrt half of result numbers are like data bef0r IFFT, but second half is wrong. I just don't know should I use FFT function when I know the IFFT took 'symmetric'.
here is the functions I used:
x_ifft=ifft(x1, 'symmetric')
x_fft=fft(x_ifft);
Thank you

You should not use "symmetric", but should use fftshift either after ifft or after fft.

Related

How to implement ifft in matlab?

I have been having a big problem understanding the concept of numerical ifft.
Consider a function in spatial domain like f(x)=-2/pi*Ln(abs(x)) in which x is between -Lx and Lx. The fourier transform of this function is F(w)=2/abs(w).
I want to figure out whether these two are numerically the same using ifft command in Matlab. If you run the simple code below, you will see the difference that bothers me:
clc
clear all
Lx=0.0005;
N=pow2(10);
dx=2*Lx/(N-1);
w=pi/(N*dx)*linspace(-N/2,N/2,N);
Hw=2./abs(w);
hx=1/dx*abs(fftshift(ifft(Hw)));
x=linspace(-Lx,Lx,N);
hxexact=-2/pi.*log(abs(x));
plot(x,hx,x,hxexact,'r')
legend('ifft','exact')
here is the output:
I would appreciate that if anyone could help me with this.
You seem to have some confusion about the FFT for your function, the result you might have been looking for is:
sqrt(2./pi) / w
This is the fft of your function IFF w is positive!
This is the FFT in the general case:
If you use MATLAB's fft function instead of using your own 2./abs(w) you will see that the ifft and the original function align.

IFFT: symmetric flag

Can anyone please explain the algorithm of performing the symmetric IFFT in MATLAB?
As an example:
out_signal = ifft(X,'symmetric');
Here, X is complex symmetric signal.
The symmetric flag when performing the ifft assumes that your frequency domain signal is conjugate symmetric or Hermitian. A function is conjugate symmetric when you reflect the signal across the y-axis and it is equal to its complex conjugate. In other words:
What this actually means is that the sign of the imaginary part of your signal is opposite when x < 0.
The reason why this is so useful is because it allows for more optimization and short-cuts in computing the inverse should the signal be conjugate symmetric. This means that one half of the spectrum is for the positive frequencies while the other half is for negative frequencies. The negative coefficients are conjugates of the positives. This leads up to a useful property of the FFT where if the Fourier Transform of a signal is conjugate symmetric, its time-domain equivalent will be purely real-valued. If you know that the output of the time-domain signal is purely real-valued, this will provide some speedups to ifft.
Take a look at the Wikipedia article I linked above for more details. Also, take a look at this useful post on DSP StackExchange for a good explanation too. If you want the IFFT algorithm to take advantage of the conjugate symmetric structure, take a look at these two posts for more details:
How to use inverse FFT on amplitude-frequency response?
https://dsp.stackexchange.com/questions/282/complex-conjugate-and-ifft

Matlab: Using fft without fftshift

I have a simple question on using fft in 1D without using fftshift. Say I have a code running the fft of sin(6*2*pi*n):
n=0:1/20:1-1/20;
x=sin(2*pi*n);
X=fft(x);
plot(abs(X));
plot(abs(fftshift(X)));
Without fft shift, I see a peak at 6Hz, and another peak at very very high frequency like 2000Hz. Does this 2000Hz component coresponds to the -6Hz peak?
Yes. Typically the output of the FFT algorithm has the negative frequencies shifted to the second half of the positive frequenies, so if one directly graphs the fft output a negative peak that's very close to zero will appear as a positive peak very close to the right hand edge of a figure. fftshift shifts the negatives to where one would intuitively expect them to be.

Is It Possible to Get SFT from FFT?

I use Auriotouch sample program to generate FFT data to get Frequency and magnitude. Is there any easy method available to get SFT from FFT?
If by SFT you mean DFT (the Discrete Fourier Transform of a finite vector or array of equally spaced audio sample values), it is identical to the result of an FFT computation (plus or minus some tiny numerical rounding differences) of that same sample vector.

How to get coefficients for sine/cosine function from complex FFT in Matlab?

I'm working on a control system that measures the movement of a vibrating robot arm. Because there is some deadtime, I need to look into the future of the somewhat noisy signal.
My idea was to use the frequencies in the sampled signal and produce a fourier function that could be used for extrapolation.
My question: I already have the FFT of the signal vector (containing 60-100 values e.g.) and can see the main frequencies in the amplitude spectrum. Now I want to have a function f(t) which fits to the signal, removes some noise, and can be used to predict the near future of the signal. How do I calculate the coefficients for the sine/cosine functions out of the complex FFT data?
Thank you so much!
AFAIR FFT essentially produces output as a sum of sine functions with different frequencies. The importance of each frequency is the height of each peak. So what you really want to do here is filter out some frequencies (ie. high frequencies for the arm to move gently) and then come back to the time domain.
In matlab this should be like going through the vector of what you got from fft, setting some values to 0 (or doing something more complex to it) and then use ifft to come back to time domain and make the prediction based on what you get.
There's also one thing you should consider while doing this - Nyquist frequency - this means that the highest frequency that you get on your fft is half of the sampling frequency.
If you use an FFT for data that isn't periodic within the FFT aperture length, then you may need to use a window to reduce spurious frequencies due to "spectral leakage". Frequency estimation techniques to better estimate "between bin" frequency content may also be appropriate. The phase of each cosine sinusoid, relative to the edge of the window, is usually atan2(imag[i], real[i]). The frequency depends on the sample rate and bin number versus the length of the FFT.
You might also want to look into using a Kalman filter instead of an FFT.
Added: If your signal isn't exactly integer periodic in the FFT length, then you may want to do an fftshift before the FFT to move the resulting phase measurement reference point to the center of your data vector, instead of a possibly discontinuous circular edge.