Frequency spectrum for a square pulse help?

17 visualizaciones (últimos 30 días)
Jonathan
Jonathan el 27 de Nov. de 2013
Editada: Azzi Abdelmalek el 27 de Nov. de 2013
I need to plot the frequency spectrum for a square wave using MATLAB. The wave is HIGH (5mV) between 0 and -2 and LOW (omv) between 0 and 2. I have already obtained the fourier seires for this function and i have the first ten components of the series.
(5/2) + ((10/pi)*sin((pi*t)/2)) + ((10/(3*pi))*sin((3*pi*t)/2)) + ((10/(5*pi))*sin((5*pi*t)/2)) + ((10/(7*pi))*sin((7*pi*t)/2))+ ((10/(9*pi))*sin((9*pi*t)/2))+ ((10/(11*pi))*sin((11*pi*t)/2))+ ((10/(13*pi))*sin((13*pi*t)/2))+ ((10/(15*pi))*sin((15*pi*t)/2))+ ((10/(17*pi))*sin((17*pi*t)/2))+ ((10/(19*pi))*sin((19*pi*t)/2))
How do I plot the frequency spectrum for this wave using MATLAB? I have tried using FFTs, but I really don't know how it works to plot the graph. I end up with the frequencies peaks at the right points, but with wrong amplitudes. Please help

Respuestas (1)

Image Analyst
Image Analyst el 27 de Nov. de 2013
Assuming your series is correct, then plotting the coefficients [5/2, (10/pi), (10/(3*pi)), etc.] should give you the same shape as if you plotted the magnitude of the spectrum you get from the fft() function. Did you do that? Do you want to attach your script for further help?
  1 comentario
Jonathan
Jonathan el 27 de Nov. de 2013
You mean by just plotting the points I need like a scatter plot? I tried using FFTs though I just started learning about them by myself and really don't know what I'm doing. I built it using various sample codes online. I get the peaks at the right places, but the amplitudes are off
t= 0:0.001:10
a = (5/2) + ((10/pi)*sin((pi*t)/2)) + ((10/(3*pi))*sin((3*pi*t)/2)) + ((10/(5*pi))*sin((5*pi*t)/2)) + ((10/(7*pi))*sin((7*pi*t)/2))+ ((10/(9*pi))*sin((9*pi*t)/2))+ ((10/(11*pi))*sin((11*pi*t)/2))+ ((10/(13*pi))*sin((13*pi*t)/2))+ ((10/(15*pi))*sin((15*pi*t)/2))+ ((10/(17*pi))*sin((17*pi*t)/2))+ ((10/(19*pi))*sin((19*pi*t)/2))
figure(1); plot(t,a); title('Square Wave') xlabel('Time (ms)') ylabel('Voltage (mv)')
Fs = 1000; %// Sampling frequency
T = 1/Fs; %// Sample time
L = length(a); %// Length of signal
t2 = (0:L-1)*T; %// Time vector
NFFT = 2^nextpow2(L); %// Next power of 2 from length of x
Y = fft(a,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
figure(2);
plot(f, abs(Y(1:NFFT/2+1)))
axis([0, 5 0, 3]) title('Frequency Spectrum') xlabel('Frequency (Hz)') ylabel('Power')

Iniciar sesión para comentar.

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!

Translated by