Solving DFT of Cos Function Issue with MATLAB

In summary, the Nyquist sampling theorem states that we need to sample at least twice the highest frequency component of the signal in order to get accurate results. This problem is caused by the fact that your single sample at 100Hz is only sampling at 4 Hz.
  • #1
amaresh92
163
0
greetings,
i have typed some code in MATLAB to find the 5 point fft of cos function of frequency 100hz but in answer i am not geting the answer at 100 hz.may i know where the things going wrong. the code is as this one

clc;
t=0:1/4:1;
x=cos(2*pi*100*t);
xm=abs(fft(x));
disp(xm)
p=0:length(xm)-1;
subplot(2,2,1);
stem(100*p,xm);



the answer is
5 0 0 0 0


thanks in advance
 
Physics news on Phys.org
  • #2
Hi amaresh92. Tell me what you know about the Nyquist sampling theorem.
 
  • #3
uart said:
Hi amaresh92. Tell me what you know about the Nyquist sampling theorem.
dont know why it has to be true
 
  • #4
Ok. The problem is that your single is at 100Hz, but you are only sampling at at 4 Hz (4 samples per second). Sampling theory says that we have to sample at at-least twice the highest frequency component of the signal, so greater than 200 Hz in this case. What this means is that your "t" spacing must be less than 0.005.
 
Last edited:
  • #5
Hi amaresh92, if you want a simple 5 point example then try this code and see if the results make more sense. :smile:

Code:
n = 5                    # Specify the number of points to sample.
fs = 500                 # Specify the sample frequency.
dt=1/fs                  # Calculate the inter-sample interval.

t = [0:n-1]*dt           # Create the sample vector.
x = cos(2*pi*100*t)      # Create the signal vector.
xm = abs(fft(x))         # Compute the fft magnitude.

df = fs/n                # Calculate the frequency increment of the fft.
ascale = n/2             # Amplitude scale factor.

                         # Plot fft magnetude. Note "reflection" about fs/2.
plot([0:n-1]*df,xm/ascale,'*')
 
Last edited:
  • #6
uart said:
Ok. The problem is that your single is at 100Hz, but you are only sampling at at 4 Hz (4 samples per second). Sampling theory says that we have to sample at at-least twice the highest frequency component of the signal, so greater than 200 Hz in this case. What this means is that your "t" spacing must be less than 0.005.

thanks a lot
 

Related to Solving DFT of Cos Function Issue with MATLAB

1. What is DFT and why is it important in solving the cos function issue in MATLAB?

DFT stands for Discrete Fourier Transform and it is a mathematical tool used to convert a signal from its original domain (often time or space) to a representation in the frequency domain. It is important in solving the cos function issue in MATLAB because it allows for accurate analysis and manipulation of signals, particularly in cases where the signal is not periodic or has discontinuities.

2. What is the cos function issue in MATLAB and how does DFT help in solving it?

The cos function issue in MATLAB refers to the problem of accurately representing a non-periodic or discontinuous signal using the built-in cos function. This can lead to errors and inaccuracies in data analysis. DFT helps in solving this issue by transforming the signal into the frequency domain, where it can be analyzed and manipulated more accurately.

3. Can DFT solve the cos function issue in all cases?

No, DFT is not a universal solution for the cos function issue in MATLAB. It is most effective in cases where the signal is not periodic or has discontinuities. In some cases, using alternative approaches such as interpolation or curve fitting may be more appropriate.

4. Are there any limitations or drawbacks to using DFT in solving the cos function issue?

One limitation of DFT is that it is a discrete method, meaning that the signal must be sampled at specific points in time or space. This can lead to errors if the sampling rate is too low or if the signal is not properly aligned with the sampling intervals. Additionally, DFT may not be suitable for real-time analysis as it requires processing of the entire signal before producing results.

5. Are there any alternatives to using DFT for solving the cos function issue in MATLAB?

Yes, there are alternative methods for solving the cos function issue in MATLAB, such as using other trigonometric functions like sine or tangent, or using interpolation techniques. It is important to carefully consider the characteristics of the signal and the specific requirements of the analysis before deciding on a method.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
584
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Programming and Computer Science
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
137
Back
Top