Very new to MATLAB and Im trying to use the FFT function. I got a video which showed me that a function and a normal m file is needed. Created that but now dont know how to call the function from the m file. Here's is the function:
function [ X,freq ] = positiveFFT( x,Fs )
%This function takes data,and discards negatives only taking the
%positives,getting rid of complex values
%adopted from blinkdagger.com
N=length(x);
k=0:N-1;
T=N/Fs;
freq=k/T; %create the frequency range
X=fft(x)/N; %normalise the data
cutOff=ceil(N/2); %cut off frequency
X=X(1:cutOff);
freq=freq(1:cutOff);
end
and the m-file:fo=4; %freqency of the sine wave(4cycles,4Hz)
Fs=100; %sampling rate
Ts=1/Fs; %sampling time interval
t=0:Ts:1-Ts;
n=length(t); %number of samples
y=2*sin(2*pi*fo*t);
[YfreqD,freqRng]=positiveFFT(y,Fs);
stem(freqRng,abs(YFreqD));
I think you should change
as