About FFT of a wave

4 visualizaciones (últimos 30 días)
Daniel Wanesh
Daniel Wanesh el 30 de Dic. de 2021
Comentada: William Rose el 4 de En. de 2022
The code below is what I have to create a cos wave in the time domain. I was just wondering how I could go about using the fft function to convert it to the frequency domain.
Fm = 2*10^6;
Em = 4;
Wm = 2*pi*Fm;
t = 0 : 5.5*10^-7 : 1*10^-4;
Vm = Em.*cos(Wm*t);
subplot(3,1,1);
xm = t;
ym = Vm;
plot(xm,ym);
Many thanks in advance,
Daniel
  2 comentarios
Daniel Wanesh
Daniel Wanesh el 4 de En. de 2022
Thank you very much for your help
Very much appreciated
William Rose
William Rose el 4 de En. de 2022
You're welcome, @Daniel Wanesh. Good luck with your work!

Iniciar sesión para comentar.

Respuesta aceptada

William Rose
William Rose el 30 de Dic. de 2021
Editada: William Rose el 30 de Dic. de 2021
Fm = 2*10^6; Em = 4;
t = 0 : 5.5*10^-7 : 1*10^-4;
ym = Em.*cos(2*pi*Fm*t);
Ym=fft(ym); %compute the discrete Fourier transform by the FFT algorithm
Ym() is a complex array. To plot the magnitudes:
plot(abs(Ym));
To compute a frequency axis for the plot above:
Fs=1/5.5e-7; %use the constant above to compute sampling frequency
L=length(ym); %length of ym = length of Ym
f=Fs*(0:L-1)/L;
plot(f,abs(Ym)); xlabel('Frequency (Hz)'); ylabel('abs(Ym)');
Note the symmetry in the plot above. The FFT of a real sequence is conjugate-symmetric about the Nyquist frequency, where fNyquist=Fs/2. Therefore you may limit your plot frequency range to [0,fNyquist] without losing any meaningful information. You may wonder why the FFT is not zero at frequencies other than Fm. The answer is that your sequence does not wrap around smoothly. Also, Fm is not exactly one of the frequencies in the DFT. You can reduce the effect of the wrap-around by windowing the signal.
  2 comentarios
William Rose
William Rose el 30 de Dic. de 2021
Editada: William Rose el 30 de Dic. de 2021
I notice that your signal is badly aliased. By that I mean that the sampling interval, 5.5e-7, is too slow to accurately represent this sine wave, whose frequency is Fm=2x10^6.
Fm = 2*10^6; Em = 4;
t1 = 0 : 5.5e-7 : 1e-5; %the original sampling, which is not fast enough
y1 = Em.*cos(2*pi*Fm*t1);
plot(t1,y1,'-r*'); hold on; xlabel('Time (s)');
Try sampling the signal at a faster rate:
t2=0:5e-8:1e-5;
y2 = Em.*cos(2*pi*Fm*t2);
plot(t2,y2,'-b.');
The original sampling rate produces the red line signal above, which is obviously an incorrect representation of the signal.
William Rose
William Rose el 30 de Dic. de 2021
@Daniel Wanesh, you can repeat the plotting of the function, and the computation and plotting in the frequency domain, by using the new vector of times above. Compute Fs using the new sampling interval, before you re-compute the vector of frequencies for plotting.
With the new time vector, you will notice that the new FFT is almost exactly zero at frequencies other than Fm. This is because the signal wraps around almost perfectly from its end to its beginning, with the new time vector. It is not exactly perfect, because the final point is a repeat of the initial point.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by