DFT of sine wave

36 views (last 30 days)
Magdalena Bartoszek
Magdalena Bartoszek on 29 Apr 2020
Answered: Raunak Gupta on 3 May 2020
Hello,
I have to calculate the DFT of the following signals sampled at 32 kHz. Plot the magnitude, phase, real and imaginary parts of the DFT coefficients.
I know that to generate plots I have to use these functions: abs, angle, real, imag
I really could use some help.
The given signal is: x = sin(2pi*8000*t + pi/8), signal length: 8 samples
I am able to create function that would be without that 'pi/8' part, no idea how to add this to my function :/ ..
As far as I am concerned, the function without my problem looks like:
n=8
fs=32000
fsin=8000
A=1
df=(2*pi)
k=0: n-1;
x=A*sin((2*pi)*fsin.*k/fs + df);
X=fft(x);
fr=k*fs/n;
figure
subplot(312)
stem(fr, real(X))
title("real");
subplot(311)
stem(fr, imag(X))
title("imaginary")
But unfortunately I have no idea how to add the pi/8 part..
Thanks in advance for every hint..
  1 Comment
Sindar
Sindar on 30 Apr 2020
It looks like you have added the pi/8, what's the problem? Are you trying to write an analytic expression for the fourier components?

Sign in to comment.

Answers (1)

Raunak Gupta
Raunak Gupta on 3 May 2020
Hi,
It looks like ‘df’ in the above code can be set to ‘pi/8’ to represent time shift in original signal. Other than that everything looks fine.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!