📄 project.m
字号:
%Name of project:Audio Effets
%programmer: Faisal Mahmood (sp-03-44)
%Dated:May 13, 2003
close all;
clear all;
[x,fs] = wavread('myvoice.wav');%fs=22.05 kbps
%time delay
lenx=length(x);
%==========================================================================
%original voice
%==========================================================================
wavplay(x,fs);
pause
%==========================================================================
%single echo
%==========================================================================
a=0.5;
delay=0.2;%seconds
D=delay*fs;% samples
n=D+1:1:lenx;
y(n)=x(n)+a*x(n-D);
wavplay(y,fs);%delayed voice
%==========================================================================
%multiple echo-comb filter(non-recursive ie FIR)
%==========================================================================
n=3*D+1:1:lenx;
yc(n)=x(n)+a*x(n-D)+x(n-2*D)*a^2+a^3*x(n-3*D);
pause
wavplay(yc,fs);
%==========================================================================
%%Plain Reverberation(Recursive ie IIR))
%==========================================================================
n=D+1:1:lenx;
xr=x';%x is a column vector and y is a row vector so transposing x
yr(n)=xr(n)+a*y(n-D);
pause
wavplay(yr,fs);
%==========================================================================
%Compression by 9 throught 2 stages of M=3
%==========================================================================
M=3;
N=1215;
b=fir1(N,1/M);%Anti aliasing filter
y=conv(b,x);
pause
wavplay(y,fs);
pause
yd=y(1:M:end);
wavplay(yd,fs/3);%Decimated (M=3)sound
pause
ymd=yd(1:M:end);%more compression
wavplay(ymd,fs/9);
%==========================================================================
%Reconstruction(expansion)through an interpolator
%==========================================================================
L=3;
xz=zeros(1,L*length(ymd));
xz(1:L:L*length(ymd))=ymd;
%designing reconstruction filter
h=L*fir1(N,1/L);
yi=conv(h,xz);
pause
wavplay(yi,3*fs/9);
%more interpolation
xmz=zeros(1,L*length(yi));
xmz(1:L:L*length(yi))=yi;
ymi=conv(h,xmz);
pause
wavplay(ymi,3*3*fs/9);
%==========================================================================
%Reagarding ratio of compression and expansion
%==========================================================================
original_length=length(x)
decimated_by_3_length=length(yd)
decimated_by_9_length=length(ymd)
interpolated_by_3_length=length(yi)
interpolated_by_9_length=length(ymi)
%==========================================================================
%Noise Gating-Due to the conditional loops,this part of program is
%commented out,as it takes much time
%==========================================================================
%clear all;
%close all;
%[x,fs] = wavread('hello.wav');%fs=22.05 kbps
%y=x;%To play original as well as processed sound
%lenx=length(x);
%for i=1:lenx
% if(y<0.024)
% y(i,:)=0
% end
%end
%figure
%subplot(211)
%plot(x);
%subplot(212);
%plot(y);
%wavplay(x,fs);%original voice
%pause
%wavplay(y,fs); %noise gated sound
%==========================================================================
%Ring modulation (kind of a SC modulation)
%==========================================================================
f0=5;Fs=10000;
N=0:1/Fs:100;
x1=0.9*sin(2*pi*f0*N);%carrier signal
len_x=length(x);
len_x1=length(x1);
len=len_x1-len_x;
ym=([x' zeros(1,len)].*x1);%multiplying the carrier n modulating signal to get modulated signal
len_y=length(ym);
yn=ym(1:length(x));% in order to add with x,making yn's length = x's
y=x'+yn;%to make voice smooth adding the modulated output in input voice
pause
wavplay(y,fs);
%==========================================================================
%Phase Shifting or Phasing using an ALP of first order
%==========================================================================
b=[-0.3536+0.3536i 1];%implementing a APF with H(z)=(z-2*exp(j*pi/4)/(z-0.5*exp(j*pi/4)
a=[1 -0.3536-0.3536i];
y=filter(b,a,x);%x is a modulating signal
pause;
wavplay(abs(y),fs);
N=1024;
[h,w]=freqz(b,a,N,'whole');
figure
subplot(211);
plot(w/pi,abs(h));
legend('Magnitude Plot');
xlabel('Frequency in terms of pi');
subplot(212);
plot(w/pi,angle(h));
legend('Phase Plot');
xlabel('Frequency in terms of pi');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -