MATLAB Learn Matlab: Sine Wave Analysis

  • Thread starter Thread starter zxc01
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion centers on the challenges faced by a student who has recently transferred courses and is required to learn Matlab without prior experience. The student is attempting to understand how to create a sine wave, calculate its Fast Fourier Transform (FFT), extract frequency information, and comprehend the effects of phase shifts on both time-domain and FFT-domain representations. Initial attempts using Matlab's guide were unsuccessful. A demo program was shared, which successfully plots a sine wave and its Fourier transform, illustrating key concepts. Additionally, a specific lecture on Fourier transforms was recommended for its clarity in explaining the relationship between discrete and continuous Fourier transforms, highlighting its value for learners in this area.
zxc01
Messages
2
Reaction score
0
Hello.

I have recently transferred courses, and am expected to know how to use Matlab, but have never been taught before. Therefore I have been trying to go through and teach myself some of the bits I will need to know from it.

We were told we had to know how to do certain things already and I have been going through these.


Create a sine wave, calculate the FFT of the sine wave, extract the frequency of the FFT of the sine wave from the FFT data, and know what happens to the time-domain and FFT-domain of this data if the phase of the sine wave were shifted by a few degrees.


I tried with the help of the getting started guide in Matlab itself and input:-

x=0:pi/100:2*pi
y=sin(x)
plot(x,y)

y=fft(x)

And couldn't do any of the others.

Would appreciate some help.
Thank you.
 
Physics news on Phys.org
I always get slighty confused about this so I wrote myself a demo program that does just this thing. It plots a sign wave and it's Fourier transform, showing spikes at just the right places.

Code:
clear all
% play with different values of fo
fo = 4;
N = 100; 
T = 2*pi;
t = linspace(0,T,N);

% the function and its fft (shifted so zero frequency occurs in the middle)
f = sin(2*pi*fo*t);
ft = fftshift(fft(f));

% frequency goes in steps 1/T
s = (-N/2+1:N/2) * 1/T;
figure(1),plot(t,f),title('f(t) versus t')
figure(2),plot(s,abs(ft)),title('fourier transform of f at s versus s')

As far as really understanding the relationship between the discrete Fourier transform and the continuous one, this lecture really cleared things up. It's lecture number 20 in an entire class on Fourier transforms. This is the class where he introduces the discrete Fourier transform. The whole class is amazing and I highly recommend it to everyone.
 

Similar threads

Replies
5
Views
2K
Replies
1
Views
3K
Replies
4
Views
3K
Replies
16
Views
14K
Replies
2
Views
3K
Replies
1
Views
2K
Replies
1
Views
5K
Replies
4
Views
2K
Replies
10
Views
3K
Back
Top