You are on page 1of 3

f0 = 1000; % in Hz

total_time = 5; % in sec.

% !!! Sampling in time


fsRatio = 1.8;
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
% 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*50 -A A]); % only observe the signal from time 0 to time 1/f0*3. once you remove
legend('x(t)', 'x[n]', 'connected x[n]')

1
2.(a)fsRatio 從20降到2之間只有大小聲的變化,變成1.8的時候因為取樣的間隔太大所以音高變了

2.(b)f0改變了。最小的fsRatio是2,如果比2小的話取樣就會偏離

f0 = 1000; % in Hz
total_time = 5; % in sec.

% !!! Sampling in time


fsRatio = 1.74;
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
% 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().

2
%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*50 -A A]); % only observe the signal from time 0 to time 1/f0*3. once you remove
legend('x(t)', 'x[n]', 'connected x[n]')

2.(c)會,不管取多少的fsRatio依然會是週期函數(如圖示fsRation=1.74仍然有週期性)

You might also like