Hello,
I'm trying to get a function wich calculate the transform fourrier at specific freqency by using 3 methods, when the first we're using 2 loop,s the second one loop and the last none.
The input of the function are a vector wichs is a sum of cosines, the method choose, a vector time t, delta t and fAxis wich contains the frequency:
clc;clear;close all
delta_t=0.1;
Tlim=5;
f=[1;2];
[t,x]=getSumOfCosines(delta_t,Tlim,f);
[T,tPeriod,xPeriod] = findPeriod(t,x);
fAxis=[6,8,92,12];
method='No Loops';
ft = myFourierTransform(method, t, x, delta_t, fAxis);
function [t,x]=getSumOfCosines(delta_t,Tlim,f)
t=0:delta_t:Tlim;
x=sum(cos(2*pi*t.*f));
end
function [ft] = myFourierTransform(method, t, x, delta_t, fAxis)
if strcmp(method,'2 Loops')
ft=zeros(length(fAxis),length(t));
for frequency=1:length(fAxis)
for time=1:length(t)
ft(frequency,time)=x(time)*exp(-1i*2*pi*time*fAxis(frequency))*delta_t;
end
end
end
if strcmp(method,'1 Loops')
ft=ones(length(fAxis),length(t));
time=1:length(t);
for frequency=1:length(fAxis)
ft(frequency,:)=x(time).*exp(-1i*2*pi*time*fAxis(frequency))*delta_t;
end
end
if strcmp(method,'No Loops')
ft=ones(length(fAxis),length(t));
frequency=1:length(fAxis);
time=1:length(t);
ind_frequency=1:length(fAxis);
ft(ind_frequency,:)=x(time).*exp(-1i*2*pi*time.*fAxis(frequency))*delta_t;
end
end
But I got this error about the no loop method:
Matrix dimensions must agree.
Error in myFourierTransform (line 23)
ft(ind_frequency,:)=x(time).*exp(-1i*2*pi*time.*fAxis(frequency))*delta_t;
Error in a (line 10)
ft = myFourierTransform(method, t, x, delta_t, fAxis);