How i will write the code for fft

  • Thread starter Thread starter cobraa_eyz
  • Start date Start date
  • Tags Tags
    Code Fft
AI Thread Summary
The discussion revolves around coding the Fast Fourier Transform (FFT) in MATLAB, focusing on resolving matrix dimension errors encountered during calculations. The initial error arose from attempting to multiply incompatible matrix sizes, which was clarified as MATLAB's treatment of multiplication. The user resolved the issue by ensuring element-wise multiplication with the correct matrix dimensions. They also inquired about limiting the FFT to a specific time range, which was addressed by adjusting the matrix size for variable A and using element-wise operations. The final solution involved successfully plotting the real part of the FFT results.
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
 
Back
Top