You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
upsampling and adding delay to a sequence
7 views (last 30 days)
Show older comments
Hi
I have a simple query.
Suppose i have a signal s = randn(1,10), if I want to add delay 100ms to this signal, what should i do?
I heard about upsampling the signal and then adding zeros, but can you help me with an example code
s = randn(1,8);
delay = 100ms;
s1 = upsample(s,?);
s_delay = [how many zeros, s1]?
Is that approach right?
Accepted Answer
Walter Roberson
on 19 Jan 2012
It is not possible to add a delay to a signal unless you know what the sampling frequency is.
12 Comments
PChoppala
on 19 Jan 2012
Okay, here is my actual prob
load handel.mat;
hfile = 'handel.wav';
[y,Fs] = wavread(hfile); % this will give me a broadband signal with 73113 samples and Fs = 8192;
I want to add a delay of 1.3 ms to this 'y'. How do I do that?
I assume I need to pad fix((Fs*1.3e-3)) zeros in the front, is that right?
In this case
fix(Fs*1.3e-3)% =10, so i need to pad 10 zeros in the beginning
x = vertcat(zeros(10,1), y(1:length(y)-10));
Is 'x' the 1.3ms delayed signal?
But I gather there is another method...wherein, we upsample the signal and low pass filter it...can you please help me with that?
Cheers
Walter Roberson
on 19 Jan 2012
Express the intervals as fractions.
1.3 ms is 13/10000 .
Fs is 1/8192
solve as a fraction:
13/10000 = x/8192
which gives x = 6656/625
Cross-check: (1/10000)*(13*625) = 6656*(1/8192) gives 13/16 = 13/16 which is true.
Therefore, the signal must be upsampled by a factor of 6656, after which 1.3 ms will correspond to 13*625 = 8125 zeros.
Adding fix((Fs*1.3e-3)) zeros will *not* get you a 1.3 ms delay: it will get you a 1.22 ms delay, which is not a good enough approximation for sound processing purposes.
PChoppala
on 19 Jan 2012
Agh, I understand it now. Thank you very much.
Please allow me to ask one more query.
1. The signal in the above quoted case 'y' has 73113 samples.
If I use
x = upsample(y,6656), I get the error
'Maximum variable size allowed by the program is exceeded'
What to do about that?
2. Fs is 8192, not 1/8192. Is it a mistake you typed in the 3rd statement?
3. Of the topic, how can we find the sampling frequency of a signal of the form s = randn(1,1000)?
Please help me as I am struggling with this concept for a couple of days.
Thanks a lot
Walter Roberson
on 19 Jan 2012
2. Yes, sorry, the sampling interval is 1/Fs, 1/8192
1. I am mildly surprised that upsample said that the maximum variable size allowed by the program was exceeded, as the result would only be 3.6+ gigabytes, which would fit in to 32 bit memory if only everything else was out of the way. I would have thus expected "out of memory" instead of maximum variable size. In any case, Yup, it's too big for you to compute using upsample() unless you switch to the 64 bit version of MATLAB.
What to do about it? The usual way is to use a fractional delay filter instead of using upsample.
3. There is no sampling frequency for a signal defined by its samples. If someone from another of our departments were to send me a data file with 1000 samples, I would not know whether it was a measurement off of one of our attosecond (1E-18 second) lasers, or a measurement that had been done once a week for about 21 years.
Walter Roberson
on 19 Jan 2012
Yup. But in your "actual prob" from your first comment, you do not have a random signal and you know the Fs from the wavread() command, so the question of sampling frequency for randn(1,1000) is not relevant to that situation.
PChoppala
on 19 Jan 2012
Hi again,
Bear with me this one time.
1. Yeah, Fs for randn is not relevant. Sorry.
2. I read the document on design.fracdelay, but could not understand how to upsample a sequence or add delay to 'y', in the above stated context. I have not worked on filters or used the command.
Can you just give me an example of how to use the command to upsample or add delay?
I can start my coding once I can do that.
Please.
and thanks for the method, it will be a big relief for me, if I can get this going today!
Cheers
Walter Roberson
on 19 Jan 2012
entiredelay = 0.0013 * Fs;
wholesamplesdelay = floor(entiredelay);
fracdelaysamples = entiredelay - wholesamplesdelay;
d = fdesign.fracdelay(fracdelaysamples);
H = design(d, 'lagrange', 'FilterStructure', 'farrowfd');
I have not researched to see how you would use H. Whatever output you get from using it needs to be pre-padded with wholesamplesdelay 0's.
upsampling would not come in to it. upsampling is an alternative method.
It would not surprise me if there is an fft() based method of implementing the delay, perhaps by adjusting the phase.
PChoppala
on 19 Jan 2012
Okay so here is how I used
entiredelay = 0.0013 * Fs;
wholesamplesdelay = floor(entiredelay);
fracdelaysamples = entiredelay - wholesamplesdelay;
d = fdesign.fracdelay(fracdelaysamples);
H = design(d, 'lagrange', 'FilterStructure', 'farrowfd');
y1 = filter(H,y);
y1 = vertcat(zeros(wholesampledelay,1),y1);
is that right?
Walter Roberson
on 19 Jan 2012
Looks plausible to within my limited filter knowledge.
PChoppala
on 19 Jan 2012
Hi again, Morning!
Just realized that we may use the translation property of Fourier transform, but unable to figure out how.
if h(x) = ƒ(x − x0), then H(w)= e^{-2 π i x0 ω }F(ω)
Can you help me with this approach?
Cheers
More Answers (0)
See Also
Categories
Find more on Filter Analysis in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)