Two-side spectrum in Matlab

72 visualizaciones (últimos 30 días)
Hoang
Hoang el 3 de Nov. de 2013
Comentada: Joao Nizer el 2 de Jul. de 2021
Dear my colleagues, I am a new user of Matlab. Now, I have a signal like x(t) = A1*sin(2*pi*f1*t) + A2*sin(-2*pi*f2*t), where f1, f2>0. Could anyone please show me whether I could obtain the spectrum of x in which frequency f2 is present only as a negative frequency of two-side spectrum (normally, f2 will appear in both sides of Matlab's FFT)?
Thank you very much.
Lomath.

Respuesta aceptada

Wayne King
Wayne King el 3 de Nov. de 2013
Editada: Wayne King el 3 de Nov. de 2013
Youssef is correct. Why do you think that f2 will only show up as a "negative" frequency.
sin() is an odd function so sin(-t) = -sin(t)
Accordingly, your signal is equal to
Fs=40;
Ts=1/Fs;
t=0:Ts:10-Ts;
f1=4; f2=15;
y=sin(2*pi*t*f1)-sin(2*pi*t*f2);
If you really want components only occurring on one side, your signal must be complex-valued. Here is an example with complex exponentials.
Fs = 40;
Ts=1/Fs;
t=0:Ts:10-Ts;
f1 = 4; f2 = -15;
y = exp(1i*2*pi*f1*t)+exp(1i*2*pi*f2*t);
ydft = fftshift(fft(y));
df = Fs/length(y);
freqvec = -Fs/2+df:df:Fs/2;
plot(freqvec,abs(ydft))
xlabel('Hz');
  2 comentarios
Hoang
Hoang el 3 de Nov. de 2013
Thanks. Sorry for the poor example. It is great if you could give me another example, pls. In my knowledge, function x = A1*cos(2*pi*f1*t)+ A2*cos(2*pi*f2*t), where f1>0, f2<0, can be used to express a rotating signal where the first term rotates in forward direction and the other rotates in backward direction. Can it be analyzed in some ways to separate f1 and f2, pls?
Joao Nizer
Joao Nizer el 2 de Jul. de 2021
freqvec = -Fs/2+df:df:Fs/2;
should be
freqvec = -Fs/2:df:Fs/2-df;

Iniciar sesión para comentar.

Más respuestas (1)

Youssef  Khmou
Youssef Khmou el 3 de Nov. de 2013
You can start by many tutorials, each offers a different approach to the DFT problem, in terms of resolution and amplitude estimation, i wrote a 2 sided example for you , verify it :
Fs=40;
Ts=1/Fs;
t=0:Ts:10-Ts;
f1=4;f2=15;
y=sin(2*pi*t*f1)+sin(2*pi*t*f2);
N=length(y);
F=fft(y);
fr=(-N/2:N/2-1)*Fs/(N);
figure, plot(fr,abs(F))
xlabel(' frequency Hz')
  4 comentarios
Hoang
Hoang el 3 de Nov. de 2013
Thank you for your explanation.
Renan Ribeiro
Renan Ribeiro el 15 de Oct. de 2018
Sorry to revive the post, but the given code did not work with me (maybe I am messing something). The code given in this post worked just fine.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by