clear
clc
f0=10000
f=[10 50 100]
fs=500
N=500
num=length(f)
s=zeros(1,N)
for i=1:num
s=s+sin(f(i)*2*pi*(1:N)/f0)
end
plot(s,'携槐Color',[73 86 142]./255, 'LineWidth',2)axis([1 N/2 min(s) max(s)])
deltaN=f0/fs
Ns=N/deltaN
for i=1:Ns
sd(i)=s((i-1)*deltaN+1)
end
sp=[]
for 辩灶友i=1:Ns
sp=[sp sd(i)*ones(1,deltaN)]
end
hold on
plot(sp,'Color',[87 141 98]./255,'辩戚LineWidth',2)axis([1 N/2 min(s) max(s)])
Wm=fs/f0
level=5/Wm
Nm=ceil(Wm/2*level)
H=zeros(1,level)
H(1:Nm)=ones(1,Nm)
H(Nm+1)=0.5
H(level-Nm+1)=-0.5
H(level-Nm+2:level)=-ones(1,Nm-1)
theta=-(level-1)/level*pi*(0:level-1)
Hg=H.*exp(j*theta)
b=real(ifft(Hg))
b=b/(sum(b.^2))
delay=level/2
sp=[sp zeros(1,delay)]
so=filter(b,1,sp)
so=so(delay+1:delay+N)/deltaN
plot(so,'Color',[212 57 63]./255,'LineWidth',2)axis([1 N/2 min(s) max(s)])
grid on
clcclose all
clear all
a=4
f0=0.02
L=50
n=1:(L-1)
x=a.*cos(2.*pi.*f0.*n)
bit=5
range=2^5
plot(x)
interval=(a*2)/(range-1)
partition = [-a:interval:a]
interval2 = (a*2)/(range)
codebook=[-a:interval2:a]
[index quantized]= quantiz(x,partition,codebook)
plot(n,x,'升渣x',n,quantized,'.')
legend('Original signal'轮滚,'Quantized signal')
%index为输出5bit输出数字信号
%下面从index到output
output=(index-16)/4
figure
plot(n,x,n,output)
legend('吵桐悄Original signal','Output signal')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)