绘制正弦波的集合

时间:2017-08-06 12:33:41

标签: matlab plot matlab-figure

我有以下代码:

windowSpec = (W.partitionBy(col("location"))
  .orderBy(col("eventtime").cast("timestamp").cast("long"))
  .rangeBetween(0, days(5)))


df.withColumn("id_count", countDistinct("userid").over(windowSpec))

其中Fs = 1000; T = 1/Fs; L = 1000; t = (0:L-1)*T; k = 25:1:50; m = 1:1:25; k对应。我想绘制由以下原因产生的25个正弦波:

m

我考虑过使用x = m*sin(2*pi*k*t); 循环来执行此操作,每次从form获取一个值,但我不确定如何继续。

2 个答案:

答案 0 :(得分:0)

以下是一个非常基本的绘图解决方案。您会注意到很难看到图中发生了什么,因此您可能需要考虑其他方式来呈现此数据。

function q45532082
Fs = 1000;
T = 1/Fs;
L = 1000;
t = (0:L-1)*T;
k = 26:1:50;
m = 1:1:25;
%% Plotting
assert(numel(m) == numel(k)); % We make sure that the number of elements is the same.
figure(); hold on; % "hold" is needed if you want to see all curves at the same time.
for ind1 = 1:numel(m)
  plot(t,m(ind1)*sin(2*pi*k(ind1)*t));
end

结果如下:

The result

请注意,代码中km中的元素数量不同,因此我必须更改它。

答案 1 :(得分:0)

使用plot的功能,您还可以在没有循环的情况下绘制所有正弦波:

Fs = 1000;
T = 1/Fs;
L = 1000;
t = (0:L-1)*T;
k = 26:1:50;
m = 1:1:25;
x = m.*sin(2.*pi.*bsxfun(@times,t.',k)); %this results in an L*25 matrix, each column is data of one wave
% or, if you have version 2016b or newer:
% x = m.*sin(2.*pi.*t.'*k);
plot(t,x) % plot all sines at ones

@Dev-iL noted,我还必须更改k

L = 1000的结果过于拥挤,所以我在L = 50点示了它:

enter image description here