Dft of cos function

  • Thread starter amaresh92
  • Start date
  • #1
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
 

Answers and Replies

  • #2
uart
Science Advisor
2,776
9
Hi amaresh92. Tell me what you know about the Nyquist sampling theorem.
 
  • #3
163
0
Hi amaresh92. Tell me what you know about the Nyquist sampling theorem.
dont know why it has to be true
 
  • #4
uart
Science Advisor
2,776
9
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
uart
Science Advisor
2,776
9
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
163
0
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 Threads on Dft of cos function

  • Last Post
Replies
5
Views
10K
  • Last Post
Replies
9
Views
2K
Replies
1
Views
8K
  • Last Post
2
Replies
29
Views
5K
  • Last Post
Replies
1
Views
6K
Replies
18
Views
5K
Replies
4
Views
2K
  • Last Post
Replies
1
Views
15K
  • Last Post
Replies
4
Views
1K
Replies
2
Views
10K
Top