2

私はmatlabと信号処理が初めてです。以下の投稿コードを書きました。私が理解できなかったtime soecificationのは、コードの最初のセクションです。間隔または期間を指定するときにサンプリングが必要な理由はわかりません。次のようなものを指定するだけで十分だと思います。

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

定常信号などをプロットするためにサンプリングのようなものが必要なのはなぜですか。別の質問は、このコードでエラーが発生paranthesis imbalanceし、解決方法を教えてください。

コード

%% 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}');
4

1 に答える 1

1

デジタル化された信号を扱っているからです。信号のサンプルを無限にプロットすることはできません。そのため、デジタル化された信号を操作する前に、サンプリング周波数などのいくつかのパラメーターを指定する必要があります。サンプリング周波数は、サンプル インデックスと時間の間の関係、つまり 1 秒間の信号に含まれるサンプル数を示します。

質問の冒頭で提案したように時間ベクトルを定義することもできますが、信号がサンプリングされたサンプリング周波数を指定している場合は、より便利です。特に、何らかの信号処理を行いたい場合 (例:ナイキスト サンプリング定理を参照)、異なるサンプリング周波数に起因する制限と特性を認識することが重要です。

あなたの括弧の不均衡はから来ています

  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);

編集:

ある種の「ライブ プロット」を取得するには、プロット コードを次のように変更します。

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

EDIT2:

% 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
于 2014-12-28T13:31:51.397 に答える