Author Topic: when to use upsampling?  (Read 1563 times)

0 Members and 1 Guest are viewing this topic.

Offline syntax333Topic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: 00
when to use upsampling?
« on: December 09, 2022, 09:26:33 pm »
I am new to DSP realm. So this maybe very simple question.

I am working with 150 point signal which is sampled at 1Msps. The problem is whenever I design a filter using matlabs' filter design tool, I couldn't make a filter with enough filter settling time thus lose samples.

For example, I want to filter 5kHz. It takes 50 points to filter to settle down. Therefore, 50 points of my 150 point original signal becomes useless. Is this the time to use upsampling method?

Upsampling my 150 point signal 4 times thus getting 600 points then losing 50 points becomes more acceptable. What is the main purpose of upsampling? Is my case one of them?

Upsampling method I use is inserting zeros between sample points then lowpass filtering the signal.
« Last Edit: December 09, 2022, 09:55:02 pm by syntax333 »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: when to use upsampling?
« Reply #1 on: December 09, 2022, 10:47:30 pm »
It is hard to tell without knowing the details, but If you upsample your signal, then your old filter design will no longer work, since sampling frequency has changed, so for the same filter design and coefficients its bandwidth would go up too.

If you want to avoid boundary conditions, it is common to extend the signal with a constant values equal to the first and last point. Or you can repeat the signal multiple times and then take the central part after the filtering.

And no matter what you do, all filters would have some delay.
« Last Edit: December 09, 2022, 10:50:03 pm by ataradov »
Alex
 

Online wasedadoc

  • Super Contributor
  • ***
  • Posts: 1356
  • Country: gb
Re: when to use upsampling?
« Reply #2 on: December 09, 2022, 11:16:34 pm »
Have you confirmed that a lower spec filter using significantly less points would not be adequate?

Also, 150 samples at 1 Msample/sec is 150 microseconds but the period of a 5 kHz signal is 200 microseconds. Have you thought about that?
« Last Edit: December 09, 2022, 11:24:49 pm by wasedadoc »
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4414
  • Country: dk
Re: when to use upsampling?
« Reply #3 on: December 09, 2022, 11:24:09 pm »
It is hard to tell without knowing the details, but If you upsample your signal, then your old filter design will no longer work, since sampling frequency has changed, so for the same filter design and coefficients its bandwidth would go up too.

If you want to avoid boundary conditions, it is common to extend the signal with a constant values equal to the first and last point. Or you can repeat the signal multiple times and then take the central part after the filtering.

And no matter what you do, all filters would have some delay.

and that delay is related to the filter bandwidth so no matter what the sample rate is the delay will be roughly the same
 

Offline syntax333Topic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: 00
Re: when to use upsampling?
« Reply #4 on: December 10, 2022, 07:47:10 am »
Ok I understand better now thank you for your replies. However, what is the use case of upsampling then?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: when to use upsampling?
« Reply #5 on: December 10, 2022, 07:59:29 am »
You may need to do a sample rate matching, for example. You may need to do operations on two signals coming from different sources. The simplest example is mixing two sound sources.
Alex
 
The following users thanked this post: syntax333

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3345
  • Country: ua
Re: when to use upsampling?
« Reply #6 on: December 10, 2022, 08:21:43 am »
I am working with 150 point signal which is sampled at 1Msps. The problem is whenever I design a filter using matlabs' filter design tool, I couldn't make a filter with enough filter settling time thus lose samples.

For example, I want to filter 5kHz. It takes 50 points to filter to settle down. Therefore, 50 points of my 150 point original signal becomes useless. Is this the time to use upsampling method?

No. This settle time is a latency of your filter, which depends on filter kernel size for FIR filter. Higher frequency needs to upsample filter kernel too. If you increase sample rate of signal for 2x times, then your filter kernel size also will be increased for 2x times and filter latency will remains the same.

Filter kernel size requirements depends on how sharp slope you're needs for your filter, how much suppression is required for stopband and how much ripple in a passband is allowed.

For example, if you're using FIR filter, there are several estimate methods to estimate filter kernel size (filter order) requirements, for example Bellanger, Fred Harris or Kaiser estimation methods. I'm using Bellanger method, because it usually shows average values between Kaiser and Fred Harris methods. You're put your filter requirements - pass band, transition band, stop band, the suppression level for stop band and allowed ripple for a passband (how much of the original amplitude can you afford to vary), on the output you got optimal filter kernel size estimation.

Just for example, if we need a FIR filter with stopband=0.5, passband=0.4948, transitionband=0.0052. With 0.1 dB ripple within passband and -140 dB rejection at stopband. Then we have the following filter order estimation:

Bellanger: 1016 taps
Fred Harris: 1222 taps
Kaiser: 1004 taps

In avarage we can use 1024 taps FIR filter for that. And it's latency will be 1024 samples. If you want less latency, you're needs to use filter with less taps and your filter will not be able to meet requirements.

So, there is no way to reduce filter latency with no filter parameter degradation.

Usually filter is intended to work with continuous signal, so if you're needs to work with fixed size buffer, then you're needs to prepare your filter. You're needs to push previous signal buffer into the filter before you push your buffer. For example, you can increase buffer size for a filter settle time at the beginning of the buffer and fill these extra samples with a real signal, then just remove these extra samples after filtering.

What is the main purpose of upsampling? Is my case one of them?

Upsample is required, because when you switch to the higher sample rate, you're needs to fill extra samples with interpolated values and recalculate existed samples for a new sample rate. When you fill extra samples with zero, it will leads to adding high frequency components, this is why low pass filter is required to remove these high frequency components.
« Last Edit: December 10, 2022, 11:30:42 am by radiolistener »
 

Offline syntax333Topic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: 00
Re: when to use upsampling?
« Reply #7 on: December 10, 2022, 08:30:43 am »

If you want to avoid boundary conditions, it is common to extend the signal with a constant values equal to the first and last point. Or you can repeat the signal multiple times and then take the central part after the filtering.


I tried both repeating signal multiple time and extending signal with first and last points but it seems like it didn't make that much of difference. I was thinking extrapolate the first and last half of the signal to extend it. Do you think it will result in better settling time compensation?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: when to use upsampling?
« Reply #8 on: December 10, 2022, 08:34:26 am »
Can you explain or show what do you mean by "settling time"? I feel like we are talking about different things.
Alex
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3345
  • Country: ua
Re: when to use upsampling?
« Reply #9 on: December 10, 2022, 08:48:04 am »
I tried both repeating signal multiple time and extending signal with first and last points but it seems like it didn't make that much of difference. I was thinking extrapolate the first and last half of the signal to extend it.

You're needs to push into filter a real signal before your first sample of interest!

For example, if your filter settle time is 50 samples and you're using sample buffer 150 samples. Then extend your buffer to 150+50=200 samples. Capture 200 samples of a signal. Push it through your filter. Remove first 50 samples from filter output. Now you will have 150 filtered samples as you wish.

Note that if you're doing continuous filtering there is no needs for buffer size extension, because filter is already prepared from previous buffer processing.

Do you think it will result in better settling time compensation?

There is no way to reduce filter latency without affecting filter parameters.

You're needs to understand that the signal is continuous and infinite. You're needs to prepare your filter with previous state of signal.
« Last Edit: December 10, 2022, 08:59:31 am by radiolistener »
 

Offline syntax333Topic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: 00
Re: when to use upsampling?
« Reply #10 on: December 10, 2022, 09:06:35 am »
Can you explain or show what do you mean by "settling time"? I feel like we are talking about different things.

In second image I showed my example lowpass filters' step response. It requires atleast 80 sample to give me a valid sample.
In first image I showed a signal passing through this filter and as you can see after 80 samples it tracks the signal perfectly. I was wondering techniques to lower this "delay" or "settling time" without sampling the signal beforehand.

Is there a technique to lower this settling time/compensate for it or this is characteristic of any filter and I have to live with it?

I tried both repeating signal multiple time and extending signal with first and last points but it seems like it didn't make that much of difference. I was thinking extrapolate the first and last half of the signal to extend it.


You're needs to push into filter a real signal before your first sample of interest!


Yes I understand that it is a common approach. I was just asking if there is any technique to use to get valid samples without sampling beforehand. I searched online couldn't find anything thus I asked here.

« Last Edit: December 10, 2022, 09:12:02 am by syntax333 »
 

Offline syntax333Topic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: 00
Re: when to use upsampling?
« Reply #11 on: December 10, 2022, 09:10:46 am »
For some reason second image couldn't be upload to server I tried in this reply to upload the image.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3345
  • Country: ua
Re: when to use upsampling?
« Reply #12 on: December 10, 2022, 09:11:51 am »
Yes I understand that it is a common approach. I was just asking if there is any technique to use to get valid samples without sampling beforehand. I searched online couldn't find anything thus I asked here.

No, this is impossible, because you can't predict what the signal was before if you don't have a previous signal samples.

If you're processing some file, you can fill zero before beginning of the file. From second buffer your filter will be already prepared with data from previous buffer.
« Last Edit: December 10, 2022, 09:15:14 am by radiolistener »
 

Offline syntax333Topic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: 00
Re: when to use upsampling?
« Reply #13 on: December 10, 2022, 09:14:51 am »
Yes I understand that it is a common approach. I was just asking if there is any technique to use to get valid samples without sampling beforehand. I searched online couldn't find anything thus I asked here.

No, this is impossible, because you can't predict what the signal was before if you don't have a previous signal samples.

If you're processing some file, you can fill zero before beginning of the file.


I was wondering if extrapolating the signal for approximate previous samples would result in better output than simply filling the previous samples with zeros?
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3345
  • Country: ua
Re: when to use upsampling?
« Reply #14 on: December 10, 2022, 09:19:56 am »
I was wondering if extrapolating the signal for approximate previous samples would result in better output than simply filling the previous samples with zeros?

You can't get better output by extrapolating. Just because output is already better.

And you cannot extrapolate by adding zero or any other value at the beginning of your sample record. Because you don't know what signal was before sampling and there is no way to predict it.

You're needs to understand that the filter has some latency and it's output sample cannot be directly compared with input sample, because input and output samples of the filter are shifted in time. In order to compare them, you're needs to push input samples through delay line with the same latency as your filter and then compare output of delay line with output of the filter.
« Last Edit: December 10, 2022, 10:50:14 am by radiolistener »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: when to use upsampling?
« Reply #15 on: December 10, 2022, 06:08:23 pm »
What is on the pictures above is a step response of your filter. It is not clear what you want it to look like, but if you remove high frequency components, all sharp steps would look like this. This is the goal of the filter.

What is your overall goal for this? You indeed can't predict the future, but there is a number of things you can do if your signal is finite and you don't need to process it in real time as samples come in.

Show the filtered result of the whole thing not just one step, and show your ideal result. If this fisrt transient is a problem, then adding 100 instances of the first sample as I suggested before would work, since the transient would end up in the unused part. But any following sharp steps in the signal would cause similar effect.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf