How i will write the code for fft

  • Thread starter Thread starter cobraa_eyz
  • Start date Start date
  • Tags Tags
    Code Fft
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
cobraa_eyz
Messages
2
Reaction score
0

Homework Statement




How i will write the code for fft

Homework Equations



ACos(ωt+φ)

The Attempt at a Solution


n = 100;
n = 0:n;
nodd = 2*n + 1;
T=n*pi/2w
w=2*pi*1.93*10^14;
phi= 0;
A=-6:6;
X= A*cos(w*T+pi)
%Here it generates error
" ? Error using ==> mtimes Inner matrix dimensions must agree."
Y=fft(X)
Plot(A,T)


When ever i use two variable values it gives me the same error, how can i fix that.
Regards
 
Physics news on Phys.org


I think the error lies in that MATLAB treats * as matrix multiplication. In
> X = A*cos(w*T+pi)
the cos part is a 1x101 matrix (1 row, 101 columns) while the A part is a 1x13 matrix (1 row, 13 columns). Clearly, those can't multiply. You should probably just use a scalar for A. Then if you want to know the Fourier transforms of different magnitudes, just do a for loop but make sure the fft is within the for loop.
 


Dear Spring
many thanks for your reply. Well i have solve that problem. Now am taking the FFT how i will add Limit to FFT i.e [0,T]
.
%E= Acos(wt+pi) [0,T]" Time domain-> Frequency domain
n=100;
n=0:n;
nodd=2*n+1;
%pi=0; %"0:360
w=2*pi*1.93*10^14;

T=n*pi/2*w;
A=-50:50;% size(A)=[ 1 101] " to adjust matrix mismatch
X=A.*cos(w*T+pi);% element wise mulitpication [size(X)=[1,101]
Y=real(fft(X))
plot(T,Y)

Regards
Shahzad