Sign in

username:

password:



Not a member?

Search matlab



Search tips

Subscribe to matlab



matlab by Keywords

Atanh | Autocorrelation | Bandpass Filter | C++ | Conv | Database | Deconv | Excel | FFT | Filter | Filtering | FIR | Fourier Transfrom | FSK | Gaussian Noise | Haykin | IFFT | Image | Java | LFSR | LMS | LPC | MEX | OFDM | QPSK | Radix | Random | Sampling | Segmentation | Simulink | Visual Basic | Waveform | Wavelet

Sponsor

NEW! TMS320C6474: 3x the performance. 1/3 the cost. Three 1 GHz cores on 1 chip.

Discussion Groups

Discussion Groups | Matlab DSP | Need help on FFT error msg

Technical discussion about Matlab and issues related to Digital Signal Processing.

  

Post a new Thread

Need help on FFT error msg - haiz...@yahoo.com.sg - Mar 17 18:18:21 2008



Hi everyone

Tried to write the program for the following question and got the error msg. Appreciate
anyone's help please! Thanks.

QUESTION
A signal is represented by the expression:

f(t) = 10 sin (1.5t) + 5 sin (2.5t) + 2.5 sin (5t) + 1.25 sin (10t)

Use MATLAB to obtain a spectrum (magnitude only) of the signal reconstructed from the sampled
signal if the sampling frequency is:

a)    5 Hz

PROGRAM
>> H=5;
>> N=1024;
>> n=[0:N/2-1];
>> t=0:10;
>> w=2*pi*H/N*n;
>> f=10*sin(1.5*t)+5*sin(2.5*t)+2.5*sin(5*t)+1.25*sin(10*t);
>> Fd=fft(f);
>> plot(w,abs(Fd(1:N/2))/H);

??? Index exceeds matrix dimensions.


(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Need help on FFT error msg - Sameer Herlekar - Mar 18 12:43:52 2008

To plot any kind of graph you need every x-axis value to possess a
corresponding y-axis value. The error is because your y-axis argument
in the command 'plot' attempts to access 512 elements of Fd when there
are only 11 elements in Fd. If you replace the line Fd=fft(f);

with the instruction
Fd=fft(f,N/2);

you will no longer have the error. But I don't think that is what
you're looking for. You can just use ordinary sampling theory which
requires that you replace the parameter 't' in the signal 'f' with the
parameter n/H. You can compute an FFT of length equal to the length of
the vector 'n'. Keep in mind that a sampling frequency of H Hz implies
that only frequencies upto H/2 can be represented uniquely. Hope the
following code works for you:

H=5;
N=1024;
n=[0:N/2-1];
f=10*sin(1.5*(n/H))+5*sin(2.5*(n/H))+2.5*sin(5*(n/H))+1.25*sin(10*(n/H));
Fd=fft(f,N/2);
plot((n(1:N/4)/(N/4))*(H/2), abs(Fd(1:N/4)))
xlabel('Frequency (Hz)'); ylabel('Magnitude')
On Mon, Mar 17, 2008 at 7:48 AM,  <h...@yahoo.com.sg> wrote:
> Hi everyone
>
>  Tried to write the program for the following question and got the error
> msg. Appreciate anyone's help please! Thanks.
>
>  QUESTION
>  A signal is represented by the expression:
>
>  f(t) = 10 sin (1.5t) + 5 sin (2.5t) + 2.5 sin (5t) + 1.25 sin (10t)
>
>  Use MATLAB to obtain a spectrum (magnitude only) of the signal
> reconstructed from the sampled signal if the sampling frequency is:
>
>  a) 5 Hz
>
>  PROGRAM
>  >> H=5;
>  >> N=1024;
>  >> n=[0:N/2-1];
>  >> t=0:10;
>  >> w=2*pi*H/N*n;
>  >> f=10*sin(1.5*t)+5*sin(2.5*t)+2.5*sin(5*t)+1.25*sin(10*t);
>  >> Fd=fft(f);
>  >> plot(w,abs(Fd(1:N/2))/H);
>
>  ??? Index exceeds matrix dimensions.
>
>  



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Need help on FFT error msg - arkkimede - Mar 18 12:44:23 2008

In the plot, the vector w ed Fd must have the same length.
try with plot(f, abs(Fd))

On Mon, Mar 17, 2008 at 3:48 PM, <h...@yahoo.com.sg> wrote:

>   Hi everyone
>
> Tried to write the program for the following question and got the error
> msg. Appreciate anyone's help please! Thanks.
>
> QUESTION
> A signal is represented by the expression:
>
> f(t) = 10 sin (1.5t) + 5 sin (2.5t) + 2.5 sin (5t) + 1.25 sin (10t)
>
> Use MATLAB to obtain a spectrum (magnitude only) of the signal
> reconstructed from the sampled signal if the sampling frequency is:
>
> a) 5 Hz
>
> PROGRAM
> >> H=5;
> >> N=1024;
> >> n=[0:N/2-1];
> >> t=0:10;
> >> w=2*pi*H/N*n;
> >> f=10*sin(1.5*t)+5*sin(2.5*t)+2.5*sin(5*t)+1.25*sin(10*t);
> >> Fd=fft(f);
> >> plot(w,abs(Fd(1:N/2))/H);
>
> ??? Index exceeds matrix dimensions.
>
>  
>



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )