Reply by arkkimede March 18, 20082008-03-18
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, 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;
> >> N24;
> >> n=[0:N/2-1];
> >> t=0:10;
> >> w=2*pi*H/N*n;
> >> f*sin(1.5*t)+5*sin(2.5*t)+2.5*sin(5*t)+1.25*sin(10*t);
> >> Fdt(f);
> >> plot(w,abs(Fd(1:N/2))/H);
>
> ??? Index exceeds matrix dimensions.
>
>
>
Reply by Sameer Herlekar March 18, 20082008-03-18
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 Fdt(f);

with the instruction
Fdt(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;
N24;
n=[0:N/2-1];
f*sin(1.5*(n/H))+5*sin(2.5*(n/H))+2.5*sin(5*(n/H))+1.25*sin(10*(n/H));
Fdt(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, 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;
> >> N24;
> >> n=[0:N/2-1];
> >> t=0:10;
> >> w=2*pi*H/N*n;
> >> f*sin(1.5*t)+5*sin(2.5*t)+2.5*sin(5*t)+1.25*sin(10*t);
> >> Fdt(f);
> >> plot(w,abs(Fd(1:N/2))/H);
>
> ??? Index exceeds matrix dimensions.
>
>
Reply by haiz...@yahoo.com.sg March 17, 20082008-03-17
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;
>> N24;
>> n=[0:N/2-1];
>> t=0:10;
>> w=2*pi*H/N*n;
>> f*sin(1.5*t)+5*sin(2.5*t)+2.5*sin(5*t)+1.25*sin(10*t);
>> Fdt(f);
>> plot(w,abs(Fd(1:N/2))/H);

??? Index exceeds matrix dimensions.