Matlab: changing frequency of a .wav file

In summary, the conversation is about a script that can play a Doppler shifted version of a WAV file. The code for a doppler shifted single frequency is provided, but there is confusion about how to shift the entire WAV file. The attempt at setting f0 as the WAV file results in an out of memory error, and changing the code leads to a matrix dimension error. The person is unsure of the correct approach and asks for clarification.
  • #1
brushman
113
1

Homework Statement


Write a script which plays a Doppler shifted version of a WAV file.

The Attempt at a Solution



This is the code for a doppler shifted single frequency:
Code:
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.
 
Physics news on Phys.org
  • #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.
 

1. How can I change the frequency of a .wav file in Matlab?

To change the frequency of a .wav file in Matlab, you can use the audioread function to read the file, then use the resample function to resample the audio data to the desired frequency. Finally, use the audiowrite function to save the resampled audio as a new .wav file.

2. Can I change the frequency of a .wav file without changing its duration?

Yes, you can change the frequency of a .wav file without changing its duration by using the resample function in Matlab. This function allows you to specify the desired sampling rate while preserving the original duration of the audio data.

3. What is the difference between upsampling and downsampling in Matlab?

Upsampling is the process of increasing the sampling rate of an audio signal, while downsampling is the process of decreasing the sampling rate. In other words, upsampling adds more samples per unit time, while downsampling removes samples. Both processes can be used to change the frequency of a .wav file in Matlab.

4. How do I specify the desired frequency when using the resample function in Matlab?

When using the resample function in Matlab, you can specify the desired frequency by providing the desired sampling rate as the second argument. For example, if you want to change the frequency to 44100 Hz, you would use resample(audioData, 44100).

5. Will changing the frequency of a .wav file affect its quality?

Changing the frequency of a .wav file in Matlab can potentially affect its quality, as the resampling process can introduce artifacts and distortions. However, if done correctly, the impact on the quality should be minimal. It is always recommended to listen to the resampled audio and adjust the resampling parameters as needed to achieve the desired quality.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
12K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
11
Views
2K
Back
Top