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.

Simple Matlab code help - no aliaisnig error?

Status
Not open for further replies.

Ibaghdadi

Newbie level 6
Joined
Dec 26, 2007
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Lebanon
Activity points
1,387
levanon matlab code

Hi iam wrinting a simple Matlab code that generates a sinusoidal signal which is then sampled ploted. when I take the sampling frequency fs=5000 and f0=4500 hz. The number of samples n=100,.
I should get an aliaisnig error right because fs<2*f0.... The problem is that i get all the signal undistorted!!! This is the Matlab code:

Code:
function [x,t]=sin_gen(f0,fs,N)
N=input('input the value N\n');%N=100                      
f0=input('input f0\n');        
fs=input('input the value fs\n');%fs=5000
n=0:N-1;
x=sin(2*pi*n*(f0/fs));
Ts=1/fs;
t=n*Ts;
stem(t,x,'r');

xlabel('t');
ylabel('x[n]');
 

Re: Simple Matlab code help

Hi,
l think i will explain with an eg.
x1(t)=cos(2*pi*10*t)
x1(t)=cos(2*pi*50*t)
if the sampling rate is fs=40Hz.
x1[n]=cos(2*pi*(10/40)*n) = cos(pi*n/2)
x1[n]=cos(2*pi*(50/40)*n) = cos(5*pi*n/2)=cos( (2*pi*n) + (pi*n/2) )
= cos( (pi*n/2) )

therefore, if we are given the sampled values generated by cos( (pi*n/2) )
there will b a confusion whether sampled value belongs to x1(t) or x2(t)


here, 50Hz is an alias of freq 10Hz.


so in time domain one cannot trace aliasing. (the sample values look similar)

in your code u r trying to analyse time domain

Only in freq domain, one can see the effect of aliasing.



Happy learning
 

Re: Simple Matlab code help

ok thanks well explained.
Although I did managed to see(at least in that case f0=4500& fs=5000) my error when i made the step size (n=0:0.5:100) smaller.
 

Re: Simple Matlab code help

Ibaghdadi wrote:
"my error when i made the step size (n=0:0.5:100) smaller."

n should b an integer. (as in Discrete time seq, it is not defined for decimal or real values.)
it is defined for integer values

so the step size should b integer. step size (n=0:1:99)

Happy learning
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top