Creating a piecewise sine function having different frequency components

4 ビュー (過去 30 日間)
Jack Talaga
Jack Talaga 2019 年 5 月 19 日
回答済み: Sulaymon Eshkabilov 2020 年 11 月 10 日
Hello,
I am brandnew in Matlab and i would like to generate a piecewise sine function with different frequency components. i.e. a signal at 1 kHz sampling frequency and having 100,200 and 300 Hz frequency components. I check the other topics but couldn't find a proper solution.
  1 件のコメント
John D'Errico
John D'Errico 2019 年 5 月 19 日
Please don't add an answer to an old question just to raise it up. You asked your own question anway.

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

回答 (3 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019 年 5 月 19 日
編集済み: Sulaymon Eshkabilov 2019 年 5 月 19 日
Hi,
If I've understood your question correctly, this is what you are trying to create:
fs = 1e3; % Sampling frequency [Hz]
t = 0:1/fs:1; % Time space [0, 1] [sec]
f1 = 100;
f2 = 200;
f3 = 300;
S1 = sin(2*pi*f1*t);
S2 = sin(2*pi*f1*t);
S3 = sin(2*pi*f1*t);
Stotal = S1+S2+S3;
plot(t, Stotal)
Note that your fs is too small (it is better to have your fs = 10[kH]) for your generated frequency components of 100, 200, 300 Hz

Star Strider
Star Strider 2019 年 5 月 19 日
Try this:
Fs = 1000;
t = linspace(0, 1, 1E+3)/Fs; % Time Vector (1 sec)
f = 100:100:300; % Frequency Vector
sm = sin(2*pi*f(:)*t*Fs)'; % Signal Matrix
sv = sm(:); % Signal Vector
tv = (0:numel(sv)-1/Fs)/Fs;
figure
plot(tv, sv)
grid
sound(sv, Fs) % Listen To The Result

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020 年 11 月 10 日
There are two opts. One elementwise multiplication and the other is just product.
% (1) Elementwise:
S1S2_e = s1.*s2;
% (2) Just a product of two row matrix (vector) elements
S1S2_p = s1*s2';

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by