Advertisement
Guest User

none

a guest
Dec 28th, 2010
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. %Play decimated file ( soundsc(y,fs) )
  2. %Play Original file ( soundsc(play,fs ) )
  3. %Play reconstucted File ( soundsc(final,fs) )
  4.  
  5. [piano,fs]=wavread('piano.wav'); % loads piano
  6. play=piano(:,1); % Renames the file as "play"
  7.  
  8. t = linspace(0,time,length(play)); % Time vector
  9. x = play;
  10. y = decimate(x,2);
  11.  
  12. stem(x(1:30)), axis([0 30 -2 2]) % Original signal
  13. title('Original Signal')
  14. figure
  15. stem(y(1:30)) % Decimated signal
  16. title('Decimated Signal')
  17.  
  18. %changes the sampling rate
  19.  
  20. fs1 = fs/2;
  21. fs2 = fs/3;
  22. fs3 = fs/4;
  23. fs4 = fs*2;
  24. fs5 = fs*3;
  25. fs6 = fs*4;
  26.  
  27. wavwrite(y,fs,'PianoDecimation');
  28.  
  29.  
  30. %------------------------------------------------------------------
  31.  
  32. %Downsampled version of piano is now upsampled to the original
  33. [PianoDecimation,fs]=wavread('PianoDecimation.wav'); % loads piano
  34. play2=PianoDecimation(:,1); % Renames the file as "play
  35.  
  36. %upsampling
  37. UpSampleRatio = 2; % 2*fs = nyquist rate sampling
  38. play2Up=zeros(length(PianoDecimation)*UpSampleRatio, 1);
  39. play2Up(1:UpSampleRatio:end) = play2; % fill in every N'th sample
  40.  
  41. %low pass filter
  42.  
  43. ResampFilt = firpm(44, [0 0.39625 0.60938 1], [1 1 0 0]);
  44.  
  45.  
  46. fsUp = (fs*UpSampleRatio)/2;
  47. wavwrite(play2Up,fsUp,'PianoUpsampled');
  48.  
  49. %Plot2
  50. %data vs time plot
  51. time=(1/44100)*length(play2);
  52. t=linspace(0,time,length(play2));
  53. stem(t,play2)
  54. title('Upsampled graph of piano')
  55. xlabel('time(sec)');
  56. ylabel('relative signal strength')
  57.  
  58.  
  59.  
  60. [PianoUpsampled,fs]=wavread('PianoUpsampled.wav'); % loads piano
  61. final=PianoUpsampled(:,1); % Renames the file as "play"
  62.  
  63.  
  64. %-------------------------------------------------------------
  65. %resampleing
  66. [piano,fs]=wavread('piano.wav'); % loads piano
  67. x=piano(:,1); % Renames the file as "play"
  68. m = resample(x,3,2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement