when to use upsampling? - Page 1
Forum section: electronics / beginners

author: syntax333
author_rank: Regular Contributor
timestamp: December 09, 2022, 09:26:33 pm
content: 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.

author: ataradov
author_rank: Super Contributor
timestamp: December 09, 2022, 10:47:30 pm
content: 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.

author: wasedadoc
author_rank: Super Contributor
timestamp: December 09, 2022, 11:16:34 pm
content: 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?

author: langwadt
author_rank: Super Contributor
timestamp: December 09, 2022, 11:24:09 pm
content: Quote from: ataradov on December 09, 2022, 10:47:30 pmand that delay is related to the filter bandwidth so no matter what the sample rate is the delay will be roughly the same

author: syntax333
author_rank: Regular Contributor
timestamp: December 10, 2022, 07:47:10 am
content: Ok I understand better now thank you for your replies. However, what is the use case of upsampling then?

author: ataradov
author_rank: Super Contributor
timestamp: December 10, 2022, 07:59:29 am
content: 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.

author: radiolistener
author_rank: Super Contributor
timestamp: December 10, 2022, 08:21:43 am
content: Quote from: syntax333 on December 09, 2022, 09:26:33 pmNo. 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 tapsFred Harris: 1222 tapsKaiser: 1004 tapsIn 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.Quote from: syntax333 on December 09, 2022, 09:26:33 pmUpsample 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.

author: syntax333
author_rank: Regular Contributor
timestamp: December 10, 2022, 08:30:43 am
content: Quote from: ataradov on December 09, 2022, 10:47:30 pmI 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?

author: ataradov
author_rank: Super Contributor
timestamp: December 10, 2022, 08:34:26 am
content: Can you explain or show what do you mean by "settling time"? I feel like we are talking about different things.

author: radiolistener
author_rank: Super Contributor
timestamp: December 10, 2022, 08:48:04 am
content: Quote from: syntax333 on December 10, 2022, 08:30:43 amYou're needs to push into filtera real signalbefore 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.Quote from: syntax333 on December 10, 2022, 08:30:43 amThere 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.

author: syntax333
author_rank: Regular Contributor
timestamp: December 10, 2022, 09:06:35 am
content: Quote from: ataradov on December 10, 2022, 08:34:26 amIn 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?Quote from: radiolistener on December 10, 2022, 08:48:04 amYes 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.

author: syntax333
author_rank: Regular Contributor
timestamp: December 10, 2022, 09:10:46 am
content: For some reason second image couldn't be upload to server I tried in this reply to upload the image.

author: radiolistener
author_rank: Super Contributor
timestamp: December 10, 2022, 09:11:51 am
content: Quote from: syntax333 on December 10, 2022, 09:06:35 amNo, 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.

author: syntax333
author_rank: Regular Contributor
timestamp: December 10, 2022, 09:14:51 am
content: Quote from: radiolistener on December 10, 2022, 09:11:51 amI was wondering if extrapolating the signal for approximate previous samples would result in better output than simply filling the previous samples with zeros?

author: radiolistener
author_rank: Super Contributor
timestamp: December 10, 2022, 09:19:56 am
content: Quote from: syntax333 on December 10, 2022, 09:14:51 amYou 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.

author: ataradov
author_rank: Super Contributor
timestamp: December 10, 2022, 06:08:23 pm
content: 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.