Basic Sampling question involving sampling rate and graphing

27 views (last 30 days)
For a labI was given this code
t=0:1/2000:.02;
x=sin(2*pi*60*t);
t240=0:1/240:.02;
n240=0:length(t240)-1;
x240=sin(2*pi*60/240*n240);
stem(n240,x240,'filled','b','LineWidth',2);
axis([0 4.8 -1 1]);
and was to put that into matlab and display the sampling and function which works fine. We then needed to make this into a function of x=Asin(omega*t) where f = 10000Hz, and find the sampling at rates of 5k, 10k, and 20, 100k. However changing the values of the sampling frequency and the function frequency gives me a graph that is not at all similar and I have no idea what I need to fix or change to get the graph to look like the initial one.
=======================================
t=0:1/3300:.02;
x=sin(2*pi*10000*t);
t5000=0:1/5000:.02;
n5000=0:length(t5000)-1;
x5000=sin(2*pi*10000/5000*n5000);
stem(n5000,x5000,'filled','b','LineWidth',2);
=======================================
t=0:1/3300:.02;
x=sin(2*pi*10000*t);
t10000=0:1/10000:.02;
n10000=0:length(t10000)-1;
x10000=sin(2*pi*10000/10000*n10000);
stem(n10000,x10000,'filled','b','LineWidth',2);
========================================
that is what I changed the code too for 5k and 10k, i know those are both less than nyquist's sampling so it will result in not a good graph, but even with 20k+ the graph isnt similar to what it was before.
what I specifically dont understand is
how
t=0:1/2000:.02
; is time
what
n240=0:length(t240)-1; is
this
stem(n240,x240,'filled','b','LineWidth',2);
part of the code and what it does
how to get a proper sampling graph of 5k,10k,20k and100k, and what to change to get that
  3 Comments
dpb
dpb on 2 Apr 2021
ADDENDUM
"That's fine when the signal being generated with that time series is one of 60 Hz as the first example; that's 2000/60 or a sample rate of 33X times the signal. You can get by with anything >2 by Nyquist, 3-4X is better with shorter time periods."
That is, >Nyquist by any amount will be enough to find the frequency content via FFT with a suitably-long record; that does NOT mean that the time series graph will look smooth; a sample rate of only slightly over Nyquist will still look like a triangle wave mostly, not a smooth sine even though there is enough frequency content in the resulting signal to compute the appropriate frequencies without aliasing.

Sign in to comment.

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 3 Apr 2021
Your code has a problem with the end time value to take into calculations and display of the calculated data points. Here are some corrected codes:
f1=240;
t=0:1/2000:.02;
%x=sin(2*pi*60*t);
t240=0:1/f1:.02;
n240=0:length(t240)-1;
x240=sin(2*pi*60/f1*n240);
figure
subplot(311)
stem(n240,x240,'filled','b','LineWidth',2);
axis([0 4.8 -1 1]);
%%
%t=0:1/2000:.02;
%x=sin(2*pi*60*t);
f1=240;
t240=0:1/f1:.02;
n240=0:length(t240)-1;
x240=sin(2*pi*f1*n240);
figure
subplot(311)
stem(n240,x240,'filled','b','LineWidth',2);
axis([0 4.8 -1 1]);
subplot(312)
f2=5000; % 5k
t5k=0:1/(f2*10):.0005;
n5k=0:length(t5k)-1;
x5k=sin(2*pi*10000/f2*n5k);
stem(n5k,x5k,'filled','b','LineWidth',2); shg
f3=1e4; % 10k
% t=0:1/(10*f3):.02;
% x=sin(2*pi*f3*t);
t10k=0:1/(10*f3):.0002;
n10k=0:length(t10k)-1;
x10k=sin(2*pi*1*n10k);
subplot(313)
stem(n10k,x10k,'filled','b','LineWidth',2); shg
Good luck.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!