You are on page 1of 8

# BO CO LAB4

Exercise 1:Synthesizer
1)To script file synthesizer.m
% sigsynth
Fs=11025;
soundsc(trumpet,Fs);

## 3)V th ngun am thanh Trumpet.mat

Figure(1);
plot(trumpet(200:400));
axis tight % looks very periodic
wavwrite(trumpet,Fs,'trumpet.wav')

4) th ph tn

## Y = fft(trumpet, 512); % take the

fft of trumpet
Ymag = abs(Y); % take the mag of Y
f = Fs * (0:256)/512; % get a
meaningful axis
subplot(3,1,2);
plot(f, Ymag(1:257)); % plot Ymag
(only half the points are needed)
xlabel('Frequency (Hz)')
ylabel('Magnitude')
axis tight

## T th ph tn ca tnh hiu m thanh trumpet ta xc nh

c 7 im c li cao nht
Freg 258.
4
Mag 11.8

538.
3
37.8

796.7

1055

1335

1593

1852

65

52.3

52.6

39

28.3

s=zeros(1,length(t));
for i=1:5
s=s+[mag(i)*cos(2*pi*freq(i)*t)];
end
end
8) Script
t=0:1/Fs:3;
freq=[258.4 538.3 796.7 1055 1335 1593 1852];
mag=[11.8 37.8 65 52.3 52.6 39 28.3];
s=0.999*s/max(abs(s));
subplot(3,1,3);
plot(s(200:400))
soundsc(s,Fs)
wavwrite(s,Fs,'sigsynth1.wav');

Figure:

## +) th tnh hiu m thanh trong khoang 200:880 cua

tinh hiu vo kh tng ng nhau
+) th tnh hiu m thanh sau khi ly mu t tnh hiu
sau khi ly mu ti nhng im tn c li cao nht
Tnh hiu khng cn ging vi tnh hiu m thanh t file
trumpet na:
-)Bin cao nht ti di tn cha ph tn c li
ln nht
-)m thanh sau khi iu ch trm hn tnh hiu vo
do nhng tn s cao (nhiu) b loi b

Exercise 2:
1)Tao script file phasefun.m
2)To tnh hiu sig1,sig2
Fs=8000;
t=0:1/Fs:1;
f1=200;
f2=300;
a=2*cos(2*pi*f1*t);
b=3*cos(2*pi*f2*t);
sig1=a+b;

sig2=2*cos(2*pi*f1*(t-1/(2*f1)))+3*cos(2*pi*f2*(t-1/(2*f2)));

## 4) th hai tinh hiu

Tnh hiu sig2 sau khi delay(sig1) b chm pha so vi tinh hieu
5)To tnh hiu sig3,sig4
sig3=cos(2*pi*500*t);
sig4=sig3+cos(2*pi*500*(t-1/(4*500)));

6)script
Fs=8000;
t=0:1/Fs:1;
f1=200;
f2=300;
a=2*cos(2*pi*f1*t);
b=3*cos(2*pi*f2*t);
sig1=a+b;
sig2=2*cos(2*pi*f1*(t-1/(2*f1)))+3*cos(2*pi*f2*(t-1/(2*f2)));
subplot(2,1,1);
plot(sig1(1:1000));
xlabel('Fre quency (Hz)')
ylabel('Mag nitude')
subplot(2,1,2);
plot(sig2(1:1000));
xlabel('Fre quency (Hz)')
ylabel('Mag nitude')
soundsc(sig1,Fs);
soundsc(sig2,Fs);
sig3=cos(2*pi*500*t);
sig4=sig3+cos(2*pi*500*(t-1/(4*500)));
figure(2)
subplot(2,1,1);
plot(sig3(1:300));
xlabel('Fre quency (Hz)')
ylabel('Mag nitude')
subplot(2,1,2);
plot(sig4(1:300));
xlabel('Fre quency (Hz)')
ylabel('Mag nitude')
soundsc(sig3,Fs)
soundsc(sig4,Fs)

## Exercise 3: Gibbs phenomena

1)To file gibb.m
2) thi
Code:
k=-10:10;
subplot(2,1,1);
figure(1);
plot(abs(Ck(k)));
xlabel('Frequency (Hz)')
ylabel('Magnitude')
subplot(2,1,2);
plot(angle(Ck(k)));
xlabel('Frequency (Hz)')
ylabel('phase')
figure(2)
subplot(2,1,1);
stem(abs(Ck(k)))
subplot(2,1,2);
stem(angle(Ck(k)))

a-trc khi ly mu

## b-sau khi lay mau

4)Ham gibbs.m
function [sigsynth]=gibbs(kmax)
t=-5:0.1:5;
k=[-kmax:kmax];
fct=Ck(k);
mag=abs(fct);
pha=angle(fct);
sigsynth=zeros(1,length(t));
for i=kmax+1:length(k)
sigsynth = sigsynth + 2*mag(i)*cos((i-kmax)*t+pha(i));
end

5)script:
t=-5:0.01:5;
gibb_1=gibbs(t,5);
gibb_2=gibbs(t,15);
gibb_3=gibbs(t,30);
figure(3);
subplot(3,1,1);
plot(gibb_1);
subplot(3,1,2);
plot(gibb_2);
subplot(3,1,3);
plot(gibb_3);