Advertisement
Guest User

Untitled

a guest
May 29th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. %% Introduction - Project, Stage 2, Option E
  2.  
  3. % Same as option D except the input .wav file can have a sampling rate of either 8kHz, 16kHz,
  4. % 22.05kHz or 44.1kHz. Your system should convert the input (with known sampling rate) to a
  5. % signal sampled at 16kHz and then pass it through the equaliser and output via
  6. % speakers/headphones. You should ensure that any aliasing due to resampling is inaudible (to
  7. % the lab demonstrators’ ears) while also ensuring that you do not audibly distort the signal of
  8. % interest with your anti-aliasing filter.
  9.  
  10. % using filterDesigner
  11.  
  12.  
  13. %% System I/O setup
  14.  
  15. deviceReader = dsp.AudioFileReader('Filename','PF_16000.wav','PlayCount',1,'SamplesPerFrame', 50);
  16. deviceWriter = audioDeviceWriter('SampleRate',deviceReader.SampleRate);
  17.  
  18. % Butterworth filter paramaters
  19. n = [10 10 10 10 10] % order of filters
  20. ch_div = [0 500 1000 2000 4000 8000]; % freq divisions for equaliser
  21. ch_div = ch_div * 2 / deviceReader.SampleRate;
  22. ch_gain = [1 1 1 1 1]; % freq
  23.  
  24. lp1 = designfilt( 'lowpassfir', 'FilterOrder', n(1), 'CutoffFrequency', ch_div(2) , 'SampleRate', deviceReader.SampleRate);
  25. bp1 = designfilt('bandpassfir', 'FilterOrder', n(2), 'CutoffFrequency1', ch_div(2), 'CutoffFrequency2', ch_div(3), 'SampleRate', deviceReader.SampleRate);
  26. bp2 = designfilt('bandpassfir', 'FilterOrder', n(3), 'CutoffFrequency1', ch_div(3), 'CutoffFrequency2', ch_div(4), 'SampleRate', deviceReader.SampleRate);
  27. bp3 = designfilt('bandpassfir', 'FilterOrder', n(4), 'CutoffFrequency1', ch_div(4), 'CutoffFrequency2', ch_div(5), 'SampleRate', deviceReader.SampleRate);
  28. hp1 = designfilt('highpassfir', 'FilterOrder', n(5), 'CutoffFrequency', ch_div(6) , 'SampleRate', deviceReader.SampleRate);
  29.  
  30. %Fs = Fs_options(2); % sampling rate in Hz (8Khz, 16kHz, 22.05kHz, 44.1Khz)
  31.  
  32. fileName = 'PF_16000.wav'; % name of file
  33.  
  34. % resample to 16Khz
  35. switch deviceReader.SampleRate
  36. case 8000
  37. % Low pass filter
  38. % Interpolation
  39. case 22050
  40. % High pass filter
  41. % Decimation
  42. case 44100
  43. % High pass filter
  44. % Decimation
  45. end
  46.  
  47. % anti-aliasing filter for down sampled signals (spectral components)
  48.  
  49. %% Main Loop
  50.  
  51. % Create slider
  52. %sld = uicontrol('Style', 'slider', 'Min',1,'Max',50,'Value',41, 'Position', [400 20 120 20], 'Callback', ch_gain );
  53.  
  54. while ~isDone(deviceReader)
  55. mySignal = deviceReader();
  56. % resample
  57. % pass throgh Frequency scaling filter
  58. myProcessedSignal = filter(lp1,mySignal) + filter(bp1,mySignal) + filter(bp2,mySignal) + filter(bp3,mySignal) + filter(hp1,mySignal);
  59. % dtft on sample and display on equaliser
  60. %disp('Begin Signal Input...');
  61. deviceWriter(myProcessedSignal);
  62. %deviceWriter(mySignal);
  63. end
  64.  
  65. release(deviceReader)
  66. release(deviceWriter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement