I'm supposed to generate a 6 seconds long sine wave that has amplitude of 1.0, frequency of 400Hz at a 8KHz sampling frequency, but I'm not sure how to control how long the wave lasts for.

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 10 月 7 日

5 投票

f=400
Amp=1
ts=1/8000;
T=6
t=0:ts:T;
y=sin(2*pi*f*t);
plot(t,y)

3 件のコメント

Kay Wonderley
Kay Wonderley 2018 年 3 月 26 日
編集済み: Image Analyst 2018 年 3 月 26 日
Hi I have done this (below).
How do I turn it into a function?
f=100;
Amp=10;
fs = 44100;
ts=1/44100;
T=10;
t=0:ts:T;
y=sin(2*pi*f*t);
sound(y,fs)
Image Analyst
Image Analyst 2018 年 3 月 26 日
Add a function line:
function [t, y] = PlaySound()
f=100;
Amp=10;
fs = 44100;
ts=1/44100;
T=10;
t=0:ts:T;
y=sin(2*pi*f*t);
sound(y,fs)
Mohamad
Mohamad 2019 年 4 月 4 日
f=400
Amp=1
ts=1/8000;
T=6
t=0:ts:T-ts; % I modified this line to make signal duration 6 seconds
y=sin(2*pi*f*t);
plot(t,y)

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 10 月 7 日

1 投票

Hint: 6 seconds at 8000 times per second means that the vector (row array) will be 48000 elements long.
sineWave = sin(2*pi*freq*timeVector);
See if that's enough hints.

3 件のコメント

Image Analyst
Image Analyst 2014 年 10 月 8 日
Well it looks like Azzi did it all for you. Though if you ever want to change the amplitude you should use
y = Amp * sin(2*pi*f*t);
Dick Rusell
Dick Rusell 2014 年 10 月 10 日
Is there a way to zoom outt? Because I get a blue box when I plot it from the frequency.
Akpabio Ekpewoh
Akpabio Ekpewoh 2019 年 7 月 11 日
Yes, just use the icons on the top of the plot

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

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by