フィルターのクリア

PLOT time domain & frequency domain of music signal

1 回表示 (過去 30 日間)
sanbadgerdude
sanbadgerdude 2017 年 4 月 20 日
コメント済み: the cyclist 2017 年 4 月 20 日
MATLAB PLOT Sinusoidal Music... Can someone help me with how to PLOT my signal for the following code in time domain and frequency domain? Apparently the way I am using PLOT is incorrect.
if true
% code
end
clc
clear all
fs = 8000;
C = 523.251;
F = 698.456;
t = 0:1/fs:0.6;
song = [F*t C*t];
y = sin(2*pi*song);
sound(y,fs);
figure
plot(t,y)

回答 (1 件)

the cyclist
the cyclist 2017 年 4 月 20 日
編集済み: the cyclist 2017 年 4 月 20 日
Try this instead
plot([t t+0.6+1/fs],y)
The problem with your code is that you used the t vector twice in generating the song, so y was double the length of t. I fixed that by extending the time vector in the plotting function.
You'll see that there is a discontinuity at t=0.6. The better way to have done this is to define one continuous time vector
t = 0:1/fs:1.2;
and then define your song over segments of that time vector. [But I was too lazy to do all that. :-) ]
  2 件のコメント
sanbadgerdude
sanbadgerdude 2017 年 4 月 20 日
I have actually extended my code to play several notes for different durations. I actually have a t1, t2, and t3 now, where
if true
% code
end
t1 = 0:1/fs:0.5;
t2 = 0:1/fs:1;
t3 = 0:1/fs:2;
Does this create more issues. I still could not get your solution to work.
the cyclist
the cyclist 2017 年 4 月 20 日
Conceptually, this is pretty simple. You need a one-to-one correspondence between your t vector and your y vector, in order to plot them.
To make a simple example, you can do
plot([1 2 3 4],[2 3 5 7])
but you are trying to do
plot([1 2 3 4],[2 3 5 7 9 11 13 17])
which will give an error because those vectors do not have a one-to-one correspondence.
So, using your new t1 etc vectors, it looks like your full time sequence is something like
t = [t1 t2+max(t1) t3+max(t1)+max(t2)]
and then you can plot your y value against that time vector.

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

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by