# How to do a fft from a sine signal with hanning function

279 views (last 30 days)
Jack Walker on 4 Oct 2016
Commented: David Pinho on 6 May 2019
Hello, i want to do a fast fourier transformation on a sine signal. By using the hanning function. Btw i am a newbie, concering matlab programming so, dont be to hard too me. If you could also help me explain the hanning function properly, i would really appreciate it.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (2)

Gareth Thomas on 4 Oct 2016
MATLAB has awesome help. If you type
doc fft
You should get a nice page with examples that should be enough to get you going: FFT in MATLAB
##### 1 CommentShowHide None
Jack Walker on 4 Oct 2016
Thank you, i will try to read the link you provided it. Although tt is a little bit complicated to me xD

Sign in to comment.

Jan Orwat on 4 Oct 2016
Edited: Jan Orwat on 4 Oct 2016
You can try starting with something like this
fs = 44100; % sampling frequency
T = 1; % period, 1 second
n = T*fs;
t = linspace(1/fs, T, n);
% calculate hanning window, if you have Signal Processing Toolbox just use hann(n)
window = 0.5 - 0.5*cos(2*pi*linspace(0, 1, n));
% generate simplest sine signal
freq = 1000; % 1kHz sine wave
s = sin(2*pi*freq);
% calculate fft
z = fft(s.*window);
hanning window is just 1 - one period of cosine function, it's usually normalised to 1.
##### 5 CommentsShowHide 4 older comments
David Pinho on 6 May 2019
s = sin(2*pi*freq); should be sin(2*pi*freq*t)

Sign in to comment.

### Categories

Find more on Spectral Measurements in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!