normalisation of frequency axis while using fft function in matlab

Hi all, As a part of my code, I have got a filtered array Va, which contains 45592 samples.What I need to do now is obtain the frequency spectrum of the signal which should have the major component as 50Hz. However, on applying plot(abs(fft(Va))), though I am getting 2 large peaks(i think a peak and its mirror image) at 2 points,I am not able to assess the X-axis scale.It is running from 0 to 50000.The peak I am getting is at approximately the 26th point and also the 45570th point.How do I adjust the x-axis so I can see the frequency component in Hz? Also, I am not sure about the sampling frequency, because the array is obtained using a m code after large number of iterations.Can somebody help?Thanks in advance.

 Accepted Answer

You must know frequency sampling, Fs . Look at this code:
Fs= ; % insert here your frequency sampling in Hz
L=length(Va);
NFFT = 2^nextpow2(L);
Y = fft(Va,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

6 Comments

Thanks, but I am still not able to put in the sample frequency because the array is generated using two for loops, one nested in other. The outer for loop runs from 1 to 501 and the loop nested in that runs from 1 to 90. The nested for loop running from 1 to 90 is responsible for generating the array.How to get the sampling frequency from this?
Fs - it cant be derived, you have to know it. This information is provided by DEVICE which digitalizes analog signal into its digital version. Where is your digital data taken from? Oscilloscope, WAV file?
Thanks Vieniava for the patient answers,please bear with me one more time.Let me explain you in detail what is going on.Initially,what I am doing is creating a sine wave of 500 samples.this is used one sample at a time as an input(this is all going on in the code btw)to determine another quantity in a for loop which runs for 501 iterations(i.e the total number of sine wave samples).However, in this loop is present another for loop which runs for 90 samples.Each value of the quantity calculated in the nested for loop is stored as the array which has to be filtered.So the total number of samples contained in the array becomes approximately 45000.This is all being done in the code itself.So how can I get the sampling frequency in this case? If it was a scope or other such..it was possible to directly set and thus get the sampling frequency.Here, all of this is being done inside the matlab code.This is the main problem for me
Paste the code defining your sine wave - it is important. We are close ;)
clear all
clc
close all
time=0:0.001:0.5;
Vm=230;
freq=50;
Va = Vm*sin(2*pi*freq*time);
Bulls eye! "time=0:0.001:0.5" that means your frequency sampling is 1/0.001 = 1000 Hz .

Sign in to comment.

More Answers (1)

What about the double-sided spectrum?
Thank you

Categories

Find more on Signal Processing Toolbox in Help Center and File Exchange

Asked:

on 11 Feb 2011

Community Treasure Hunt

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

Start Hunting!