help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

amplitude axis of frequency domain plot not matching question tia sal22


From: Rick T
Subject: amplitude axis of frequency domain plot not matching question tia sal22
Date: Wed, 9 Mar 2011 12:46:56 -1000

Greetings all 

I have a frequency domain plot that plots but the amplitude doesn't match 
the equation at all.  In the example I have the amplitude set to 8 but when I plot it the amplitude
shows up as 30+ why is this?

tia sal22

code below:
Fs = 1000;                    % Sampling frequency
t=linspace(0,1,1000);
vp_sig_orig=8*sin(2*pi*2*t)
vp_sig_len=length(vp_sig_orig); 


% Use next highest power of 2 greater than or equal to length(x) to calculate FFT.
nfft= 2^(nextpow2(length(vp_sig_orig))); 

% Take fft, padding with zeros so that length(fftx) is equal to nfft 
fftx = fft(vp_sig_orig,nfft); 

% Calculate the numberof unique points
NumUniquePts = ceil((nfft+1)/2); 

% FFT is symmetric, throw away second half 
fftx = fftx(1:NumUniquePts); 

% Take the magnitude of fft of x and scale the fft so that it is not a function of the length of x
mx = abs(fftx)/length(vp_sig_orig); 

% Take the square of the magnitude of fft of x. 
mx = mx.^2; 

% Since we dropped half the FFT, we multiply mx by 2 to keep the same energy.
% The DC component and Nyquist component, if it exists, are unique and should not be multiplied by 2.
if rem(nfft, 2) % odd nfft excludes Nyquist point
  mx(2:end) = mx(2:end)*2;
else
  mx(2:end -1) = mx(2:end -1)*2;
end

% This is an evenly spaced frequency vector with NumUniquePts points. 
freq_vect = (0:NumUniquePts-1)*vp_sig_len/nfft; 


% Generate the plot, title and labels. 
subplot(2,1,1),plot(t,vp_sig_orig)
title('Time domain plot'); 
xlabel('time'); 
ylabel('Power'); 

plot_len=1000;%length to plot
subplot(2,1,2), plot(freq_vect(1:end),mx(1:end))
title('Power Spectrum of vp'); 
xlabel('Frequency (Hz)'); 
ylabel('Power'); 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]