+ All Categories
Home > Documents > lab china 2010 lab all - eit.lth.se · Digital Signal Processing ETI265 2010 Introduction In the...

lab china 2010 lab all - eit.lth.se · Digital Signal Processing ETI265 2010 Introduction In the...

Date post: 15-Sep-2018
Category:
Upload: ngotuyen
View: 220 times
Download: 2 times
Share this document with a friend
26
2010
Transcript

  

                                   

 

2010

Digital Signal Processing ETI265 2010

Introduction In the course we have 3 laboratory works for 2009. Each laboratory work is a 2 hours lesson. We will use MATLAB for illustrate some features in digital signal processing. We will also use the DSK 6713 DSP kit from Texas Instruments for real time digital signal processing, combined with Matlab. The programs in the DSK are started from Matlab. For this year, there are at lot of uncertainty about the computers and equipment. We have to be prepared to use only Matlab and also to have problems running Matlab together with Texas Instruments program CCS. The three laboratory works planned for this year are Lab 1: Real time spectral analysis using Fourier transform Equipment: PC with Matlab and input/output of sound. Matlab: 7.04 Matlab toolboxes: Signal Processing toolbox Data acquisition toolbox Lab 2: Audio processing in Texas DSK 6713

Equipment: PC with Matlab and input/output of sound. Matlab: 7.04 Matlab toolboxes: Signal Processing toolbox Data acquisition toolbox CCS toolbox Texas Instruments: DSK6713 starters kit Lab 3: Audio processing in Texas DSK 6713

Equipment: PC with Matlab and input/output of sound. Matlab: 7.04 Matlab toolboxes: Signal Processing toolbox Data acquisition toolbox CCS toolbox Texas Instruments: DSK6713 starters kit

Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital signal processing. Start Matlab and update the Matlab path. Connect the microphone to PC ’ mic in’ connector. You can use the speakers in the PC or connect external headphones. Task 1. Real time spectral analysis using Fourier transform Start Matlab. At the Matlab prompt, type sigfftio_lin (or sigfftio_log or demoai_fft’) Now a spectrum analyzing window will be opened, see below

Item 1: Say the word ‘smile’ slowly and look at the spectra of the vowels ‘i’ and ‘e’. Fill in the diagram below and estimate the pitch. My pitch is…………...(some mean value). Item 2: Try to generate a sound with as flat spectrum as possible. (‘oral white noise’)

Task 2. Real time spectrogram A spectrogram is a time-frequency plot of the signal. A sliding window is applied to the signal and the short time Fourier transform are determined for each time-window. The plot has time on the x-axis and frequency on the y-axis. See help spectrogram for more information Type N=20000; Fmax=4000; record_spectra_china % N=no of samples (Fs=10 kHz),

%Fmax = max freq in the plot (<5000 Hz) Now 2 seconds of ‘mic in’ will be recorded and then the spectrogram will be shown. (Increase N if you want to have longer sequences)

Item 1: Pronounce the Chinese words below and see if you have the correct

pitch (tone). Let the Chinese students show the correct pitch.

Use also some Swedish words with Chinese tone.

Item 2: In Swedish we have two tones (accent). Try the Swedish words A: ‘anden’, ‘the duck’ (bird) B: ‘anden’, ‘the ghost, The Swedish students have to learn the Chinese students the correct pitch.

Task 3. Estimation of impulse responses using correlation Correlation functions are often used in estimation of unknown systems. This is described in the textbook pages 99-101 and in the slides from the second lecture.. Input – Output Relations using correlation functions (from the slides)

    Autocorrelation function for the output 

    )()()()()()( lhlhlriflrlrlr hhxxhhyy −∗=∗=  Cross correlation function for input‐output signal 

    )()()( lrlhlr xxyx ∗=  

If the autocorrelation for the input is a delta function, )()( llrxx δ= , we

direct have the impulse response )()( lrlh yx= .

If the autocorrelation for the input is not a delta function, we have to estimate the impulse response from the expression for the cross correlation. This is not included in this course. But still, we can find a lot of information even in this case. We will here use pre-generated signals. In files on the computer there are pairs of input and output signals from various unknown filters. Try to estimate these impulse responses.

h(n) y(n) = h(n) * x(n) x(n)  

Item 1: Music noise through an echo filter. Type the command below load sig_music; x=sig_music(:,1); y=sig_music(:,2); soundsc(x,10000); pause(10), soundsc(y,10000); Use also the plot command to plot parts of the signals. subplot(211), plot(x), subplot(212), plot(y) % Plot input and output First, can you now here the delay part (echoes). N0=1000;[rxx,n]=lab_sigcorr(x,x,N0);plot(n,rxx);grid on % input auto correlation N0=1000;[ryx,n]=lab_sigcorr(y,x,N0);plot(n,ryx);grid on % cross correlation N0=1000;[ryy,n]=lab_sigcorr(y,y,N0);plot(n,ryy);grid on % autocorrelation First, can you now here the delay part (echoes). N0=1000;[rxx,n]=lab_sigcorr(x,x,N0);plot(n,rxx);grid on % input auto correlation N0=1000;[ryx,n]=lab_sigcorr(y,x,N0);plot(n,ryx);grid on % cross correlation N0=1000;[ryy,n]=lab_sigcorr(y,y,N0);plot(n,ryy);grid on % autocorrelation Estimate the delay in the impulse response. The delay is ……...ms. Item 2: White noise through an echo filter. Type the command below load sig_noise; x=sig_noise(:,1);y=sig_noise(:,2); % Load input and output data Note: Decrease the pause to 10 s. soundsc(x,10000);pause(4),soundsc(y,10000); % Listen to input and output Use also the plot command to plot parts of the signals. subplot(211), plot(x), subplot(212), plot(y) % Plot input and output Now, determine and plot the correlation functions N0=1000;[rxx,n]=lab_sigcorr(x,x,N0);plot(n,rxx);grid on % input auto correlation N0=1000;[ryx,n]=lab_sigcorr(y,x,N0);plot(n,ryx);grid on % in-out cross correlation N0=1000;[ryy,n]=lab_sigcorr(y,y,N0);plot(n,ryy);grid on % output autocorrelation Estimate the delay in the impulse response. The delay is ……...ms. Item 3: A swept sinusoid (swept sinusoids) through a echo filter. Type: load sig_sweep; x=sig_sweep(:,1);y=sig_sweep(:,2); % Load the signals soundsc(x,10000);pause(2),soundsc(y,10000); % Listen to the input and output Use also the plot command to plot parts of the signals.

subplot(211), plot(x), subplot(212), plot(y) % Plot input and output Can you here the delay part. My guess of the delay , …………ms Now, compute the autocorrelation of the output and the cross correlation between in and out. Type N0=1000;[rxx,n]=lab_sigcorr(x,x,N0);plot(n,rxx);grid on % input auto correlation N0=1000;[ryx,n]=lab_sigcorr(y,x,N0);plot(n,ryx);grid on % in-out cross correlation N0=1000;[ryy,n]=lab_sigcorr(y,y,N0);plot(n,ryy);grid on % output autocorrelation Estimate the delay in the impulse response. The delay is ……...ms. Item 4: White noise through a band pass filter. Type the command below load sig_bandpass_noise; x=sig_bandpass_noise(:,1);y=sig_bandpass_noise(:,2); soundsc(x,10000);pause(3),soundsc(y,10000); N0=1000;[rxx,n]=lab_sigcorr(x,x,N0);plot(n,rxx);grid on % input auto correlation N0=1000;[ryx,n]=lab_sigcorr(y,x,N0);plot(n,ryx);grid on % cross correlation N0=1000;[ryy,n]=lab_sigcorr(y,y,N0);plot(n,ryy);grid on % autocorrelation You can here that the output signal is a narrow band signal. Check the spectrum by taking the Fourier transform of ryx(n) by typing sigfftp(ryx,10000,10000,1000); % plot spectra up to 1 kHz, Fs=10 kHz Item 5: Speech through a GSM phone We know that the signal passing through a GSM system are delayed. How much?. A signal before and after passing the GSM phone is stored in a file (sample rate 10 kHz). Type the command below load sig_gsm; x=sig_gsm(:,1);y=sig_gsm(:,2); soundsc(x,10000);pause(3),soundsc(y,10000); Determine the delay using the correlation functions N0=1000;[ryx,n]=lab_sigcorr(y,x,N0);plot(n,ryx);grid on % cross correlation N0=1000;[ryy,n]=lab_sigcorr(y,y,N0);plot(n,ryy);grid on % autocorrelation The delay is ………..ms.

Item 6: Estimate the echo-system in the DSK (if the DSK 6713 board available) Estimation of impulse responses of a system running in the DSK using correlation We will do this with a minimum of instruments. Using portable PCs: Portable PC:s have only microphone input which is a monophonic input means that we cannot simultaneous record booth input and output. Stationary PCs: Here we normally have both microphone input (monophonic) and line input (stereophonic). Type init_digsig Connect the DSK as shown in the figure and in the text but connect the microphone to ‘mic in’ on the DSK instead. Then, connect ‘line out’ from the DSK to ‘line in’ on the PC. Finally, connect the headphone (or speaker) to the PC. Start the DSK by typing the following in Matlab setDSPopen_echo_mic Now the program CCS from Texas Instruments start and the echo program is downloaded to the DSP and executed. Talk into the microphone and listen. Can you here the echoes. Now we want to use correlation to estimate the delay of the echoes. Type the command below to estimate the cross correlation and make some noise (white noise) or spikes into the microphone. Nloop=1;Ntot=25001;Fs=10000;record_crosscorr_high Type the command below to estimate the autocorrelation Nloop=1;Ntot=25001;Fs=10000;record_autocorr_high

Digital Signal Processing ETI265 China 2010 Laboratory work 2: Digital Audio technique in real time Introduction In this laboratory work we will use the DSK 6713 DSP kit from Texas Instruments and CCS-software from Texas instruments. We also use Matlab in parallel. The program in the DSP can be started from Matlab if the CCS-Matlab toolbox is installed. This is not the case here. Instead, programs in the DSP are loaded direct for each task in the laboratory work. Type init_digsig to see how the DSP shall be connected. Start CCS by clicking at the icon. Then file --> load program --> then select ***.out files corresponding to the task below from the directory C:\lib_digsig_china\lab_china_out\***.out Task 1. Check effects of echoes The echo processor delays the signal D samples and multiply the signal with the damping factor a , |a|<1 (gainD).

A number of precompiled files (**.out) with different values of the delay 'D' and 'gainM' and 'gainD' are stored in the PC. load this out-files into the DSP by 'file' ---> 'load program' then press 'debug' ---> 'run' to start the program Load and run 'echo_fir_D50ms_N1.out' D=50ms, gainM=1,gainD=.8 'echo_fir_D100ms_N1.out' D=100ms, gainM=1,gainD=.8 'echo_fir_D200ms_N1.out' D=200ms, gainM=1,gainD=.8 Try to read some text and listen the output from the system below at the same time. 'delay_fir_D50ms_N1.out' D=50ms, gainM=0,gainD=.8 'delay_fir_D100ms_N1.out' D=100ms, gainM=0,gainD=.8 'delay_fir_D200ms_N1.out' D=200ms, gainM=0,gainD=.8

Task 2. Check effects of echoes, 3 echoes Add some more delay lines shown as shown in the figure below.

Load and run the program 'echo_fir_D50ms_N3.out' Talk in the microphone and listen. IIR echo circuit

Load and run the program 'echo_iir_D50ms.out' D=50ms, gainM=1,gainD=.8 'echo_iir_D100ms.out' D=100ms, gainM=1,gainD=.8 'echo_iir_D200ms.out' D=200ms, gainM=1,gainD=.8

Task 3 A simple reverb is shown in the figure. The total delay are

)2cos( nFreqswingdelaydelaytotal ⋅⋅+= π for each part.

A more complex reverb is preprogrammed and the program can be downloaded. Load the following program to listen to different sound effects. Load and run 'echo_small_room.out' 'echo_large_room.out' 'echo_large_hall.out' Use the microphone or play the file 'c:\lib_digsig_ti_lab\labprojects\china_out\mama.wav' using 'Sound Recorder' in the PC.

Task 4 Speech scrambler A time-discrete system is given by the figure above. First, listen to signals through this system (talk into the microphone). Use the microphone or play the file 'c:\lib_digsig_ti_lab\labprojects\china_out\mama.wav' using 'Sound Recorder' in the PC. Load and run 'changsign.out' Then, try to analyze the system: assume that the input )1.02cos()( nnx π= . Determine the output. Hint: Draw the spectra for x(n) and y(n). Spectrum |X(f)| and |Y(f)|.

cos(2π 0.5 n)=(‐1)n

x(n)  y(n)

Task 5: SSB-modulator A time-discrete system is given below (SSB modulator). First, listen to signals through this system (sampling rate=8000 Hz). Use the microphone or play the file 'c:\lib_digsig_ti_lab\labprojects\china_out\mama.wav' using 'Sound Recorder' in the PC. Load and run the following programs and listen. 'dsp_ssbdemo_off0.out' : delta F=0 Hz , delta f=0 'dsp_ssbdemo_off100.out': delta F=100 Hz, delta f=100/8000 'dsp_ssbdemo_off200.out' delta F=200 Hz delta f=200/8000 Then, try to analyze the system: Assume that the input is )1.02cos()( nnx π= . Determine the output. Hint: Draw the spectra for in the points A, B, C, D and E for delta f=0.025 in the figure below. What's happen if delta f is zero and non-zero, respectively?

Hlowpass(f)Hlowpass(f)C 

y(n)x(n) 

B  D  E A 

1 0.75 f0.25  0.5

| Hlow pass (f)| 

2

Appendix Files in c:\lib_digsig_ti_lab\labprojects\china_out\ 

  Matlab codes for speech scrambler and SSB mod/demodulator %ssb.m demo of SSB-mod/demoulation bm 2009 % Use: N=20000;deltaf=0.025;,ssb f0=.1; fc=.25; n=1:N; hlp=fir1(500,2*.25); xa=sin(2*pi*f0*n); xb=xa.*sin(2*pi*fc*n); xc=filter(hlp,1,xb); xd=xc.*cos(2*pi*(fc+deltaf)*n); xe=filter(hlp,1,xd); subplot(511),sigfftp(xa,1,N); subplot(512),sigfftp(xb,1,N); subplot(513),sigfftp(xc,1,N); subplot(514),sigfftp(xd,1,N); subplot(515),sigfftp(xe,1,N); %speech_scrambler.m demo of speech scrambler bm 2009 % Use: N=20000;speech_scrambler f0=.1; n=1:N; x=sin(2*pi*f0*n); y=(-1).^n.*x; subplot(511),sigfftp(x,1,N,1); subplot(512),sigfftp(y,1,N,1);

Digital Signal Processing ETI265 China 2010 Laboratory work 3: Design of IIR filters Introduction In this laboratory work we will design FIR and IIR filters. First, we will show the relation between pole-zero plots and the magnitude spectra and impulse responses for digital filters. The we will design notch filters which will be tested in both Matlab and in the DSK 6713 DSP kit from Texas Instruments. Preparation exercise 1 Combine the pole-zero plot and the magnitude spectra |H(f)| below. Show the pair of pole-zero plot and magnitude spectra corresponding to the same system. Pole-zero plot Magnitude spectra |H(f)|

Preparation exercise 2 Sketch the magnitude spectra |H(f)| for the given the pole-zero plots. Pole-zero plot Magnitude spectra |H(f)|

Laboratory tasks IIR filter The program MKIIR is used for interactive IIR filter design. You can place poles and zeros in the pole-zero plane and then show the impulse response, magnitude spectra and phase function for the digital system. The program can also design filters from specification of requirements of magnitude spectra. A set of standard filters are also included in the program.

Task 1 Type MKIIR to start the program at the Matlab prompt. Place a pole or a pair of complex poles in the z plane and check the result. Press first Replace last. Move the pole inside the unit circle and check the result. Specially, look at the relation of the magnitude and angle of the poles and the magnitude spectra and the impulse response. Release Replace last.

Task 2 Choose poles and zeros for fulfilling the demands below based on your experience from task 1. Press Import Workspace and open the file irspec1.mat to load the specifications into MKIIR.

Now, choose poles and zeros to fulfill the requirements. You can ave your filter with Export Workspace and choose a file name (i.e.filter1.mat. Then press Import filter to reload the filter. Optional task Compare with standard filter solutions. Stop the program MKIIR, press Exit. Task 3 Now, you will examine notch filters. The system function for both the FIR filter and the IIR filter are given below

with 0ω the frequency which shall be cancelled. Plot the magnitude spectra for the filters with varying position of the poles and zeros using the program MKIIR . Alternatively, you can use Matlab direct and typing your system function above (FIR). w0=2*pi*0.2; f=0:.01:1;z=exp(j*2*pi*f);Hfir=1-2*cos(w0)*z.^(-1)+z.^(-2);plot(f,abs(Hfir));

Task 4 In this task, you shall cancel sinusoids added to music files. Sampling rate 8000 Hz, stereo. Call global S, jukebox, song=S; and choose a song from the list. You must choose one of the first 5 for testing in the DSP. The variable S will contents 100000 samples from the song and it is stored in the variable 'song' for future use. Listen to the song (small part) soundsc(song,8000); Use Windows "Sound recorder" to listen to the whole song. Avoid long files in Matlab due to difficulties to stop the sound outputs in Matlab. Now, use MKSPA to determine the frequencies of the sinusoids. Press PEAK and use the mouse to point at peaks in the spectrum. The frequencies are multiples of 10 Hz. Write down the frequencies for the peaks of your song. Press Exit to stop MKSPA. Now, you shall determine a notch filter which cancel the sinusoids. Try both FIR and IIR filters. Type your choice of poles and zeros in Matlab and put them into vectors. Then, determine the A and B polynomials. Example: z1=exp(-j*2*pi*F1/Fs); z2=conj(z1); z3=exp(-j*2*pi*F2/Fs); z4=conj(z1); z5=exp(-j*2*pi*F3/Fs); z6=conj(z1); Z=[z1,z2,z3,z4,z5,z6]; P=0.9*Z; B=poly(Z) A=poly(P) zplane(B,A) % check pole-zero plot plot also the magnitude spectrum for your filter (see help freqz)

f=0:.01:1; w=2*pi*f; H=freqz(B,1,w); plot(f,abs(H)); %FIR f=0:.01:1; w=2*pi*f; H=freqz(B,A,w); plot(f,abs(H)); %IIR

Notice: You must use j for the imagine part. Test the filter using MKIIR.

Test the filter in Matlab You have already a small part of the song in the global variable 'song'. If not, reloaded using: song=wavread('ssilence',[1 100000]); % load 100 000 value Listen to the disturbed song (no filtering) soundsc(song, 8000); % listen Fs=8 kHz Filter the song with your filters, both the FIR and the IIR filter and listen. y0=filter(B,1,song); soundsc(y0, 8000); y1=filter(B,A,song); soundsc(y1, 8000); Did your filters fulfill the requirements? Test the filter in the DSP if Matlab toolbox CCS is installed Then, download the filter to the DSP. Type global cc B A, filter_menu. Press Open DSP and wait until the DSP has started. Play your song and test your filter using Download. Test both the FIR and the IIR filter. Test the filter in the DSP if the Matlab toolbox CCS not is installed Load the selected sound file (see appendix) into the 'sound recorder'. 'c:/lib_digsig_china\soundfiles\ssilence.wav' Load the precompiled programs with the correct filter coefficients into the DSP by 'file' ---> 'load program' select your program FIR: c:\lib_digsig\china_out\notch_fir_ssilence.out (see appendix) then press 'debug' ---> 'run' to start the program. Start the output from the sound recorder and listen. Then, select program IIR: c:\lib_digsig\china_out\notch_iir_ssilence.out (see appendix) then press 'debug' ---> 'run' to start the program. Start the output from the sound recorder and listen. Test the filter in the DSP if the Matlab toolbox CCS not is installed, advanced Load the selected sound file into the sound recorder. Open the project 'c:\lib_digsig_china\\lab_iir\pip_iir.pjt' in CCS, open the c-code and point to the variable 'IIRFIRsw'. Load the precompiled program with the correct filter coefficients into the DSP by 'file' ---> 'load program', select your program (see appendix) then press 'debug' ---> 'run' to start the program. Mark the variable, press right mouse button and select 'quick watch'. Now, you can change this variable. This variable controls if the filter is active or not and the variable can be change

during execution of the program. IIRFIRsw=0 means no filter, IIRFIRsw=1 means FIR filter and IIRFIRsw=2 means IIR filter.

Appendix: Program descriptions IIR filter design, MKIIR MKIIR can be used for interactive filter design from poles and zeros.

Function Import Workspace: Read filter specifications from file. Export Workspace: Save filter specifications on file. Set filter specs: Input filter specifications. Filter coeffs: Input filter coefficients. Help: Not implemented yet. About: Program version. Reset: Resets poles and zeros but not filter specifications. Exit: Exits and save workspace to the file current.mat . Add pole: Place pole, press left mouse button, ends with

right mouse button. Delete pole: Place cursor over pole, press left mouse

button to delete, ends with right mouse button. Add zero: Set Add pole Delete zero: See delete pole

Move: See add pole Import filter: Import of standard filters from Matlab

Signal Processing Toolbox. Magnitude: Magnitude function. Phase: Phase function. Impulse: Impulse response. Replace last: Replace last Reciproc Zeros: HighPass: High pass filter |H(f)|_{| f=0.5}=1,

Low pass filter |H(f)|_{| f=0}=1. Zoom: Zoom. Unwrap; Phase Unwrap Phase. Focus: Radius Adjust Gain: Adjust Gain in dB.

Spectral analysis, MKSPA MKSPA is used to analyze the spectra in the sound files.

Functions Window: Window functions. FFT length: FFT length. Overlap: Number of overlapping segments Fs(Hz): Sampling frequency. Zoom: Activate/deactivate Matlab zoom Analyze: Analyze Exit End the program.  

Appendix: Sound files used in Laboratory work 3   

Directory:    c:\lib_digsig_soundfiles 

Matlab:    

   


Recommended