title: How would i down-sample a .wav file then reconstruct it using nyquist? - in MATLAB
body: <p>This is all done in MATLAB 2010</p>
  
  <p>My objective is to show the results of: undersampling, nyquist rate/ oversampling</p>
  
  <p>First i need to downsample the .wav file to get an incomplete/ or impartial data stream that i can then reconstuct.</p>
  
  <p>Heres the flow chart of what im going to be doing So the flow is analog signal -> sampling analog filter -> ADC -> resample down -> resample up -> DAC -> reconstruction analog filter</p>
  
  <p>what needs to be achieved:</p>
  
  <blockquote>
    <p>F= Frequency</p>
    
    <p>F(Hz=1/s) E.x. 100Hz = 1000 (Cyc/sec)
    F(s)= 1/(2f)</p>
    
    <p>Example problem: 1000 hz = Highest
    frequency 1/2(1000hz) = 1/2000 =
    5x10(-3) sec/cyc or a sampling rate of
    5ms</p>
  </blockquote>
  
  <p>This is my first signal processing project using matlab.</p>
  
  <p>what i have so far.</p>
  
  <pre><code>% Fs = frequency sampled (44100hz or the sampling frequency of a cd)
  
  [test,fs]=wavread('test.wav'); % loads the .wav file
  left=test(:,1);
  
  % Plot of the .wav signal time vs. strength
  
  time=(1/44100)*length(left);
  t=linspace(0,time,length(left));
  plot(t,left)
  xlabel('time (sec)');
  ylabel('relative signal strength')
  
  **%this is were i would need to sample it at the different frequecys (both above and below and at) nyquist frequency.*I think.***
  
  soundsc(left,fs) % shows the resaultant audio file , which is the same as original ( only at or above nyquist frequency however) 
  </code></pre>
  
  <p>Can anyone tell me how to make it better, and how to do the sampling at verious frequencies?</p>
  
  <p>heres the .wav file <a href="http://www.4shared.com/audio/11xvNmkd/piano.html" rel="nofollow">http://www.4shared.com/audio/11xvNmkd/piano.html</a></p>
  
  <p>EDIT:</p>
  
  <pre><code>%Play decimated file ( soundsc(y,fs) ) 
  %Play Original file ( soundsc(play,fs ) )
  %Play reconstucted File ( soundsc(final,fs) )
  
  [piano,fs]=wavread('piano.wav'); % loads piano
  play=piano(:,1); % Renames the file as "play"
  
  t = linspace(0,time,length(play));          % Time vector
  x = play;
  y = decimate(x,25);
  
  stem(x(1:30)), axis([0 30 -2 2])   % Original signal
  title('Original Signal')
  figure
  stem(y(1:30))                        % Decimated signal
  title('Decimated Signal')
  
  %changes the sampling rate
  
  fs1 = fs/2;
  fs2 = fs/3;
  fs3 = fs/4;
  fs4 = fs*2;
  fs5 = fs*3;
  fs6 = fs*4;
  
  wavwrite(y,fs/25,'PianoDecimation');
  
  
  %------------------------------------------------------------------
  
  %Downsampled version of piano is now upsampled to the original
  [PianoDecimation,fs]=wavread('PianoDecimation.wav'); % loads piano
  play2=PianoDecimation(:,1); % Renames the file as "play
  
  %upsampling
  UpSampleRatio = 2;  % 2*fs = nyquist rate sampling
  play2Up=zeros(length(PianoDecimation)*UpSampleRatio, 1);
  play2Up(1:UpSampleRatio:end) = play2; % fill in every N'th sample
  
  %low pass filter
  
  ResampFilt = firpm(44, [0 0.39625 0.60938 1], [1 1 0 0]);
  
  
  fsUp = (fs*UpSampleRatio)*1;
  wavwrite(play2Up,fsUp,'PianoUpsampled');
  
  %Plot2
  %data vs time plot
  time=(1/44100)*length(play2);
  t=linspace(0,time,length(play2));
  stem(t,play2)
  title('Upsampled graph of piano')
  xlabel('time(sec)');
  ylabel('relative signal strength')
  
  
  
  [PianoUpsampled,fs]=wavread('PianoUpsampled.wav'); % loads piano
  final=PianoUpsampled(:,1); % Renames the file as "play"
  
  
  %-------------------------------------------------------------
  %resampleing
  [piano,fs]=wavread('piano.wav'); % loads piano
  x=piano(:,1); % Renames the file as "play"
  m = resample(x,3,2);
  </code></pre>
  
  <p>Original:
  <a href="http://www.4shared.com/audio/11xvNmkd/piano.html" rel="nofollow">http://www.4shared.com/audio/11xvNmkd/piano.html</a></p>
  
  <p>New:
  <a href="http://www.4shared.com/audio/nTRBNSld/PianoUs.html" rel="nofollow">http://www.4shared.com/audio/nTRBNSld/PianoUs.html</a></p>