Matlab code solulions for Hmwk 2 problem 4 (Word Doc)

advertisement
4. Matlab code and representative figures are shown below. (Homework 2 Solutions, Spring 2005.)
% hmwk2_feb05.m
s1=wavread('sent1.wav')'; % Read in sentence 1
s3=wavread('sent3.wav')'; % Read in sentence 2
x1=interp(s1,8); % Increase the speech sampling rate to 64 kHz
x3=interp(s3,8);
X1=fft(x1); % Compute the spectrum of the in-phase and quadrature signals
X3=fft(x3);
T=1/64000; % The simulation sampling rate is 65 kHz
t=[0:length(x1)-1]*T;
fc=12000; % The QAM carrier frequency is 12 kHz
y=x1.*cos(2*pi*fc*t)+x3.*sin(2*pi*fc*t); % Generate the QAM waveform
Y=fft(y);
f64=[0:length(t)-1]/(length(t)*T);
figure(1), subplot(3,1,1), plot(f64,abs(X1)) % In-phase signal spectrum
subplot(3,1,2), plot(f64,abs(X3)) % Quadrature signal spectrum
subplot(3,1,3), plot(f64,abs(Y)) % Plot the spectrum of the QAM signal
% Add in effect of channel noise. Assume no band-pass filter.
sigPow=sum(y.*y)/length(y); % Compute the signal power per sample.
noisePow=sigPow; % Set noise power equal to the signal power per sample.
stddev=sqrt(noisePow); % Set noise standard deviation to square root of power.
noise=stddev*randn(1,length(y)); % Use Gaussian random number generator to >>
% generate AWGN.
yn=y+noise; % Add noise to modulated signal, so SNR = 0 dB.
Yn=fft(yn);
figure(2), subplot(3,1,1)
plot(f64,abs(Yn)) % Plot spectrum of the channel output signal with noise
% A suitable FIR bandpass filter can be generated as follows.
fbeb=[0 6000*2*T 8000*2*T 16000*2*T 18000*2*T 1];
dampsb=[0 0 1 1 0 0];
bbp=remez(fl,fbeb,dampsb);
Bbp=fft(bbp,256); % Compute frequency response of band-pass filter
f256=[0:255]/(256*T); % Compute frequency vector for filter frequency response
% plot(abs(Bbp))
% plot(20*log10(abs(Bbp)))
% Apply bandpass filter to the noisy QAM signal.
ybpf=filter(bbp,1,yn);
Ybpf=fft(ybpf);
subplot(3,1,2), plot(f64,abs(Ybpf)) % Plot spectrum of bandpass filter output
delay=T*fl/2;
% The bandpass filter has a delay of fl/2 samples.
% Demodulation
theta = 0; % theta is the receiver phase error
yin=ybpf*2.*cos(2*pi*fc*(t-delay)+theta); % Demodulate the in-phase component
yquad=ybpf*2.*sin(2*pi*fc*(t-delay)+theta); % Demodulate the quadrature
component
Yin=fft(yin);
Yquad=fft(yquad);
subplot(3,1,3)
plot(f64,abs(Yin),f64,abs(Yquad),f64,abs(Y)) % Plot the spectrum after mixer
% Apply the output lowpass filter
fl=100; % The FIR filter impulse response length is fl+1
fbe=[0 3400*2*T 6000*2*T 1]; % Define FIR low-pass filter parameters
damps=[1 1 0 0];
% Frequencies are scaled by 2*T in Remez design
b=remez(fl,fbe,damps); % Generate FIR low-pass filter coefficients
B=fft(b,256); % Compute low-pass filter frequency response
xin=filter(b,1,yin); % Low-pass filter the in-phase component
xquad=filter(b,1,yquad); % Low-pass filter the quadrature component
Xin=fft(xin);
Xquad=fft(xquad);
figure(3), subplot(3,1,1)
plot(f64,abs(Xin)) % Plot in-phase spectrum at low-pass filter output
subplot(3,1,2), plot(x1) % Plot input in-phase signal
subplot(3,1,3), plot(xin) % Plot output in-phase signal
xind=decimate(xin,8); % Decimate the in-phase signal to the original
xquadd=decimate(xquad,8); % speech sampling rate of 8 kHz
wavwrite(xind,8000,16,'s1_theta0.wav');
wavwrite(xquadd,8000,16,'s3_theta0.wav');
% sound(xind,8000); % play out the in-phase component speech
figure(4), subplot(2,1,1)
plot(f256,abs(Bbp)) % Plot band-pass filter frequency response
subplot(2,1,2), plot(f256,abs(B)) % Plot lpw-pass filter frequency response
%
%
%
%
%
%
Note that the filtering introduces a delay of (length-1)/2. So, the FIR
filters above all have length = 101, and hence delay of 50 samples.
When the band-pass filter is included in the % simulation, this delay must
be included in properly selecting the phase of the reference
sine and cosine for demodulation. e.g.., instead of using cos(2*pi*fc*t+theta),
use cos(2*pi*fc*(t-td)+theta), where td = n0*T, and n0 is the proper delay.
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Download