Change values using repmat

4 ビュー (過去 30 日間)
Carlos Pérez
Carlos Pérez 2020 年 10 月 26 日
コメント済み: Ameer Hamza 2020 年 10 月 26 日
Hello everybody,
I have this code
input = '101110'
fs=8000
f0 = 800
duration = 0.1
timeseq=0:1/fs:strlength(input)*duration;
And I want to multiply each 1 of the input and each 0 with the following line.
cos(2*pi*f0*timeseq)
I want to do it without using loops like for, I think I should use fome matlab functions like repmat or repelem but I don't know how they need to be used.
Thank you

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 26 日
I think you are trying to do something like this
input = '101110';
input_num = input - '0';
fs=8000;
duration = 0.1;
timeseq=0:1/fs:strlength(input)*duration-1/fs;
tone_frequency = 2;
input_vec = repelem(input_num, 1, fs*duration);
out = cos(2*pi*tone_frequency*timeseq).*input_vec;
  2 件のコメント
Mireia Boneta Camí
Mireia Boneta Camí 2020 年 10 月 26 日
Hi Ameer, why do you have to put -1/fs in the timeseq?
Ameer Hamza
Ameer Hamza 2020 年 10 月 26 日
So that the number of elements in timeseq are exact multiple of strlength(input)*duration.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by