0% found this document useful (0 votes)
138 views3 pages

Tutorial DSP

This document provides instructions for using MATLAB to build a digital filter to remove noise from an audio file and reveal a secret message. The file contains noise at a specific frequency disguising a secret code for the student's group. Students are instructed to use MATLAB functions like wavread(), FFT(), and filtfilt() to read in the file, analyze its frequency spectrum, design an FIR filter to remove the noise frequency, apply the filter, and output the processed audio file containing the revealed secret code. Key steps include determining the sampling rate, identifying the noise frequency, designing a filter, verifying it removes only that frequency, and playing the original and filtered files to check the result.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views3 pages

Tutorial DSP

This document provides instructions for using MATLAB to build a digital filter to remove noise from an audio file and reveal a secret message. The file contains noise at a specific frequency disguising a secret code for the student's group. Students are instructed to use MATLAB functions like wavread(), FFT(), and filtfilt() to read in the file, analyze its frequency spectrum, design an FIR filter to remove the noise frequency, apply the filter, and output the processed audio file containing the revealed secret code. Key steps include determining the sampling rate, identifying the noise frequency, designing a filter, verifying it removes only that frequency, and playing the original and filtered files to check the result.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Mechtron 3TB4: Embedded Systems Design II Tutorial 3

Name: Name:

Building a digital lter using Matlab:


In this tutorial we are going to decrypt secret information using a software lter. Each group will be given a wave le that contains a secret code for that group only. A deliberate noise at some frequency is added to the le in order to disguise the information. Your task is to build a software lter using Matlab to lter out the noise so that the secret information can be revealed (hearable by headphone). The wave le for your group (secret code groupX.wav, where X is your group ID) can be found in your groups subversion repository at https://websvn.mcmaster.ca/mt3tb4/groupX/Lab3/secret_code_group#.wav where # is your group ID. The type of lter we are going to build is the FIR lter that was discussed in the class. Matlab has a set of DSP functions that enables us to do this easily. Please follow the instructions and ll in the blanks: Start Matlab. The following commands perform the ltering; before you execute them, read the help les of these functions by using help FunctionName to understand their use.
1

% read the . wav file - replace # by your group number ! % Variable x stores the wave and fs stores the sampling rate [x , fs ] = wavread ( AbsolutePath \ secret_code_group #. wav );

% perform FFT on the original signal to determine the frequency % of the noise L = length ( x ); NFFT = 2^ nextpow2 ( L ); X = fft (x , NFFT )/ fs ; % Show the sampling rate . fs % We know the sampling rate is __________

11

16

% % We need now to plot our FFT to find the source of the noise . % Plot single - sided amplitude spectrum . f = fs /2* linspace (0 ,1 , NFFT /2+1); plot (f ,2* abs ( X (1: NFFT /2+1)));

21

26

% reading the FFT we realize that the frequency we want to % remove is _________ ( hint : our noise is a pure sign wave ) % Now specify the frequency you want to eliminate by setting fkill = _______________ ; % Hint : fkill is always in the range 0 - 1 , and is % normalized to frequency fs /2

31

36

% % % %

Determine coefficients of the FIR filter that will remove that frequency . Start off the following blank with the value 4. Note the following filter only works with even numbers .

coeff = firgr ( _____ ,[0 , fkill -.1 , fkill , fkill +.1 ,1] ,[1 ,1 ,0 ,1 ,1] , { n , n , s , n , n });
41

% Plot the filter % Plot the frequency response of the designed filter to % verify that it satisfies the requirements
46

freqz ( coeff ,1); % % % % % % % % % You should try different filter lengths in the firgr command and find out which one is the best . Filter length of 4 is terrible ideally your filter should only filter out the noise while passing all other signals . Try increasing your filter length until you can achieve an adequate result . Be sure to plot ( with freqz ) each time you create a new filter . If you pick a filter length too big the filter will " blow up ". If you are unsure whether your filter is blown up or not , seek help from a TA .

51

56

coeff * 32768
61

% coeff * 32768= _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ % Please record these numbers . You will need them when doing lab3 . % filter the input signal x ( t ) using the designed FIR filter to get y ( t )

66

y = filtfilt ( coeff , 1 , x );

71

% perform FFT on the filtered signal to observe the % absence of frequency of the noise Y = fft (y , NFFT )/ L ; % play the original ( x ) and filtered ( y ) file to hear the difference wavplay (x , fs );

76

wavplay (y , fs ); % The secret code for your group is ______________


81

% create the vector for horizontal axis % create two plots subplot (2 ,1 ,1);

86

% first one shows FFT of the original signal plot (f ,2* abs ( X (1: NFFT /2+1))); xlabel ( Frequency ( Hz ) ) ylabel ( | X ( f )| ) subplot (2 ,1 ,2); % second one shows FFT of the filtered signal
96

91

plot (f ,2* abs ( Y (1: NFFT /2+1))) xlabel ( Frequency ( Hz ) ) ylabel ( | Y ( f )| )


101

% write the file to disk replacing # by your group number ! wavwrite (y , fs , 16 , AbsolutePath \ secret_code_broken_group #. wav );

You might also like