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.

How to view the frequency contents of a signal in MATLAB?

Status
Not open for further replies.

usman

Junior Member level 3
Joined
Aug 4, 2005
Messages
27
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,281
Activity points
1,502
Hi, if i have a signal or composite signal, how can i view its frequency contents in MATLAB, i used fft but i am not satisfied with the result.
 

plot frequency in matlab

hey fft gives peaks @ the frequencies which r present in the signal. wat didn't satisfy you.does the signal consists of so many frequencies tat u were not convenient visualizing it.
 

windowed short time fouire transform

If you are seeing energy at frequencies that you didn't expect, try applying a "window" to the data before performing the FFT. If you don't know what that is, refer to MATLAB help, or any book on digital signal processing.
 

Re: frequency in MATLAB

Try this simple example

pulse in time --> sinc in freq

working fine for any pulse of width <100

function []=fourier(m)
x=[ones(1,m),zeros(1,100-m)];

X=fft(x);
f=-50:1:49;
figure;plot(f, fftshift(abs(X))), grid
 

frequency in MATLAB

the output of fft is the "true" frequency of the signal, for there is a tradeoff between the time resolution and frequency resolution. If you want the frequency setting in the generator of the signal, you need to design a special way based on the properties of the signals.
 

Re: frequency in MATLAB

if your sampling frequency is Fs and if u r taking an N pt FFT, then ur frequency resolution is Fs/N. so if u r not satisfied with ur resolution try Zero padding the signal to make it large in samples or simply collect more samples before taking FFT.
 

Re: frequency in MATLAB

AOA!
my question is very simple. let me reexplain agian.
i have 3 signals of frequencies: f1=100HZ, f2=150hz, f3=50 hz. and added all the three sinosoids to get a composite signal.
now i want to plot the composite signal in frequency domain to see the frequency contents in the it.

regards,
 

frequency in MATLAB

That's a much clearer question. ;)

Try this:
Code:
N  = 1000;      % number of points
fs = 1000;      % sample rate
f1 = 100;       % signal 1 frequency
f2 = 150;       % signal 2 frequency
f3 = 50;        % signal 3 frequency
a1 = 2.3;       % signal 1 amplitude
a2 = 1.5;       % signal 2 amplitude
a3 = 1.1;       % signal 3 amplitude
t = (0 : N-1) / fs;
y = a1 * cos(2*pi*f1*t) + a2 * cos(2*pi*f2*t) + a3 * cos(2*pi*f3*t);
h = fft(y);
% Discard duplicate upper half. Scale frequency and amplitude.
freq = fs * (0 : N/2) / N;
plot(freq, 2 / N * abs(h(1 : N/2+1))); xlabel('Hertz');
 

frequency in MATLAB

perhaps you could use short time fouire transform or wavelet transform
 

Re: frequency in MATLAB

When you try the above example you should know that N must be a power ot two for example 1024. Otherwise the fft function is computationally ineffective.
If you make N=1024 in the above example you probbbably will be unsatisfied :). you will seee not just peakse but slopes around them also since the signal period is not multiple of the window length (N). Therefore you need a carefull selection of N according to the signal frequencies and the neccessary resolution
 

frequency in MATLAB

Yes, a 1024 point FFT is about twice as fast as a 1000 point FFT.
You can change both N and fs to 1024. The plot will be similar, but with a max freq of 512 Hz.
 

Re: frequency in MATLAB

Hey,you must map of the samples on to the 0 2*pi interval then by using the sampling frequency you can fin the frequency content which has peak.Don't forget that sampling frequency is equal to pi in discrete case.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top