How i will write the code for fft

  • Thread starter Thread starter cobraa_eyz
  • Start date Start date
  • Tags Tags
    Code Fft
Click For Summary
SUMMARY

The discussion focuses on implementing the Fast Fourier Transform (FFT) in MATLAB, specifically addressing matrix dimension errors encountered during calculations. The user initially faced an error due to incompatible matrix sizes when attempting to multiply matrices in the expression X = A*cos(w*T+pi). The solution involved using element-wise multiplication with the dot operator (.*) and ensuring that the matrix A was correctly sized. The final code successfully computes the FFT and plots the results.

PREREQUISITES
  • Understanding of MATLAB syntax and operations
  • Familiarity with Fast Fourier Transform (FFT) concepts
  • Knowledge of matrix operations and dimensions in MATLAB
  • Basic understanding of trigonometric functions and their applications in signal processing
NEXT STEPS
  • Learn about MATLAB's element-wise operations and their importance in matrix calculations
  • Explore advanced FFT techniques and optimizations in MATLAB
  • Study the implications of frequency domain analysis in signal processing
  • Investigate the use of for loops in MATLAB for iterative FFT calculations
USEFUL FOR

This discussion is beneficial for MATLAB users, signal processing engineers, and students working on FFT implementations and troubleshooting matrix operations in MATLAB.

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
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
2K
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K