为什么我们需要时间采样来绘制平稳信号? [英] why do we need time sampling to plot a stationary signal?

查看:125
本文介绍了为什么我们需要时间采样来绘制平稳信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Matlab和信号处理的新手.我已经写了下面发布的代码.我不明白的是,代码开头的time soecification部分.我不为什么在指定时间间隔或持续时间时我们为什么需要采样,我认为只需指定以下内容即可:

I am new to matlab and signal processing. I have wrote the below posted code. what i could not understand is, the time soecification section at the beginning of the code. I do not why do we need sampling when specifying an interval or time duration, i think it suffice to specify something like the following :

t = (0: 0.2: 1.0)  for an example,

为什么我需要采样之类的东西来绘制诸如固定信号之类的东西. 另一个问题是,这段代码给我一个错误,提示paranthesis imbalance如何解决.

why do i need some thing like sampling to plot such as stationary signal. another question is, this code gives me an error saying paranthesis imbalance how to solve it please.

代码

%% Time specifications:
  Fs = 8000;                       % samples per second
  dt = 1/Fs;                       % seconds per sample
  StopTime = 1;                    % seconds
  t = (0:dt:StopTime-dt);         % seconds

  x = (10)*cos(2*pi*3*t) ...          
  + (20)*cos(2*pi*6*t  ...  
   + (30)*cos(2*pi*10*t) ...
  + (50)*cos(2*pi*15*t);

  % Plot the signal versus time:
  figure;
  plot(t,x);
  xlabel('time (in seconds)');
  ylabel('Amplitude');
  title('Signal versus Time');
  title('{\bf Periodogram}');

推荐答案

因为我们正在处理数字化信号.您不能绘制无限数量的信号样本.这就是为什么在使用数字信号之前需要指定一些参数的原因,例如采样频率.采样频率使您可以确定样本索引与时间之间的关系,即在一秒钟的信号中有多少样本.

Because we are dealing with digitized signals. You can not plot an infinite amount of samples of your signal. That is why you need to specify some parameters prior to working with digitized signals, such as the sampling frequency. The sampling frequency gives you a relationship between your samples indices and time, namely how many samples you have in one second of signal.

您也可以按照问题开头的建议定义时间向量,但是如果您指定了对信号进行采样的采样频率,这将更加方便.特别是如果您想进行一些信号处理(请参见:奈奎斯特采样定理)了解不同采样频率的局限性和特性至关重要.

You can also define your time vectors as you suggested in the beginning of your question, but it is way more convenient, if you have specified a sampling frequency with which your signal was sampled. Especially if you want to do some signal processing (see e.g.: Nyquist sampling theorem) it is crucial that you are aware of limitations and properties stemming from different sampling frequencies.

您的括号不平衡来自

  x = (10)*cos(2*pi*3*t) ...          
  + (20)*cos(2*pi*6*t)  ...  % <= Missing parenthesis in this line
   + (30)*cos(2*pi*10*t) ...
  + (50)*cos(2*pi*15*t);

要获得某种实时绘图",可以将绘图代码更改为以下内容:

To get kind of a "live plot" you can change your plotting code to something like this:

figure;
xlabel('time (in seconds)');
ylabel('Amplitude');
title('Signal versus Time');

h = plot(nan);
for i=1:length(t)
    set(h,'YData', x(1:i), 'XData', t(1:i));
    drawnow
end

% Time specifications:
Fs = 8000;                       % samples per second
dt = 1/Fs;                       % seconds per sample
StopTime = 1;                    % seconds
t = (0:dt:StopTime-dt);         % seconds

x1 = (10)*cos(2*pi*3*t);
x2 = (20)*cos(2*pi*6*t);
x3 = (30)*cos(2*pi*10*t);
x4 = (50)*cos(2*pi*15*t);

% Plot the signal versus time:
figure;
xlabel('time (in seconds)');
ylabel('Amplitude');
title('Signal versus Time');

h1 = plot(nan, 'r');
hold on
h2 = plot(nan, 'g');
hold on
h3 = plot(nan, 'black');
hold on
h4 = plot(nan, 'b');
hold on
for i=1:length(t)
    set(h1,'YData', x1(1:i), 'XData', t(1:i));
    set(h2,'YData', x2(1:i), 'XData', t(1:i)); 
    set(h3,'YData', x3(1:i), 'XData', t(1:i)); 
    set(h4,'YData', x4(1:i), 'XData', t(1:i)); 
    drawnow
end

这篇关于为什么我们需要时间采样来绘制平稳信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆