📄 cp5_1.m
字号:
%%%%%%%%%%% Comprehensive Problem 5.1 %%%%%%%%%%%
% Discrete-Time Control Problems using %
% MATLAB and the Control System Toolbox %
% by J.H. Chow, D.K. Frederick, & N.W. Chbat %
% Brooks/Cole Publishing Company %
% September 2002 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ---- Drum beat sound track ----
% drum sound track recorded by Nick Chbat
% m file by Joe Chow
load local
fs = 16384 % sampling rate
% extract the main part of the signal
% use 65536 point
N = 2^16;
kstart = 10000;
y = local(kstart:kstart+N-1);
t=[0:length(y)-1]'/fs;
figure, plot(t,y)
xlabel('Time (sec)')
ylabel('local')
title('Original drum beats')
disp('Play original drum sound track')
sound(y,fs)
disp('*******>');pause
disp('Frequency spectrum of original drum sound track')
yfft = fft(y);
% frequency scale
df = fs/N;
f = [0:df:fs-df];
figure, plot(f,abs(yfft))
xlabel('Frequency (Hz)')
ylabel('Magnitude of frequency response')
disp('*******>');pause
% Downsample by 2
x = reshape(y,2,N/2);
x1 = x(1,:);
t=[0:length(x1)-1]'/(fs/2);
figure, plot(t,x1)
xlabel('Time (sec)')
ylabel('local')
title('Signal downsampled by a factor of 2')
disp('Play drum sound track downsampled by a factor of 2')
sound(x1,fs/2)
disp('*******>');pause
disp('Frequency spectrum of downsampled drum sound track')
x1fft = fft(x1);
% frequency scale
df = (fs/2)/(N/2);
f = [0:df:fs/2-df];
figure, plot(f,abs(x1fft))
xlabel('Frequency (Hz)')
ylabel('Magnitude of frequency response')
disp('*******>');pause
% Downsample by 4
x = reshape(y,4,N/4);
x2 = x(1,:);
t=[0:length(x2)-1]'/(fs/4);
figure, plot(t,x2)
xlabel('Time (sec)')
ylabel('local')
title('Signal downsampled by a factor of 4')
disp('Play drum sound track downsampled by a factor of 4')
sound(x2,fs/4)
disp('*******>');pause
disp('Frequency spectrum of downsampled drum sound track')
x2fft = fft(x2);
% frequency scale
df = (fs/4)/(N/4);
f = [0:df:fs/4-df];
figure, plot(f,abs(x2fft))
xlabel('Frequency (Hz)')
ylabel('Magnitude of frequency response')
disp('*******>');pause
% Downsample by 8
x = reshape(y,8,N/8);
x3 = x(1,:);
t=[0:length(x3)-1]'/(fs/8);
figure, plot(t,x3)
xlabel('Time (sec)')
ylabel('local')
title('Signal downsampled by a factor of 8')
disp('Play drum sound track downsampled by a factor of 8')
sound(x3,fs/8)
disp('*******>');pause
disp('Frequency spectrum of downsampled drum sound track')
x3fft = fft(x3);
% frequency scale
df = (fs/8)/(N/8);
f = [0:df:fs/8-df];
figure, plot(f,abs(x3fft))
xlabel('Frequency (Hz)')
ylabel('Magnitude of frequency response')
disp('End of Comprehensive Problem CP5.1')
%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -