SIN WAVE PLOT NOT WORKING

10 ビュー (過去 30 日間)
Aditya Mehta
Aditya Mehta 2017 年 2 月 13 日
回答済み: Jan 2017 年 2 月 13 日
>
> f= input('enter the frequency in hertz of the sine wave');
a=input('enter amplitute');
phi=input('enter phase shift');
n=input('enter n')
fs=44000;
t=0:.0001:5;
y= a*sin(2*pi*f*n+ phi);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('Sine wave');
end
I have to generate several sinusoid with a given magnitude A, frequency f0 [Hz], and phase shift φ [rad]. x(n) = A sin(2πf0n + φ). what is wrong with above code as it shows the same graph for all the values. also can you tell me how to specify start and stop moment for signal sampling.(forgive my ignorance i am a beginner)

回答 (1 件)

Jan
Jan 2017 年 2 月 13 日
Your y is a scalar, because it does not depend on the time vector t. Try this:
y = a*sin((2*pi*f*n) * t + phi);

カテゴリ

Help Center および File ExchangeTime-Frequency Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by