フィルターのクリア

ascribe zeros to an array

2 ビュー (過去 30 日間)
Nuks Kar
Nuks Kar 2023 年 9 月 23 日
編集済み: Bruno Luong 2023 年 9 月 24 日
I am new to matlab. I want to ascribe zeros to frequencies going from 1001 to 2048 after having built a spectrum from 1 to 1000.
How do I do it please.
f= 1001:2048;
  2 件のコメント
Rik
Rik 2023 年 9 月 23 日

Have a read here and here. It will greatly improve your chances of getting an answer.

If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).

Nuks Kar
Nuks Kar 2023 年 9 月 24 日
Thank you very much.

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

回答 (2 件)

Walter Roberson
Walter Roberson 2023 年 9 月 23 日
frequencies = linspace(0, 2400, 250);
spectrum = rand(size(frequencies));
subplot(2,1,1); plot(frequencies, spectrum); title('before zeroing');
spectrum(frequencies >= 1001 & frequencies <= 2048) = 0;
subplot(2,1,2); plot(frequencies, spectrum); title('after zeroing')
  1 件のコメント
Nuks Kar
Nuks Kar 2023 年 9 月 24 日
Thanks a lot.

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


Bruno Luong
Bruno Luong 2023 年 9 月 24 日
編集済み: Bruno Luong 2023 年 9 月 24 日
To pad a vector with zeros you only need to set the last-element of the extended vector to 0
f=rand(1,5) % 1000 in your case
f = 1×5
0.7012 0.5664 0.9478 0.7397 0.8932
fpad = f; fpad(8)=0; fpad % 2048 in your case
fpad = 1×8
0.7012 0.5664 0.9478 0.7397 0.8932 0 0 0
Note that is you call fft/ifft on fpad, you don't even need to construct it, fft and ifft has the length in second argument that you can use to do fft on padded array without explicitly constructing it. Both of these return the same result
fft(fpad)
ans =
3.8485 + 0.0000i -0.3146 - 1.8714i 0.6467 + 0.1733i -0.0694 + 0.0243i 1.2362 + 0.0000i -0.0694 - 0.0243i 0.6467 - 0.1733i -0.3146 + 1.8714i
fft(f,8)
ans =
3.8485 + 0.0000i -0.3146 - 1.8714i 0.6467 + 0.1733i -0.0694 + 0.0243i 1.2362 + 0.0000i -0.0694 - 0.0243i 0.6467 - 0.1733i -0.3146 + 1.8714i

カテゴリ

Help Center および File ExchangeOctave についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by