MATLAB Answers

Basic Sampling question involving sampling rate and graphing

23 views (last 30 days)
Zachariah Brown
Zachariah Brown on 2 Apr 2021
Commented: Zachariah Brown on 3 Apr 2021
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

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.

Community Treasure Hunt

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

Start Hunting!

Translated by