Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Matlab: changing frequency of a .wav file

  1. Sep 12, 2010 #1
    1. The problem statement, all variables and given/known data
    Write a script which plays a Doppler shifted version of a WAV file.

    3. The attempt at a solution

    This is the code for a doppler shifted single frequency:
    Code (Text):
    vs = 1100; % speed of sound in feet per second
    v0 = s*22/15; % speed of the vehicle in feet per second
    fs = 10000; % sampling frequency
    ts = 1/fs; % the sampling period
    f0 = 440;
    td = d/vs; % this is the time for sound to move the distance d
    r = v0/vs; % this ratio should be much less than one of course
    t1 = sqrt(1 - td^2)/r -1; % time vehicle passes you
    t = [ t1-3: ts: t1+3]; % a time base for the signal, with 3 seconds each side
    a = (r^2)*(t-t1)/(1-(r^2));
    b = ((td^2)+(r^2).*(t-t1).^2)./(1-(r^2));
    tau = ((-1)*(2.*a)+sqrt(((2.*a).^2)+(4).*(b)))/(2); % quad form to solve for tau
    y = .5 * sin(2*pi*f0*(t-tau));
     
    What I need is to shift an entire wav file. I tried just setting f0 = wavread('file') but I get an error saying out of memory. Then when I change the f0*(t-tau) to f0.*(t-tau) I get an error saying matrix dimensions must agree.

    I'm not really sure which way it's supposed to be, anyways.

    Thanks.
     
  2. jcsd
  3. Sep 14, 2010 #2
    I'm not sure what you're doing exactly; you need to provide a complete code listing. Something is wrong with your setup if you are unable to use wavread to even read the file.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook