polyphase sample rate conversion with non-integer factor - matlab

I am not sure if this is the right place to ask this question, but I have designed a sample rate conversion filter h[n], with matlab's filterbuilder for interpolation factor I=5, and decimation factor D=9. Since D>I, matlab will design a filter with cutoff frequency pi/D.
Then I converted the designed filter h[n] into I=5 polyphase filters, using matlab's method polyphase(). However, I noticed that the coefficients of each seperate polyphase filter do not sum to 1. Hence, I cannot compute valid interpolated sample points. How is this possible? Am I missing something?

See my post at: dsp.stackexchange.com for an answer to this question, and a guide on how to design a sample rate converter with non-integer factor.

Related

Wrong Amplitude after FFT [Matlab] [duplicate]

I am trying to use FFT to decode morse code, but I'm finding that when I examine the resulting frequency bin/bucket I'm interested in, the absolute value is varying quite significantly even when a constant tone is presented. This makes it impossible for me to use the rise and fall around a threshold and therefore decode audio morse.
I've even tried the simple example that seems to be copied everywhere, but it also varies...
I can't work out what I'm doing wrong, and my maths is not clever enough to understand all the formulas associated with FFT.
I now it must be possible, but I can't find out how... can anyone help please?
Make sure you are using the magnitude of the FFT result, not just the real or imaginary component of a complex result.
In general, when a longer constant amplitude sinusoid is fed to a series of shorter FFTs (windowed STFT), the magnitude result will only be constant if the period of the sinusoid is exactly integer periodic in the FFT length. e.g.
f_tone modulo (f_sampling_rate / FFT_length) == 0
If you are only interested in the magnitude of one selected tone frequency, the Goertzel algorithm would serve as a more efficient filter than a full FFT. And, depending on the setup and length restrictions required by your chosen FFT library, it may be easier to vary the length of a Goertzel to match the requirements for your target tone frequency, as well as the time/frequency resolution trade-off needed.

Matlab cftool - fit using percentage deviation as criteria

I have a strong varying data which I am trying to fit using custom function in cftool in Matlab. The issue is that the fit is done default using sum of squared errors (SSE) as criteria to minimize the fit. This results in large errors in fit for small values, since their offset's contribution to SSE is low.
I would like to do the fit with sum of squared relative deviation (percentage error) as minimum criteria. Is there a way to achieve this?
Of course, I can do this in a script form by explicitly mentioning the minimizing function. However, my equation form is not a finalized one and therefore, it is difficult to play with, if it is hard-coded in the script. I find the interactive cftool way of creating fits easier.
I found a way to introduce sum of squared percentage error as criteria in Matlab cftool as follows.
The sum of squared errors (SSE) is computed as
It can be observed that there is some freedom through the weights. If we take
then this results in sum of squared percentage error. y_i is the data to be fitted.
Update: As James pointed out, necessary care has to be taken for y_i=0

How to effectively deal with quantization error in Matlab so that it meets the amplitude specification

I am trying to design a FIR filter in Matlab that can be used to meet certain amplitude specification. The problem is that the gain calculated after calculating the coefficient using firpm function and the gain calculated with quantised coefficients are not the same. Please note that the order of the filter is calculated correctly.
Is there any way to keep both the gains same?
You can, by trial and error, add noise filtered random dithering before quantization until the difference in total gain is minimized.

Choosing Real vs Complex 2D FFTs using apple Accelerate framework

Can anyone advise on the correct FFT to be using (Real or Complex)? I have looked here but still have questions.
I want to do image correlation to identify the location of a sub image within a master image. I understand the basics of FFTs and iFFTs.
The plan:
Perform an FFT on a master image. 512x512
Take complex conjugate of sub image.
Perform an FFT on the sub image. 30x30 but padded with zeros to 512x512
Complex Multiply the two resulting matrixes
Perform iFFT on result
Even though the result should be (mostly) real, take the magnitude of resulting matrix
Look for maximum value which should correspond to maximum correlation.
I am having trouble getting the results that I anticipate.
If I use the real 2d fft (vDSP_fft2dzrip), the result is in a packed format that makes it hard to use a vDSP_zvmul to multiply to two result matrixes.
If I use the complex fft (vDSP_fft2dzip), I fail to get any correlation at all.
The apple examples and most of the audio examples don't do anything with the results of the forward FFT other than do the inverse.
Can anyone help me get started with image correlation? First question...can I use the complex FFT and avoid the packed format?
The only difference between a real and complex FFT is that the real FFT can be slightly more efficient by using a clever packing scheme that transforms a 2^n real FFT into a 2^(n-1) complex FFT. The results should be the same in both cases. So I would stick with the complex FFT for simplicity if I were you, at least until you have everything working.
Have you also taken a look at vImageConvolve_ARGB8888? It seems to do what you are trying to do, with a lot less effort :)

Designing a simple bandpass/bandstop filter in Matlab

For a homework assignment I have to design a simple bandpass filter in Matlab that filters out everything between 250Hz and 1000 Hz. What I did so far:
- using the 'enframe' function to create half overlapping windows with 512 samples each. On the windows I apply the hann window function.
- On each window I apply an fft. After this I reconstruct the original signal with the function ifft, that all goes well.
But the problem is how I have to interpret the result of the fft function and how to filter out a frequency band.
Unless I'm mistaken, it sounds like you're taking the wrong approach to this.
If your assignment is to manipulate a signal specifically by manipulating its FFT then ignore me. Otherwise.. read on.
The FFT is normally used to analyse a signal in the frequency domain. If you start fiddling with the complex coefficients that an FFT returns then you're getting into a complicated mathematical situation. This is particularly the case since your cut-off frequencies aren't going to lie nicely on FFT bin frequencies. Also, remember that the FFT is not a perfect transform of the signal you're analysing. It will always introduce artefacts of its own due to scalloping error, and convolution with your hann window.
So.. let's leave the FFT for analysis, and build a filter.
If you're doing band-pass design in your class I'm going to assume you understand what they do. There's a number of functions in Matlab to generate the coefficients for different types of filter i.e. butter, kaiser cheby1. Look up their help pages in Matlab for loads more info. The values you plug in to these functions will be dependent on your filter specification, i.e. you want "X"dB rolloff and "Y"dB passband ripple. You'll need some idea of the how these filters work, and knowledge of their transfer functions to understand how their filter order relates to your specification.
Once you have your coefficients, it's just a case of running them through the filter function (again.. check the help page if you're not sure how this works).
The mighty JOS has a great walkthrough of bandpass filter design here.
One other little niggle.. in your question you mentioned that you want your filter to "filter out" everything between 250Hz and 1000Hz. This is a bit ambiguous. If you're designing a bandpass filter you would want to "pass" everything between 250Hz and 1000Hz. If you do in fact want to "filter out" everything in this range you want a band-stop filter instead.
It all depends on the sampling rate you use.
If you sample right according to the Nyquist-Shannon sampling theorem then you can try and interpret the samples of your fft using the definition of the DFT.
For understanding which frequencies correspond with which samples in the dft results, I think it's best to look at the inverse transformation. You multiply coefficient k with
exp(i*2*pi*k/N*n)
which can be interpreted to be a cosine with Euler's Formula. So each coefficient gets multiplied by a sine of a certain frequency.
Good luck ;)