11 November 2018 1 10K Report

I want to use fft on first cycle of sine wave to get all samples from it.

fs=1000; t = 0:1/fs:0.2-1/fs; x = 5*sin(2*pi*50*t); plot(t,x)

To do it I used loop:

n = 20; for i=n:length(x) y = fft(x(i:i+n-1)); end

where n is number of samples/cycle (fs=1000, freq=50 Hz).

But MATLAB shows me an error "Index exceeds matrix dimensions" in line with y = fft(...).

How to fix it?

Similar questions and discussions