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.

Matlab, How to get frequency spectrum?

Status
Not open for further replies.
plot frequency matlab

Use psd(x) function.
 

plotting spectrum in matlab

claudiocamera said:
eg Yn=abs(fftshift(fft(y,n)))/N where N is the number of points of the signal and n >N is the number of points of the DFT ( n-N is zero padding).

Why are we dividing by N??

If you could please explain.
 
  • Like
Reactions: cili

    cili

    Points: 2
    Helpful Answer Positive Rating
how to plot spectrum in matlab

fft is command to see spectrum plot it against frequency
 

fft matlab spectrum

I understand that FFT is for plotting in the Frequency domain.. but why are we "Dividing by N"??

Added after 1 minutes:

zhenyabb said:
in MatLab help is good example for fft,

roughly output spectrum in dB is:
20log10(abs(fft(sin(2*pi*fc*tt))))

in this case the amlitude is 2 peak-to-peak that corresponds 10 dBm(at)50 Ohm for sine signal with amplitude 2Vp-p. MatLab shows power 0dB(at)fc

Can somebody say how take into account this 50 Ohm output impedance to get proper power?


Did anyone get an answer to this.. please??
 

signal spectrum matlab

Hi to every body

realy this forum is very good

such discussions are very useful

thanks to all the replyers
 

Re: fourier spectrum matlab

starfish said:
I am uploading 2 PDF files on Fourier Transform / Spectrum calculation and display in Matlab. I used it for the lab of DSP.

You can also use the below function for displaying the frequency spectrum in MATLAB. As "N" the number of points for fft increases the spectrum becomes more accurate to the theoratical values.

Here 'signal' is the data vector for which u want to see the frequency spectrum. 't' is the time vector for which the signal exists , 'ts' is the sampling time , 'N' is the number of fourier transform points.

function[freq,mag]=fouriertransform(signal,t,ts,N);
S=fft(signal,N);
CS=[S(N/2+1:N) S(1:N/2)];
freq=[-N/2+1:N/2]/(N*ts);
mag=abs(CS);
figure;
plot(freq,mag);

hi,
I want to get FFT from non-stationary wave. I know that I should use data window.
I've wrriten a code for it but I don't know my code is correct or not?
please help me
 

Re: fourier spectrum matlab

tavakoliahmad said:
hi,
I want to get FFT from non-stationary wave. I know that I should use data window.
I've wrriten a code for it but I don't know my code is correct or not?
please help me

see this post


scroll down to see it
 

Re: plotting spectrum in matlab

shabzbd said:
claudiocamera said:
eg Yn=abs(fftshift(fft(y,n)))/N where N is the number of points of the signal and n >N is the number of points of the DFT ( n-N is zero padding).

Why are we dividing by N??

If you could please explain.

In the mathematical formulation of the DFT, we use <refer figure 1>

This expression can also be written in terms of a DFT matrix; when scaled appropriately it becomes a unitary matrix and the DFT signal (Xk) can thus be viewed as coefficients of input signal (x) in an orthonormal basis.

And the inverse is given as, <refer figure 2>

Where "N" is the total number of samples in the DFT signal. If length the time-domain signal is less than N, it's zero-padded and if it's more, it's truncated.

Hope it helps.
 

Thanks for all your replies. I have tried doing the same for the set of data that I have got but with no use. I have got a data file that contains 2500 points of amplitude against time which I am trying to find the FFT of. Since its a 5MHz signal, I am expecting to see the peak magnitude at around 5MHz, but I am not! Been fiddling around for a couple of weeks now.

data=dlmread('inputm.txt','\t'); % to input the points in the file column 1 being time and column 2 being for the corresponding amplitude.
time=data:),1);
vdata=data:),2);
X=fft(vdata);
M=abs(X);
f0=5000000; % This is the fundamental frequency.
f=f0*(0:length(X)-1);
figure;
clf;
plot(f(1:(length(f))),M(1:(length(M))))

Can anyone help - Basically I have got data which when plot will give a signal - I need to find the FFT of this signal and verify that the peak magnitude is at 5MHz ( although its not expected for it to be exactly at 5 maybe 4.89 or so). Thanks.

Added after 46 minutes:

I have also tried this code to get the amplitude spectrum, but I would still get the magnitude at the wrong frequency when I am suppose to get it around 5MHz.

clear;
clc;
s=importdata('echo1.txt');
z=s.data;
Y=z:),2);
y=fft(Y)
figure(1), plot(y)
figure(2),plot(y,'ro')
grid on
xlabel('Real number')
ylabel('Imaginary')
title('FFT of Signal')

n=length(y)
power=abs(y(1:floor(n/2))).^2
nyquist=1/2
freq=((1:n/2)/(n/2)*nyquist)*5000000
figure(3), plot(freq,power)

xlabel('Frequency')
ylabel('Power')
title('Power Spectrum of Signal')
grid on


amp=abs(y(1:floor(n/2)))
figure(4), plot(freq,amp)
xlabel('Frequency')
ylabel('Amplitude')
title('Amplitude Spectrum of Signal')
grid on

Added after 27 minutes:

I have also tried this code to get the amplitude spectrum, but I would still get the magnitude at the wrong frequency when I am suppose to get it around 5MHz.

clear;
clc;
s=importdata('echo1.txt');
z=s.data;
Y=z:),2);
y=fft(Y)
figure(1), plot(y)
figure(2),plot(y,'ro')
grid on
xlabel('Real number')
ylabel('Imaginary')
title('FFT of Signal')

n=length(y)
power=abs(y(1:floor(n/2))).^2
nyquist=1/2
freq=((1:n/2)/(n/2)*nyquist)*5000000
figure(3), plot(freq,power)

xlabel('Frequency')
ylabel('Power')
title('Power Spectrum of Signal')
grid on


amp=abs(y(1:floor(n/2)))
figure(4), plot(freq,amp)
xlabel('Frequency')
ylabel('Amplitude')
title('Amplitude Spectrum of Signal')
grid on
 

Hi guys

Can someone give me a solution?

I want to see frequency and Power spectrum of the following:

1. Bandwidth - 890 MHz - 960 Mhz
2. Channel Bandwidth - 200 KHz
3. Carrier Seperation - 250 Khz
4. Input - NRZ data

I tried with three carrier frquencies within the range ie 890 MHz, 890.45 Mhz and 890.9 MHz. i faced the following problem:

1. Matlab takes a long time to work in MHz range.
2. Carrier seperation is so small that the spectrum overlaps and can't be differentiated.

plz someone help me with the coding.

thnx in advance.

shaz
 

hi guys

i am badly in need of the solution, but still no reply. guys plz help me. thnx in advance.

shaz
 

Dear fraizer,

Lets try a simple approach

Say your data is recorded after every 0.2 seconds (lets call this as T; time step)
>> T=0.2

Say you have 60,000 recordings of data ( lets call this N=60000)
>> N=60000

Now imagine an index say n which goes from 0 to N-1, or from 1 to N, your choice
>> n=(0:N-1)

Next we calculate the frequency (this is the range from -fc to +fc; where fc is the critical or Nyquist frequency. This Nyquist frequency is computed as Fc=1/(N*T). However, we are concerned with the frequency range which should go from n times fc. Basically half the signal, the other half will be the same)
>> fn=n/(N*T)

Next read the data file (you only need the recordings data column, say its stored in xFunction)
Now DFT or as Matlab says FFT is simple
>> fft(xFunction)


To plot, you should use the log-log scale to makes things more pronounced
>> loglog(fn,abs(ans), 'Displayname','ans');figure(gcf)

Just for the record you can computed the Spectrum simply by FORTRAN or C code by adding the Cosine and Sine components of each frequency for all the data, see Numerical Recipes (FORTRAN) the art of Scientific computing by Press et al). Hope this helps.
 

Re: spectrum in matlab

to see frequency response, we need to keep input fix suppose vin =1 and very the frequency. and then get the corresponding output
now i get say output vector and input vector,

Suppose i have out vector B and input vector A

TF = fft(B,j-1)./ fft(A,j-1);

now in order to plot magnitide plot ... is it ok to do mag = abs(TF) ??

is my approach right?
 
Last edited:

Plotting absolute value of the magnitude of fft results variation of amplitude with respect to length of fft. I want to observe the actual amplitude of different frequency component of a periodic signal in frequency domain plot. How can I do this in matlab?
 

I got the attached plot using matlab fft -
Code:
Code:
Fs=150;
t=0:1/Fs:1;
f=5;
x=square(2*pi*f*t);

nfft=1024;
X=fft(x,nfft);
X=X(1:nfft/2);

xt=abs(X);
f=[0:nfft/2-1]*Fs/nfft;
subplot(2,1,1);
plot(t,x);
subplot(2,1,2);
plot(f,xt);
sqfft.jpg

- - - Updated - - -

I want to see the actual amplitude of all the frequency components (fundamental frequency and harmonics).
 

how would you plot this Fourier series on mathlab
V(t)= A/10+∑(n=1(2A/npi(sin (npi)/10)) cos2pi (nf0)t

what would be the signal using the first 4 harmonics assuming A= 2V.
also the signal using the first 8 harmonics assuming A= 2V.
 

Re: frequency plot matlab

Please let me show the principle,
for two-sided fft,
f= -Fs/2 : Fs/N : Fs/2-Fs/N
because [ (Fs/2-Fs/N) - (-Fs/2) + Fs/N ] / (Fs/N) = N (equal to the number of points in fft)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top