Can somebody trace my error in this solution of spectrum

2 visualizaciones (últimos 30 días)
I have found the frequency spectrum of signal x=(4+cos(1000*pi*t+pi/3)).*(sin(500*pi*t+pi/4))
There is slight difference in my hand calculation amplitude and amplitude by Matlab. By me, the amplitude at 250 Hz is 2 and by Matlab it is 1.8
My solution is attached here
The matlab code is here
Fs = 2000;
t = 0:1/Fs:1-(1/Fs);
x=(4+cos(1000*pi*t+pi/3)).*(sin(500*pi*t+pi/4));
%x=(4+cos(40*pi*t)).*(cos(200*pi*t-pi/2));
%x=cos(pi*t).*(sin(10*pi*t));
xdft = (1/length(x))*fft(x);
freq = -1000:(Fs/length(x)):1000-(Fs/length(x));
plot(freq,abs(fftshift(xdft)))
xlabel('Freq(Hz)-------->')
ylabel('Amplitude')
Kindly tell me abt my error
and more thing, if at two points, we have freq component, what happen to them, are they added or the lower one is merged in it

Respuesta aceptada

Wayne King
Wayne King el 2 de Oct. de 2011
If a negative term appears associated with a single frequency, like say
-2*exp(1j*pi/4) that has no impact on magnitude that is just a pi phase shift.
-2*exp(1j*pi/4) = 2*exp(1j*pi/4-pi) % or +pi
remember exp(1j*pi) = exp(-1j*pi) = -1
where it did make a difference is when you had terms that had the same frequency because as you saw you ended with a magnitude you didn't expect.
Remember a magnitude is real-valued and non-negative.
  1 comentario
moonman
moonman el 2 de Oct. de 2011
I really appreciate you Wayne King,
U r really professional engineer who is expert in all areas.
Thanks a lot for giving detailed description to all of my queries

Iniciar sesión para comentar.

Más respuestas (7)

moonman
moonman el 2 de Oct. de 2011
Can anybody help me here
  1 comentario
Walter Roberson
Walter Roberson el 2 de Oct. de 2011
When you are posting and hoping for a fast response, it is best if you keep in mind the time and date it would be in North America. The majority of the people who volunteer to answer MATLAB questions are in eastern United States, which is GMT-0500 during the winter, GMT-0400 during the summer, and two of the more frequent volunteers are one timezone further over, GMT-0600 during the winter, GMT-0500 during the summer. When you post at 0930 UTC, that is only 0530 in the eastern US in summer, 0430 for those two volunteers. On what, to them, is a Sunday. If you manage to get anyone in those two timezones at all on a Sunday morning, they would either be just barely awake from letting the dog out, or very tired from having stayed up all night.
There _are_ some volunteers in western Europe who answer, but most of them do things with their families on Sunday mornings.

Iniciar sesión para comentar.


Sim
Sim el 2 de Oct. de 2011
You forgot to add the red-underlined terms.

moonman
moonman el 2 de Oct. de 2011
I dont think we have to add them even if we add, then answer at one side will be 2.25 and other will be 1.75 which will be wrong
some expert plz help me out
  4 comentarios
moonman
moonman el 2 de Oct. de 2011
If we add
2*(exp(j*pi/4))-.25*(exp(j*pi/12)) in matlab
it gives answer as
1.1727 + 1.3495i
It is again not matching with discussed quantity that is 1.78
Sim
Sim el 2 de Oct. de 2011
What you have is the phasor (a complex vector). Its length is abs(1.1727 + 1.3495i) = 1.7878. When you plotted your fft, you plotted the magnitude: abs(fftshift()). So you get the length of the phasors.

Iniciar sesión para comentar.


Wayne King
Wayne King el 2 de Oct. de 2011
The sine terms at 250 Hz interact such that the magnitude of the sum is not 2 (when you look at the two-sided spectrum).
What you end up with at that frequency is
4*sin(2*pi*250*t+pi/4)-1/2*sin(2*pi*250*t+pi/12)
If you look at the magnitude spectrum of that:
Fs = 4e3;
t = 0:1/Fs:1-(1/Fs);
x = 4*sin(2*pi*250*t+pi/4)-(1/2)*sin(2*pi*250*t+pi/12);
xdft = (1/length(x))*fft(x);
freq = -2000:(Fs/length(x)):2000-(Fs/length(x));
plot(freq,abs(fftshift(xdft)))
xlabel('Freq(Hz)-------->')
ylabel('Amplitude')
max(abs(fftshift(xdft)))
You see where the magnitude comes from.

moonman
moonman el 2 de Oct. de 2011
ok thanks, just make one last point clear if we have two freq components at one location, the way i am having at 250 Hz in attached file, should i show single bar of 1.8 magnitude or i should show two bars with different colors at 250Hz and and -250 Hz so total of 4 bars
Can i have j term in magnitude I mean 2j exp(j*pi/4)
  1 comentario
Wayne King
Wayne King el 2 de Oct. de 2011
I think that is misleading because the two terms interact. Remember the triangle inequality: for complex number z and w |z+w| <= |z| + |w|.
What you have is |z+w|
You only have one frequency term at that point in the spectrum. Take an extreme case: imagine I have a cos(omega *t) and cos(omega*t-pi) and I add them together. Does it make sense to show 2 amplitudes of 1/2 at -omega and omega?

Iniciar sesión para comentar.


moonman
moonman el 2 de Oct. de 2011
Ok thanks and what abt this
Can i have j term in magnitude I mean 2j exp(j*pi/4)
  3 comentarios
Wayne King
Wayne King el 2 de Oct. de 2011
No, j is the unit imaginary so that cannot appear in the magnitude. The magnitude of any complex number is purely real, j is the number 0+j or (0,1) if you want to think of a complex number as an ordered pair of real numbers.
j is always associated with phase. In fact, you can write:
2*j exp(j*pi/4) = 2*exp(j(pi/4+pi/2))
Test this in MATLAB:
isequal(2*1j*exp(j*pi/4),2*exp(1j*3*pi/4))
in both cases the magnitude is just 2.
Sim
Sim el 2 de Oct. de 2011
**well, I made a typo in my answer, and just to corroborate what wayne said, in the exponential, I should have written j*pi/4+j*pi/2, not j*pi/4+j*pi.

Iniciar sesión para comentar.


moonman
moonman el 2 de Oct. de 2011
ok thanks and what about the minus terms which i get while solving the questions by hand. u can see in above attached file, there are three terms among the six underlined terms which are having negative sign
what is impact of this negative sign while plotting spectrum

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by