Learn Matlab: Sine Wave Analysis

  • MATLAB
  • Thread starter zxc01
  • Start date
  • Tags
    Matlab
In summary, the individual is seeking help with understanding how to use Matlab for their recently transferred courses. They have attempted to teach themselves, but have encountered difficulties in creating a sine wave, calculating its FFT, and extracting its frequency. They have also struggled with understanding the relationship between the discrete and continuous Fourier transform. They have found a helpful demo program and recommend lecture number 20 of a Fourier transform class for further understanding.
  • #1
zxc01
2
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
  • #2
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.
 
  • #3


Hello,

It's great that you are taking the initiative to learn Matlab on your own. It can be a very useful tool for scientific analysis and data processing.

To create a sine wave in Matlab, you can use the "sin" function. For example, if you want to create a sine wave with a frequency of 5 Hz and a duration of 1 second, you can use the following code:

t = 0:0.001:1; % time vector from 0 to 1 second with a step size of 0.001
f = 5; % frequency of the sine wave in Hz
y = sin(2*pi*f*t); % create the sine wave

To calculate the FFT of the sine wave, you can use the "fft" function. This will give you the amplitude and phase information of the different frequency components present in the signal. To extract the frequency from the FFT data, you can use the "findpeaks" function. This will give you the frequency with the highest amplitude in the FFT data.

If you shift the phase of the sine wave by a few degrees, it will affect both the time-domain and FFT-domain data. In the time-domain, the waveform will be shifted horizontally, while in the FFT-domain, the amplitude and phase information will be affected.

I would recommend going through some tutorials or online courses to learn more about Matlab and its capabilities. The official Matlab website has a lot of resources available, including tutorials and documentation. You can also find helpful videos and tutorials on YouTube.

I hope this helps. Good luck with your learning journey!
 

1. What is Matlab?

Matlab is a high-level programming language and interactive environment commonly used in scientific and engineering fields. It allows users to perform a variety of numerical computations, data analysis, and visualization tasks.

2. What is a sine wave?

A sine wave is a mathematical function that describes a smooth repetitive oscillation. It is characterized by its amplitude, frequency, and phase. In Matlab, sine waves can be generated using the "sin" function.

3. How do I analyze a sine wave in Matlab?

To analyze a sine wave in Matlab, you can plot the wave using the "plot" function, adjust its parameters such as amplitude and frequency, and perform mathematical operations on it using built-in functions. You can also use the "fft" function to perform a Fast Fourier Transform and analyze the frequency components of the wave.

4. Can I use Matlab for real-world applications?

Yes, Matlab is widely used in various industries and research fields for real-world applications such as signal processing, control systems, image and video processing, and machine learning. It is a versatile tool that can handle complex numerical computations and data analysis tasks efficiently.

5. Is Matlab difficult to learn?

While Matlab may seem intimidating at first, it is relatively easy to learn compared to other programming languages. Its intuitive syntax and extensive documentation make it a popular choice for beginners and experienced programmers alike. With practice and dedication, anyone can learn and master Matlab.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
829
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
16
Views
13K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Back
Top