Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help!!! precise spectrum analysis using Matlab

Status
Not open for further replies.

yujun61hugh

Newbie level 2
Newbie level 2
Joined
Mar 5, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
how to calculate spectrum analysis in matlab

I need to get the precise spectrum component of the signal I generated in Matlab Simulink. The code i use now is shown as
Fs = 2e6; % Sampling frequency
T = 1/Fs; % Sample time
L = 2000000; % Length of signal
y = output(2001:(L+2001),2)';
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2);
plot(f,2*abs(Y(1:NFFT/2)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

Basicly, I simulate the system for 1.001 sec. and take the last 1s data to do FFT.
However, when I test this code using an ideal sin wave with frequency 1K Hz and amplitude equal to 1. the FFT result shows that at the 1K Hz, the signal component is only 0.75. who could tell me the reason and how to improve the code. Thanks a lot.

Added after 7 minutes:

I upload the spectrum figure here.
 

linspace fft

Why are you lusing this line ???
y = output(2001:(L+2001),2)'; esp output???? (where is the sinuisoidal signal instead)

also, simulate the system for 1.001 sec.??? Y not simulate exactly for 1 sec.
because,the exact number of cycles of the "x"Hz sine wave that occur in the no. of
samples i/p signal should be an integer. for getting the proper spectrum.



another point : in the code you used

f = Fs/2*linspace(0,1,NFFT/2);

just use f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2)+1)) to plot the single sided spectrum.


if U have further doubt hen vsist the folowing site:

www.mathworks.com
in the search engine type fft, see documentation details.
also visit
www.mathworks.com/support/tech-notes/1700/1702.html
www.mathworks.com/support/tech-notes/1700/1703.html
www.mathworks.com/support/tech-notes/1700/1704.html


Happy learning
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top