필터 지우기
필터 지우기

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 CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by