# sinus generation and it's fft in radians

I'm trying to generate sine signal and display it's fft in radians, byt I meet several issues that I can't understand. Please find my script below:

clear all; close all; clc;
fs = 10*pi;
ts = 1/fs;
t = 0:ts:2*pi;
sine = cos(10*t);
plot(t/pi,sine)
sinefft = fft(sine);
subplot(2,1,1)
plot(abs(sinefft))
subplot(2,1,2)
plot(abs(fftshift(sinefft)))


Results

1. Why on first plot fft shows that cosine has a frequency 11 radians?

2. How to shift fft to achieve frequency domain around 0?

I will be thankful for your explanations.

Maks

1. Why on first plot fft shows that cosine has a frequency 11 radians?

The array index number of the cosine peak is 11. The frequency is different.

Matlab indexes from 1, so the FFT bin number will be 10 (as we have a 0 bin in FFTs).

The frequency of that bin will be $$\frac{2 \pi (11 - 1) }{N } = \frac{2 \pi 10}{ 198} = \frac{10\pi}{99}$$ assuming your FFT length was 198.

Note that this will be a normalized frequency between 0 and $2\pi$ (or, if you prefer, $-\pi$ and +$\pi$).

1. How to shift fft to achieve frequency domain around 0?

Your use of fftshift does this in the second plot. However, you need to set the $x$ axis by doing something like:

N = length(sinefft);
delta_omega = 2*pi/N; % rad/sec between FFT bins
omega = -pi:delta_omega:(pi - delta_omega)
plot(omega, abs(fftshift(sinefft)));


Minor Correction I previously had this frequency variable as f, it's actually omega.

How to calculate now what frequency in Hz has this signal?

So the normalized frequency in radian per second is omega. That ranges from $-\pi$ to $+\pi$ (modulo some end effects).

The normalized frequency in "Hz" is f. This will be omega/2/pi. This ranges from -0.5 to +0.5.

The frequency in terms of the sampling frequency will be f_true = omega / pi / 2 * fs (where fs is the sampling frequency).

• Great! That's clearing a lot. But I have one question more, therefore I'm new in radians domain (it was always unclear for me, but I've made myself a goal to understand relation between w and f): How to calculate now what frequency in Hz has this signal? Is it f = w/2*pi? – Maks Piechota May 5 '16 at 18:02
• @MaksPiechota : Check out my update; I made a mistake earlier, and have tried to address the question in your comment. – Peter K. May 5 '16 at 18:16
• Ok, many thanks for your explanation. But why delta_f = 2*pi/N? I see it works but I don't understand why it is independent from sampling frequency? – Maks Piechota May 5 '16 at 18:39
• @MaksPiechota Once you've sampled, we don't really care about the sampling frequency as far as DFTs or filtering are concerned. We just have data in an array, indexed by an integer. We do care about the sampling frequency when we want to relate it to the "analog" world, just not once we're just working with numbers in an array. For the samples in the array, we only really care about normalized frequency (from 0 to 1 or -0.5 to +0.5 or in radian/second from -$\pi$ to |$\pi$). – Peter K. May 5 '16 at 18:42
• Ok. So in nominator we have $2\pi$ because this is the range that we want to have in out fft x axis? – Maks Piechota May 5 '16 at 19:00