MATLAB - Fourier (how do I do this)

In summary, the person is looking to use Matlab to check their answers for finding the Fourier transform of cos(omega_0 t). They mention that they know the answer is pi*(delta(omega - omega_0) + delta(omega + omega_0)), and they are trying to do this in Matlab using the fourier function. They provide an example of using the function with cos(t) and getting the correct answer, but they are unsure of how to do it with a variable, such as cos(a*t). They request assistance in being able to check harder transforms. The expert then provides a solution by initializing the symbolic variables and using the fourier function with cos(a*t), which returns the desired answer.
  • #1
810
0
I would like to use Matlab to check my answers.

For example, I want to find the Fourier transform of [tex] \cos \omega_0 t [/tex].

I know the answer is:
[tex] \pi ( \delta(\omega - \omega_0) + \delta(\omega + \omega_0)) [/tex].

How do I do this in Matlab. All I can find is something like this:
Code:
clc;
syms t;
fourier(cos(t))

This returns:
Code:
pi*(dirac(w-1)+dirac(w+1))

I would really like to be able to do something like:
Code:
clc;
syms t;
fourier(cos(a*t))

and get:
Code:
pi*(dirac(w-a)+dirac(w+a))

so I can actually check harder transforms.

How would I do this?

Thanks in advance :)
 
Physics news on Phys.org
  • #2
Just make sure that "a" is also initialized in your symbolic variables.

>> syms a t
>> fourier(cos(t))

ans =

pi*(dirac(w - 1) + dirac(w + 1))

>> fourier(cos(a*t))

ans =

pi*(dirac(a + w) + dirac(a - w))
 

1. How do I perform a Fourier transform in MATLAB?

To perform a Fourier transform in MATLAB, you can use the built-in function fft. Simply pass in the data you want to transform as an argument, and the function will return the transformed data. Alternatively, you can also use the fft2 function for two-dimensional signals and fftshift for shifting the zero-frequency component to the center.

2. How do I plot the frequency spectrum in MATLAB?

To plot the frequency spectrum in MATLAB, you can use the plot function. First, use the fft function to transform your data. Then, use the abs function to get the magnitude of the transformed data. Finally, plot the magnitude against the frequency using the plot function.

3. How do I apply a filter to a signal in MATLAB?

To apply a filter to a signal in MATLAB, you can use the filter function. First, define your filter coefficients using the fir1 or fir2 functions. Then, pass in the filter coefficients and the signal you want to filter to the filter function. The function will return the filtered signal.

4. How do I generate a signal with specific frequency components in MATLAB?

To generate a signal with specific frequency components in MATLAB, you can use the fft function. First, define the desired frequency components as a vector. Then, use the ifft function to transform the frequency components into a time-domain signal. You can also use the cos or sin functions to create signals with specific frequencies.

5. How do I analyze the frequency content of a signal in MATLAB?

To analyze the frequency content of a signal in MATLAB, you can use the fft function. This will transform the signal into its frequency components. You can then use the abs function to get the magnitude of each frequency component and plot it using the plot function. Additionally, you can use the fftshift function to shift the zero-frequency component to the center for a more clear visualization of the frequency spectrum.

Suggested for: MATLAB - Fourier (how do I do this)

Replies
5
Views
919
Replies
4
Views
455
Replies
2
Views
1K
Replies
4
Views
2K
Replies
4
Views
2K
Replies
1
Views
1K
Replies
9
Views
2K
Replies
2
Views
2K
Replies
1
Views
869
Back
Top