Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Introduction - Project, Stage 2, Option E
- % Same as option D except the input .wav file can have a sampling rate of either 8kHz, 16kHz,
- % 22.05kHz or 44.1kHz. Your system should convert the input (with known sampling rate) to a
- % signal sampled at 16kHz and then pass it through the equaliser and output via
- % speakers/headphones. You should ensure that any aliasing due to resampling is inaudible (to
- % the lab demonstrators’ ears) while also ensuring that you do not audibly distort the signal of
- % interest with your anti-aliasing filter.
- % using filterDesigner
- %% System I/O setup
- deviceReader = dsp.AudioFileReader('Filename','PF_16000.wav','PlayCount',1,'SamplesPerFrame', 50);
- deviceWriter = audioDeviceWriter('SampleRate',deviceReader.SampleRate);
- % Butterworth filter paramaters
- n = [10 10 10 10 10] % order of filters
- ch_div = [0 500 1000 2000 4000 8000]; % freq divisions for equaliser
- ch_div = ch_div * 2 / deviceReader.SampleRate;
- ch_gain = [1 1 1 1 1]; % freq
- lp1 = designfilt( 'lowpassfir', 'FilterOrder', n(1), 'CutoffFrequency', ch_div(2) , 'SampleRate', deviceReader.SampleRate);
- bp1 = designfilt('bandpassfir', 'FilterOrder', n(2), 'CutoffFrequency1', ch_div(2), 'CutoffFrequency2', ch_div(3), 'SampleRate', deviceReader.SampleRate);
- bp2 = designfilt('bandpassfir', 'FilterOrder', n(3), 'CutoffFrequency1', ch_div(3), 'CutoffFrequency2', ch_div(4), 'SampleRate', deviceReader.SampleRate);
- bp3 = designfilt('bandpassfir', 'FilterOrder', n(4), 'CutoffFrequency1', ch_div(4), 'CutoffFrequency2', ch_div(5), 'SampleRate', deviceReader.SampleRate);
- hp1 = designfilt('highpassfir', 'FilterOrder', n(5), 'CutoffFrequency', ch_div(6) , 'SampleRate', deviceReader.SampleRate);
- %Fs = Fs_options(2); % sampling rate in Hz (8Khz, 16kHz, 22.05kHz, 44.1Khz)
- fileName = 'PF_16000.wav'; % name of file
- % resample to 16Khz
- switch deviceReader.SampleRate
- case 8000
- % Low pass filter
- % Interpolation
- case 22050
- % High pass filter
- % Decimation
- case 44100
- % High pass filter
- % Decimation
- end
- % anti-aliasing filter for down sampled signals (spectral components)
- %% Main Loop
- % Create slider
- %sld = uicontrol('Style', 'slider', 'Min',1,'Max',50,'Value',41, 'Position', [400 20 120 20], 'Callback', ch_gain );
- while ~isDone(deviceReader)
- mySignal = deviceReader();
- % resample
- % pass throgh Frequency scaling filter
- myProcessedSignal = filter(lp1,mySignal) + filter(bp1,mySignal) + filter(bp2,mySignal) + filter(bp3,mySignal) + filter(hp1,mySignal);
- % dtft on sample and display on equaliser
- %disp('Begin Signal Input...');
- deviceWriter(myProcessedSignal);
- %deviceWriter(mySignal);
- end
- release(deviceReader)
- release(deviceWriter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement