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.

Help me with creating divide sin function in Matlab

Status
Not open for further replies.

itmr

Member level 3
Joined
Nov 5, 2010
Messages
55
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,750
HI EVERYBODY

i need to create the function x1(t) = [sin(2*pi*50 t)] / [pi*t] in matlab.

i did it by create the suitable time vector and assign the func like this

t = -1 : 0.001 : 1 ;
x1_t = sin(2*50*pi*t.) / pi*t.;

the size of t is 1 2001
and instead of get the same size at x1(t) ' i get that the size of x1(t) is 1 1
i know its smaal mistake but i will be very glad for help with it
thanks a lot everybody
 

Re: Divide sin in matlab

I don't have Matlab installed on this machine to verify, but I believe your problem comes from Matlab's interpretation of the dataset. Fundamentally, Matlab functions are used to manipulate matrices (MATLAB = MATrix LABoratory). To apply a function to a vector of individual elements (like your time vector), you need to tell Matlab to evaluate each element in "t" individually... not crunch the whole matrix at once. You do this with the . (dot) operator. For each mathematical operator, you should put in it's dot equivalent (e.g. * becomes .* , / becomes ./ , etc).

So, your desired code should be:
t = -1 : 0.001 : 1 ; (same)
x1_t = sin(2.*50.*pi.*t.) ./ pi.*t.;

Now, Matlab should take each value of t, evaluate the equation, and drop it into the vector x1_t, at the same index position. This will make x1_t the same size as t.

Hope that helps. You could also some simpler equations to explore the dot-operator functionality.
 

Re: Divide sin in matlab

thanks a lot it was realy realy helps me..
i am very appreciate it..

probably i coded it like this

t = -1 : 0.001 : 1 ;
x1_t = [sin(2.*50.*t.*pi)]./ (t.*pi);

again thanks a lot
 

Re: Divide sin in matlab

So, your desired code should be:
t = -1 : 0.001 : 1 ; (same)
x1_t = sin(2.*50.*pi.*t.) ./ pi.*t.;
Your explanation is right and your code is almost correct. You do not need the ".*" or "./" in all the operations but only where you need to divide the vectors element-wise. The Correct code is:
Code:
t = -1 : 0.001 : 1 ; (same)
x1_t = sin(2*50*pi*t) ./ (pi*t);
 

Re: Divide sin in matlab

I don't believe Matlab cares if you dot every operator or not. It should simply perform the vector math on a vector of size 1. Perhaps not the most expedient method, computationally-speaking, but it should produce the same result. Thanks for the code clean-up; I didn't have Matlab installed on that machine to validate.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top