f0 = 1000;
total_time = 5;
fsRatio = 20;
fs = f0*fsRatio;%20000
T = 1/fs; % sampling interval in time
A = 0.25; % magnitude
phi = 0; % phase
t = (0:T:total_time); % time axis
% x(t) = A*cos(2*pi*f0*t+phi) where A: magnitude (>= 0), f0: 1/(fundamental period), phi: phase
x_CT = A*cos(2*pi*f0*(0:1/(f0*100):total_time)+phi); % x(t), sampling rate is high enough so th
x_DT = A*cos(2*pi*f0*t+phi); % x[n] = x(nT), sampled cosine/discrete time sinusoid
%Npoint = length(x_DT); % number of points in sampled cosine
sound(x_DT,fs); % play the signal by the sound card, type "help sound" (without the double quot
figure
plot((0:1/(f0*100):total_time), x_CT,'-', 'linewidth', 2); % CT signal
hold on
stem(t, x_DT,'r', 'linewidth', 2); % DT signal
plot(t, x_DT,'r', 'linewidth', 2); % connet the dots, i.e., connect DT x[n]
xlabel('Time (sec.)');
ylabel('x(nT)');
title('Discrete time sinusoid (time domain)');
axis([0 1/f0*5 -A A]); % only observe the signal from time 0 to time 1/f0*3. once you remove t
legend('x(t)', 'x[n]', 'connected x[n]')
xlim([0.00000 0.00500])
ylim([-1.00 1.00])
1
f0 = 1000; % in Hz
total_time = 5; % in sec.
% !!! Sampling in time
fsRatio = 20;
fs = f0*fsRatio;
T = 1/fs; % sampling interval in time
A = 0.5; % magnitude
phi = 0; % phase
t = (0:T:total_time); % time axis
% x(t) = A*cos(2*pi*f0*t+phi) where A: magnitude (>= 0), f0: 1/(fundamental period), phi: phase
x_CT = A*cos(2*pi*f0*(0:1/(f0*100):total_time)+phi); % x(t), sampling rate is high enough so th
x_DT = A*cos(2*pi*f0*t+phi); % x[n] = x(nT), sampled cosine/discrete time sinusoid
%Npoint = length(x_DT); % number of points in sampled cosine
sound(x_DT,fs); % play the signal by the sound card, type "help sound" (without the double quot
figure
plot((0:1/(f0*100):total_time), x_CT,'-', 'linewidth', 2); % CT signal
hold on
stem(t, x_DT,'r', 'linewidth', 2); % DT signal
plot(t, x_DT,'r', 'linewidth', 2); % connet the dots, i.e., connect DT x[n]
xlabel('Time (sec.)');
ylabel('x(nT)');
title('Discrete time sinusoid (time domain)');
2
axis([0 1/f0*5 -A A]); % only observe the signal from time 0 to time 1/f0*3. once you remove t
legend('x(t)', 'x[n]', 'connected x[n]')
f0 = 1000; % in Hz
total_time = 5; % in sec.
% !!! Sampling in time
fsRatio = 20;
fs = f0*fsRatio;
T = 1/fs; % sampling interval in time
A = 1; % magnitude
phi = 0; % phase
t = (0:T:total_time); % time axis
% x(t) = A*cos(2*pi*f0*t+phi) where A: magnitude (>= 0), f0: 1/(fundamental period), phi: phase
x_CT = A*cos(2*pi*f0*(0:1/(f0*100):total_time)+phi); % x(t), sampling rate is high enough so th
x_DT = A*cos(2*pi*f0*t+phi); % x[n] = x(nT), sampled cosine/discrete time sinusoid
%Npoint = length(x_DT); % number of points in sampled cosine
sound(x_DT,fs); % play the signal by the sound card, type "help sound" (without the double quot
figure
plot((0:1/(f0*100):total_time), x_CT,'-', 'linewidth', 2); % CT signal
hold on
stem(t, x_DT,'r', 'linewidth', 2); % DT signal
plot(t, x_DT,'r', 'linewidth', 2); % connet the dots, i.e., connect DT x[n]
3
xlabel('Time (sec.)');
ylabel('x(nT)');
title('Discrete time sinusoid (time domain)');
axis([0 1/f0*5 -A A]); % only observe the signal from time 0 to time 1/f0*3. once you remove t
legend('x(t)', 'x[n]', 'connected x[n]')
1.a:如果振幅A的值越大,聽到的聲音越大
f0 = 2000; % in Hz
total_time = 5; % in sec.
% !!! Sampling in time
fsRatio = 20;
fs = f0*fsRatio;
T = 1/fs; % sampling interval in time
A = 1; % magnitude
phi = 0; % phase
t = (0:T:total_time); % time axis
% x(t) = A*cos(2*pi*f0*t+phi) where A: magnitude (>= 0), f0: 1/(fundamental period), phi: phase
x_CT = A*cos(2*pi*f0*(0:1/(f0*100):total_time)+phi); % x(t), sampling rate is high enough so th
x_DT = A*cos(2*pi*f0*t+phi); % x[n] = x(nT), sampled cosine/discrete time sinusoid
%Npoint = length(x_DT); % number of points in sampled cosine
sound(x_DT,fs); % play the signal by the sound card, type "help sound" (without the double quot
figure
4
% type "help plot" (without the double quote) under MATLAB console to see the usage of plot().
% type "help stem" to see the usage of stem().
%plot((0:1/(f0*100):total_time), x_CT,'-o', 'linewidth', 2);
plot((0:1/(f0*100):total_time), x_CT,'-', 'linewidth', 2); % CT signal
hold on
stem(t, x_DT,'r', 'linewidth', 2); % DT signal
plot(t, x_DT,'r', 'linewidth', 2); % connet the dots, i.e., connect DT x[n]
xlabel('Time (sec.)');
ylabel('x(nT)');
title('Discrete time sinusoid (time domain)');
axis([0 1/f0*5 -A A]); % only observe the signal from time 0 to time 1/f0*3. once you remove t
legend('x(t)', 'x[n]', 'connected x[n]')
f0 = 4000; % in Hz
total_time = 5; % in sec.
% !!! Sampling in time
fsRatio = 20;
fs = f0*fsRatio;
T = 1/fs; % sampling interval in time
A = 1; % magnitude
phi = 0; % phase
t = (0:T:total_time); % time axis
% x(t) = A*cos(2*pi*f0*t+phi) where A: magnitude (>= 0), f0: 1/(fundamental period), phi: phase
x_CT = A*cos(2*pi*f0*(0:1/(f0*100):total_time)+phi); % x(t), sampling rate is high enough so th
5
x_DT = A*cos(2*pi*f0*t+phi); % x[n] = x(nT), sampled cosine/discrete time sinusoid
%Npoint = length(x_DT); % number of points in sampled cosine
sound(x_DT,fs); % play the signal by the sound card, type "help sound" (without the double quot
figure
% type "help plot" (without the double quote) under MATLAB console to see the usage of plot().
% type "help stem" to see the usage of stem().
%plot((0:1/(f0*100):total_time), x_CT,'-o', 'linewidth', 2);
plot((0:1/(f0*100):total_time), x_CT,'-', 'linewidth', 2); % CT signal
hold on
stem(t, x_DT,'r', 'linewidth', 2); % DT signal
plot(t, x_DT,'r', 'linewidth', 2); % connet the dots, i.e., connect DT x[n]
xlabel('Time (sec.)');
ylabel('x(nT)');
title('Discrete time sinusoid (time domain)');
axis([0 1/f0*5 -A A]); % only observe the signal from time 0 to time 1/f0*3. once you remove t
legend('x(t)', 'x[n]', 'connected x[n]')
1.b:f0從1000開始調高到4000,音調變得越來越高
f0 = 1000; % in Hz
total_time = 5; % in sec.
% !!! Sampling in time
fsRatio = 20;
6
fs = f0*fsRatio;
T = 1/fs; % sampling interval in time
A = 1; % magnitude
phi = pi/4; % phase
t = (0:T:total_time); % time axis
% x(t) = A*cos(2*pi*f0*t+phi) where A: magnitude (>= 0), f0: 1/(fundamental period), phi: phase
x_CT = A*cos(2*pi*f0*(0:1/(f0*100):total_time)+phi); % x(t), sampling rate is high enough so th
x_DT = A*cos(2*pi*f0*t+phi); % x[n] = x(nT), sampled cosine/discrete time sinusoid
%Npoint = length(x_DT); % number of points in sampled cosine
sound(x_DT,fs); % play the signal by the sound card, type "help sound" (without the double quot
figure
% type "help plot" (without the double quote) under MATLAB console to see the usage of plot().
% type "help stem" to see the usage of stem().
%plot((0:1/(f0*100):total_time), x_CT,'-o', 'linewidth', 2);
plot((0:1/(f0*100):total_time), x_CT,'-', 'linewidth', 2); % CT signal
hold on
stem(t, x_DT,'r', 'linewidth', 2); % DT signal
plot(t, x_DT,'r', 'linewidth', 2); % connet the dots, i.e., connect DT x[n]
xlabel('Time (sec.)');
ylabel('x(nT)');
title('Discrete time sinusoid (time domain)');
axis([0 1/f0*5 -A A]); % only observe the signal from time 0 to time 1/f0*3. once you remove t
legend('x(t)', 'x[n]', 'connected x[n]')
1.c:改變相位不會發生音調音量上的變化,改變相位角是time shift
7
8