how do i randomly sample a sinewave?

hey can someone help me?i am trying to randomly sample sinewave but i am having no luck. i have tried Google, i tried using the help function on the 'rand' command and still i am no closer to sampling the signal.

2 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 15 日
What do you mean?
Kel
Kel 2014 年 3 月 15 日
i have signal shown by the code below and would like to take random samples of the signal,
fo=4 fs=100 ts=1/fs t=0:ts:1-ts n=length(t) y=2*sin(2*pi*fo*t) plot(t,y)

サインインしてコメントする。

 採用された回答

dpb
dpb 2014 年 3 月 15 日

0 投票

yrand=y(randperm(length(y),K));
returns K random samples from y

その他の回答 (2 件)

Image Analyst
Image Analyst 2014 年 3 月 15 日

1 投票

Try this:
fo=4
fs=100
ts=1/fs
t=0:ts:1-ts
n=length(t)
y=2*sin(2*pi*fo*t)
plot(t,y)
numberOfSamplesToTake = 20;
sampleIndexes = randperm(numel(y), numberOfSamplesToTake)
% Plot the samples;
ts = t(sampleIndexes)
ys = y(sampleIndexes)
hold on;
plot(ts, ys, 'r*');

4 件のコメント

Kel
Kel 2014 年 3 月 15 日
thank you
Kel
Kel 2014 年 3 月 16 日
hey i have tried your answer and matlab doesn't seem to like it. it's coming up with an error saying:
??? Error using ==> randperm Too many input arguments.
i am getting the blue sinwave but not the random red plots
Image Analyst
Image Analyst 2014 年 3 月 16 日
You must have a really old version of MATLAB before they added the second input argument of randperm. Try this:
numberOfSamplesToTake = 20;
sampleIndexes = randperm(numel(y))
sampleIndexes = sampleIndexes(1:numberOfSamplesToTake)
dpb
dpb 2014 年 3 月 16 日
Ah...good catch, IA. Never crossed my mind but my R12 doesn't include it--how quick we forget! :)
Presuming you're correct (and that's a good bet) perhaps a good use for a utility function for the OP to take the second argument.

サインインしてコメントする。

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 8 月 14 日

0 投票

An alternative solution is:
N_samples = 20;
y_rand = datasample(y, N_samples);
% OR
y_rand = randsample(y,N_samples);

カテゴリ

ヘルプ センター および File ExchangeMeasurements and Feature Extraction についてさらに検索

質問済み:

Kel
2014 年 3 月 15 日

回答済み:

2021 年 8 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by