UNIVERSITY OF WARWICK School of Engineering ES905 MSc Signal Processing Module (2010) AM SIGNALS AND FILTERING EXERCISE Deadline: This is NOT for credit. It is best done before the first assignment. You will use the MATLAB package to design some FIR filters and use them to process some Amplitude Modulated (AM) Signals You may download copies of this document and useful files from the web: http://www2.warwick.ac.uk/fac/sci/eng/staff/rcs/msc/ The pages below are part of a self learning exercise. Copy the MATLAB files from the above website when instructed to do so. Think about the questions that have been posed and fill in the text boxes if you wish. Remember: This exercise is not for credit, just to aid your education. Do not hand your results in. 1
UNIVERSITY OF WARWICK School of Engineering ES905 Signal Processing, Assignment 1, Part A: AM Signals and Filtering Date: Introduction The exercise concerns the synthesis of some signals that are commonly found in communications systems. You will be adding noise to these signals. Filters will be designed to extract sinusoidal frequencies from the signals, and the noise content of the signals will be examined. You may plug headphones into the sockets at the front of some computers so that you can listen to the signals that you are observing as graphs on the screen. Matlab will be used extensively in this exercise. Before beginning, copy files: lab2_fir.m, lab2_synth.m, lab2_process.m, lab2_snr.m and noise_data.txt to your working directory. These can be found at: http://www2.warwick.ac.uk/fac/sci/eng/staff/rcs/msc/ass1/ Copy the files as instructed. FIR Filter Design File: lab2_fir.m Save to your local disk. Make sure it has.m extension and nothing else In this first experiment you are going to extract two sinusoids from a signal containing two added sinusoids. You will design FIR filters using the Remez exchange algorithm. In the lectures we studied a method to design FIR filters using frequency plane specification, and a Fourier series technique to obtain the filter s coefficients. Today you will use a CAD method which works by minimising the differences between the specified and actual filter responses. Open a Matlab window (Double click on the icon). Open lab2_fir.m by clicking File (top left corner), then open, and then select lab2_fir.m. An editor window will appear. To execute the code click debug, then run etc. Part 1 of the code concerns the synthesis of the signal to be filtered. Its specification is: First signal, x1, has frequency, = 100Hz, peak amplitude = 1V Second signal, x2, has frequency, x2 = 400Hz, peak amplitude = 1V Sampling frequency, fs = 2000Hz (ie folding frequency ff > 400 >,100Hz) Combined signal, x = x1 + x2. fs = 2000; t = 0:(1/fs):0.1; %Set up sampling intervals over a 0.1s period x1 = sin(2*pi*100*t); x2 = sin(2*pi*400*t); x = x1 + x2; subplot(3,1,1), plot(t,x) %Plot the signal against time title('the combined signal, x'); %Wait until <return> is pressed 2
The program will wait at the. Alternatively cut the required code and paste it to the Matlab window. Observe the signal. Does it appear to be correct? Can you see the summed sinusoids? Part 2 of the code concerns the specification of the 1 st filter. This will be low-pass with a nominal cut-off midway between 100Hz and 400Hz. However, for practicality, separate pass 0 to 225Hz), transition (225 to 275Hz), and stop bands (275 to folding frequency), are specified in vector: fhz0. fhz0 = [0 225 275 fs/2]; These are converted to be non-dimensional: f0 = fhz0/(fs/2); Next a vector containing the required gain of the filter at the specified frequencies appears. Eg Lowpass: [1 1 0 0], high-pass: [0 0 1 1], band-pass [0 0 1 1 0 0]. ml0 = [1 1 0 0]; Next the filter coefficients, brl are calculated. Notice the specification vectors f0 and ml0. The 60 is the order of the filter. [brl] = remez(60, f0, ml0); Observe how good the filter is by comparing the specification with its actual spectrum. fhz1 = linspace(0, fs/2, 50); om1 = 2*pi*fHz1; z = exp(sqrt(-1)*om1/fs); ml = abs(polyval(brl,z)); subplot(3,1,2), plot(fhz0, ml0, fhz1, ml) title('spectrum of low-pass filter'); ylabel(' G '); xlabel('frequency (Hz)'); Try designing some filters with different orders eg 6 and 20. Comment on the effect on the frequency response of changing the filter s order. Now return to filter order 60 and filter the signal to extract the low frequency sinusoid. y1 = filter(brl,1,x); subplot(3,1,3), plot(t,y1) title('the extracted low frequency signal, x'); 3
Comment on the lack of output for the 1 st 15ms. Now design and implement a high-pass filter to extract the 400Hz sinusoid from the signal. Plot three graphs:- Input signal against time; Modulus of filter gain against frequency; Output signal against time. Hints: (i) (ii) In the editor, copy the code for the low pass filter and modify it Display the 3 graphs, are they correct? Are the titles and labels correct? If so then give Matlab the command print and retrieve your hardcopy if you want one. Synthesise a Noisy AM Signal (File: lab2_synth.m) and (noise_data_10.txt) Read the file containing a random signal (noise) into array A. View and listen to a sample of the noise. %%% Read data from file produced by a C program into 1 x Flength array fid = fopen('noise_data_07.txt','r'); %open the file [A,Flength] = fscanf(fid,'%f',[1,inf]); %read the data into A A = A/300; A((Flength+1):(2*Flength)) = A; %adjust noise level and length plot(a(1:128)) title( Noise ); ylabel( Amplitude ); xlabel( Time (s) ); soundsc(a); %plot the 1 st 128 noise samples. Set a sampling frequency of 4kHz and create a 500Hz carrier wave. %%% Create carrier sinewave of length: 4.0secs, frequency: 500Hz fs = 4000; %sampling frequency 4000Hz t = 0:(1/fs):4.0; %create 'time' samples x1 = sin(2*pi*500*t); %create a 500Hz sinewave carrier subplot(3,1,1), plot(t(1:128),x1(1:128)) title('sample length of carrier wave'); soundsc(x1) Create a message signal. This will be an 80Hz sinusoid. Notice that its maximum amplitude has been limited to 0.3V. This will limit the modulation depth of the AM wave to ka = 0.3 as the carrier has a peak amplitude of 1V. AM wave, s( t) = Ac [1 + kam( t)]cos(2π f ct), where k a controls the modulation depth, f c is the carrier frequency, A c is the carrier peak amplitude, and m(t) is the message signal. %%% Create message signal sinewave of length: 4.0secs, frequency: 80Hz ka = 0.3; % modulation depth x2 = ka*sin(2*pi*80*t); subplot(3,1,2), plot(t(1:128),x2(1:128)) title('sample length of modulation wave'); soundsc(x2) 4
Create the AM signal, s %%% Amplitude modulate the carrier s = ((1 + x2).*x1); subplot(3,1,3), plot(t(1:128),s(1:128)) title('sample length of modulated carrier wave'); soundsc(s) Add noise to AM signal %%% Add noise to the AM signal n = A(1:(1 + (fs * 4.0))); % truncate noise sequence sn = s + n; % add noise to signal subplot(3,1,3), plot(t(1:128),sn(1:128)) title('sample length of noisy AM wave'); soundsc(sn) Three graphs should be visible on the PC screen:- Carrier wave against time; Message signal against time; Noisy AM signal against time. Obtain a printout of these on a single sheet of A4 if you wish. Process the Noisy AM Signal (File: lab2_process.m) In this section you will retrieve the message signal from the noisy AM signal that you synthesised in the previous section. This will be achieved by a three stage process :- (i) Band-pass filter the carrier wave, (ii) Rectify the modulated carrier, (iii) Low-pass filter the rectified carrier to obtain the message signal. (i) Band-pass filter the carrier wave. Design a filter. The filter is specified in the frequency domain. Transform the AM signal and view its spectrum. %%% Transform a sample of the AM signal to the frequency domain S=fft(sn(1:1024)); %use fast Fourier transform, sample length 1024 Sa=abs(S); % modulus of spectrum Sp=angle(S); %phase % Calibrate spectrum in Hz b = 1:1024; frs = (b-1)/1024*fs; % frequencies % plot graph clf % clear screen subplot(3,1,1), plot(frs,sa); title('spectrum of AM wave'); ylabel(' Sa '); Observe the carrier and sidebands. You must design a filter to extract both the carrier and the sidebands. The gain will be [0 0 1 1 0 0]. Try significant frequencies [0 350 440 560 650 fs/2] Hz. %%% Tune in the carrier. That is band pass filter the AM signal %design the filter fhz = [0 350 440 560 650 fs/2]; mbp = [0 0 1 1 0 0]; %specify significant frequencies %magnitude specification of band-pass 5
f0 = fhz/(fs/2); b_bp = remez(120, f0, mbp); %non-dimensional significant frequencies % obtain filter coefficients %check the pass and stop bands of the filter fhz1 = linspace(0, fs/2, 50); om1 = 2*pi*fHz1; z = exp(sqrt(-1)*om1/fs); bp = abs(polyval(b_bp,z)); subplot(3,1,2), plot(fhz1,bp) title('band-pass filter characteristic'); Now tune in the noisy AM signal % filter the noisy AM signal am = filter(b_bp,1,sn); AM = abs(fft(am(1:1024))); % Check the spectrum of the filtered AM signal subplot(3,1,3), plot(frs,am); title('spectrum of tuned AM wave'); ylabel(' Sa '); xlabel('frequency (Hz)'); Obtain a printout of these three frequency domain plots if you wish. Now you can detect the message signal. Firstly rectify the AM wave. %%% Retrieve the message signal (80 Hz sinusoid) % View a sample of the tuned (received) AM signal clf subplot(3,1,1), plot(t(1:400),am(1:400)) title('received AM signal'); soundsc(am); % Rectify the AM signal rec = am; % copy the am to rec for i = 1:(fs*4.0), if am(i) < 0; rec(i) = 0; % reset all negative samples to 0 end end subplot(3,1,2), plot(t(1:400),rec(1:400)) title('rectified AM signal'); soundsc(rec); The rectified signal must now be low-pass filtered. Specify and implement such a filter, and then use it to recover the message signal. 6
Specification of the low-pass filter. Frequency specification Vector (Hz): [ ] Non-dimensional frequency specification vector: [ ] Gain specification vector: [ ] Filter order: Comment on the suitability of this filter: Display the following three graphs on the PC screen:- Received AM signal against time; Rectified signal against time; Detected (low-pass filtered) signal against time. Obtain a printout of these if you wish. Comment on the appearance of the message signal. Investigate the Noisy Signals (File: lab2_snr.m) Signal to Noise Ratio (SNR). We can define the receiver input SNR as the ratio of the average power of the modulated input signal, P s to the average power of the input noise P n. Ps SNR = 10log. Pn Estimate the SNR of the noisy AM signal. In this case there are two ways to proceed. Firstly, P s and P n can be estimated before they are added (not generally the case). Secondly they can be estimated from measurements on the noisy AM signal. Estimation before P s and P n are added. Obtain statistics on s(t) and n(t). You need to calculate the average power of each signal, ie sum the squares of the individual samples and divide by N, the number of samples. eg: 1 N 2 P = ( n k ). n k = 1 [ ] N Basically you are calculating the mean square value, and noting that the mean value of each signal is zero, you can use the variance (var) function to calculate the average power of each signal. %%% Estimate SNR before addition of am signal and noise % Estimate noise power MEAN = mean(n) MAX = max(n) MIN = min(n) VARIANCE = var(n) 7
Pn = VARIANCE; subplot(3,1,1), plot(t(1:400),n(1:400)) title('sample of noise signal'); n_sq = n.* n; subplot(3,1,2), plot(t(1:400),n_sq(1:400)) title('sample of noise power'); ylabel('power (V**2)'); % Estimate signal power MEAN = mean(s) MAX = max(s) MIN = min(s) VARIANCE = var(s) Ps = VARIANCE; s_sq = s.* s; subplot(3,1,3), plot(t(1:400),s_sq(1:400)) title('sample of signal power'); ylabel('power (V**2)'); SNR = 10 * log10(ps/pn) %use log10 for base 10 Record the statistics and SNR of the separate signals Mean Maximum Minimum Variance (power) Signal s(t) Noise n(t) SNR db Estimate the SNR from the received AM wave. You will have to extract the noise and AM signals from the received signal. Use filters. You already have the band-pass filtered am wave. Try bandstop filtering with the inverse characteristic to obtain the noise. Then proceed as above. Record the statistics and SNR of the combined AM wave Mean Maximum Minimum Variance (power) Signal s(t) Noise n(t) SNR db Comment on the difference between the SNR when estimated by these two methods. RCS, 28/9/10 8