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]');
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.
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.