Can i plot spectrum of a signal in Matlab
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
moonman
el 1 de Oct. de 2011
Comentada: Amna
el 12 de Oct. de 2023
I want to plot spectrum diagram which gives the frequency content of a signal x(t) for example if i draw spectrum of x(t) = 14 cos(200*pi*t -pi/3)
by hand it will be two arrows at -100 and +100 with values 7e^(jpi/3) and 7e^(-jpi/3)
Can some software or matlab can do this for me
0 comentarios
Respuesta aceptada
Wayne King
el 1 de Oct. de 2011
Fs = 1000;
t = 0:1/Fs:1-(1/Fs);
x = 14*cos(200*pi*t-pi/3);
xdft = (1/length(x))*fft(x);
freq = -500:(Fs/length(x)):500-(Fs/length(x));
plot(freq,abs(fftshift(xdft)));
2 comentarios
Wayne King
el 1 de Oct. de 2011
Your frequency above is actually 100 Hz (2*100*pi*t). You have not given the sampling rate, so I just assumed 1000 Hz here.
Amna
el 12 de Oct. de 2023
Can anyone plz explain what will be the spectrum of j*cos(2*pi*10*t) , j*exp(-j*2*pi*10*t),
-j*exp(-j*2*pi*10*t) and -j*cos(2*pi*10*t) ?? please plot them i'm not asking for magnitude plot show me actual plots please help.
Más respuestas (6)
moonman
el 1 de Oct. de 2011
2 comentarios
Wayne King
el 1 de Oct. de 2011
Yes, 200 is right, but I would sample at least a bit more than that, 200 would put the 100 Hz component right at the Nyquist. I would avoid that.
Not sure exactly what you're asking in the 2nd, you should sample based on the bandwidth of your signal, which is 2000 Hz here (you have a component at -1000 and 1000) so 1000-(-1000)=2000. You have to sample at least at the bandwidth (2 kHz).
Wayne King
el 1 de Oct. de 2011
sorry I misread above-- your bandwidth is 1 kHz (500-(-500))=1000. I misread the frequency as (2*1000*pi) instead of (1000*pi). you have to sample at least at the bandwidth. (1 kHz).
moonman
el 1 de Oct. de 2011
1 comentario
Wayne King
el 1 de Oct. de 2011
Oh sorry! yes, for some reason, I read 2*pi*1000 in your first post, you are right. it's 500 Hz so it has to be sampled at a minimum of 1 kHz.
moonman
el 1 de Oct. de 2011
2 comentarios
Wayne King
el 1 de Oct. de 2011
The factor your refer to is the phase, you can get that by plotting the angle() (but that tends to be messy unless you unwrap it which is another matter), or you can query it directly. For example, xdft(101) corresponds to the DFT bin for 100 Hz in the example I gave you. Because the bins are spaced at Fs/length(x) with the first bin corresponding to zero frequency, DC. If you query
angle(xdft(101))
you get -1.0472, which is -pi/3
Wayne King
el 1 de Oct. de 2011
as far as your multiplication problem, use the .* operator
x = cos(1000*pi*t+pi/3).*(sin(500*pi*t+pi/4));
2 comentarios
Wayne King
el 1 de Oct. de 2011
That is because you changed the sampling frequency, in your frequency vector
freq = -2000:(Fs/length(x)):2000-(Fs/length(x));
Your frequency vector is set up for a 4000 Hz sampling rate. However you left
Fs = 1000;
So your sizes are not correct.
Also you are creating a modulated signal above, so you have to think about what the spectrum of that signal is. That is different than just adding components.
Fs = 4000;
t = 0:1/Fs:1-(1/Fs);
x = cos(1000*pi*t+pi/3).*(sin(500*pi*t+pi/4));
xdft = (1/length(x))*fft(x);
freq = -2000:(Fs/length(x)):2000-(Fs/length(x));
plot(freq,abs(fftshift(xdft)));
0 comentarios
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!