Asked by Sarah Chesbrough
on 10 Nov 2018 at 21:16

function z=fft_do(x,T)

N=156;

T=5;

dt=T/N;

f0=12.8;

f1=12;

t =(1:N)*dt;

fft_do(sin(2*pi*f0*(t))+2*sin(2*pi*f1*(t)));

% or

%fft_do(sin(2*pi*30*(1:128)/128*5),5);

N=length(x);

%dt=T/N;

X=fft(x,N);

N2=floor(N/2);

Power=X.*conj(X)/N^2;

f=(0:N2)/(N2*2*dt);

z=Power;

stem(f,2*Power(1:N2+1))

xlabel('Frequency')

ylabel('Power')

title('Power spectral density')

Opportunities for recent engineering grads.

Apply Today
## 14 Comments

## Image Analyst (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635435

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635437

## Sarah Chesbrough (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635467

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635469

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635470

## Sarah Chesbrough (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635480

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635488

## Sarah Chesbrough (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635494

## Image Analyst (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635500

## Sarah Chesbrough (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635510

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635527

## Sarah Chesbrough (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635813

## Stephen Cobeldick (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635832

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429146-how-to-fix-an-infinite-recursion#comment_635863

Sign in to comment.