📄 firfil.m
字号:
clear
clc
Fs=16000;
N=2*Fs;
Ts=1/Fs;
%语音采样及量化
disp('please record first piece audio signal 3 seconds later')
pause(1)
disp('3')
pause(1)
disp('2')
pause(1)
disp('1')
disp('start!!!!!!!!!!!!!!!!!')
x1= wavrecord(N,Fs,'double');
wavplay(x1,Fs);
disp('please record second piece audio signal 3 seconds later')
pause(1)
disp('3')
pause(1)
disp('2')
pause(1)
disp('1')
disp('start!!!!!!!!!!!!!!!!!')
x2= wavrecord(N,Fs,'double');
wavplay(x2,Fs);
figure(1)
title('spectrum of first piece audio signal');
pinpu(x1,Fs);
%调制及混音
fc=8000;
w=2*pi*fc;
carrywave=rot90(cos(w*[0:Ts:length(x2)*Ts-Ts]));
x2=x2.*carrywave;
figure(2)
title('spectrum of second piece audio signal');
pinpu(x2,Fs);
wavplay(x2,Fs);
x=x1+x2;
figure(3)
title('spectrum of mix audio signal');
pinpu(x,Fs);
wavplay(x,Fs);
%FIR滤波器设计及验证
%b=fir1(48,[200,3400]/Fs*2,hamming(49));
chose=input('chose first piece audio signal please enter 1,\nchose second audio signal please enter 2:');
switch chose
case 1
f=[0 0.02 0.02 0.06 0.06 0.15 0.15 0.27 0.27 0.3 0.3 0.75 0.75 1];
m=[0 0 0.05 0.05 1 1 1 1 0 0 0 0 0 0];
b=fir2(47,f,m);
figure(4)
title('spectrum of digital filter');
freqz(b);
y=fftfilt(b,x);
A=2;
y=y*A;
figure(5)
title('spectrum of filtered first audio signal');
pinpu(y,Fs);
%解调
otherwise
fc1=8000;
w=2*pi*fc;
carrywave=rot90(cos(w*[0:Ts:length(x)*Ts-Ts]));
x=x.*carrywave;
figure(6)
title('spectrum of demodulation audio signal');
pinpu(x,Fs);
f=[0 0.02 0.02 0.06 0.06 0.15 0.15 0.27 0.27 0.3 0.3 0.75 0.75 1];
m=[0 0 0.05 0.05 1 1 1 1 0 0 0 0 0 0];
b=fir2(47,f,m);
y=fftfilt(b,x);
A=2;
y=y*A;
figure(7)
title('spectrum of filtered second audio signal');
pinpu(y,Fs);
wavplay(y,Fs);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -