音频文件&&IIR滤波器&&加窗
1: clc;
2: clear all;
3: close all;
4: [x,fs,bits]=wavread('ding.wav',[1024 5120-1]);
5:
6: sound(x,fs,bits);
7: N=length(x);
8:
9: mywin1=window(@kaiser,N);%kaiser窗
10: mywin2=window(@hamming,N);%hamming窗
11: s1=x.*mywin1;%信号加kaiser窗
12: s2=x.*mywin2;%信号加hamming窗
13: spectrum_origin=abs(fftshift(fft(x,length(x))));%加hamming窗后信号频谱
14: spectrum1=abs(fftshift(fft(s1,length(s1))));%加hamming窗后信号频谱
15:
16: spectrum2=abs(fftshift(fft(s2,length(s2))));%加kaiser窗后信号频谱
17: spectrum=zeros(1,N);
18:
19: %%二次加窗算法部分
20: for i= 1:N
21: if isMax(i,spectrum1)==1
22: spectrum (i) = spectrum2(i);
23: else
24: spctrum (i) = spectrum1(i);
25: end
26:
27: end
28: f_coordinate=linspace(-fs/2,fs/2,N);%频率坐标
29:
30: figure;
31: subplot(211);
32: plot(f_coordinate, (spectrum_origin) );
33: title(' 频谱');
34: xlabel('频率');ylabel('幅度');
35: subplot(212);
36: plot(f_coordinate, (spectrum) );
37: title(' 频谱');
38: xlabel('频率');ylabel('幅度');
39:
40: %%%%%%%%%%%%%%%%%%%%%IIR filter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41: Fs = 22050; % Sampling Frequency
42:
43: Fpass = 5000; % Passband Frequency
44: Fstop = 6000; % Stopband Frequency
45: Apass = 1; % Passband Ripple (dB)
46: Astop = 80; % Stopband Attenuation (dB)
47: match = 'stopband'; % Band to match exactly
48:
49: % Construct an FDESIGN object and call its BUTTER method.
50: h = fdesign.lowpass(Fpass, Fstop, Apass, Astop, Fs);
51: Hd = design(h, 'butter', 'MatchExactly', match);
52:
53:
54: y=filter(Hd,x);
55:
56: N=length(y);
57:
58: mywin1=window(@kaiser,N);%kaiser窗
59: mywin2=window(@hamming,N);%hamming窗
60: s1=y.*mywin1;%信号加kaiser窗
61: s2=y.*mywin2;%信号加hamming窗
62: spectrum_origin=abs(fftshift(fft(y,length(y))));%加hamming窗后信号频谱
63: spectrum1=abs(fftshift(fft(s1,length(s1))));%加hamming窗后信号频谱
64:
65: spectrum2=abs(fftshift(fft(s2,length(s2))));%加kaiser窗后信号频谱
66: spectrum=zeros(1,N);
67:
68: %%二次加窗算法部分
69: for i= 1:N
70: if isMax(i,spectrum1)==1
71: spectrum (i) = spectrum2(i);
72: else
73: spctrum (i) = spectrum1(i);
74: end
75:
76: end
77: f_coordinate=linspace(-fs/2,fs/2,N);%频率坐标
78:
79: figure;
80: subplot(211);
81: plot(f_coordinate, (spectrum_origin) );
82: title(' 频谱');
83: xlabel('频率');ylabel('幅度');
84: subplot(212);
85: plot(f_coordinate, (spectrum) );
86: title(' 频谱');
87: xlabel('频率');ylabel('幅度');
88:
OPTIMISM, PASSION & HARDWORK