Frequency domain convolution vs Time domain multiplication - matlab

I want to smooth PSD. What I think is I calculated aurocorrelation via xcorr. Then I calculated fourier transform vit fft. Then convolved with gaussian windows. I get smoothed PSD.
According to fourier transform property instead of convolution, I can calculate ifft of PSD(which equal to autocorrelation) and ifft of gaussian window. I can multiply in time domain and I can calculate fourier transform. When I use this way I couldn't get smoothed PSD. Where is the problem?
s -> my signal
Rxx1=xcorr(s,288,'biased');%autocorrelation
w=gausswin(5)%gauss windows
F1=dftmtx(M)*(diag(ifft(w,M)))*Rx;%instead of frequency convoluiton I use time domain multiplation
plot(abs(F1));

Related

How do I pass the signal to the frequency domain?

I have one noisy signal, and this signal is in the time domain. I want to draw this signal through the Fourier transform. As a result, what I expect is a Gaussian dispersion around 0. However, I don't know how to apply and draw the Fourier transform on my signal. I would be glad if you could help.
signalplusnoise=1x674
signalplusnoise=[0.0161,0.0308, 0.0112, ..., 0.3827]

STFT(Short-Time Fourier Transform) & DFT(or FFT) in Matlab

I want to try STFT & FFT using Matlab. What I wonder is
STFT of signal computes the result that FFT(DFT) of each windowed signal and I can see the change of each frequency value over time. If I calculate the average of each frequency over the total time, can I get the same amplitude result with the result of the FFT(DFT) of the whole signal?

How to correctly bandpass filter in frequency with MATLAB?

i'm pretty new to matlab and signal processing, but I am working on a project and I am stuck. My goal is to do a band-pass fast Fourier transform (FFT) filter with cut-off frequencies of 0.5 Hz and 3 Hz from a real signal. My input signal is a signal sampled ad 405Hz and of around 35000 samples. My implementation looks like this:
%ZFiltered = My signal
filtered = bandpass(fft(zFiltered), [0.5 3], sampling_frequency);
res = ifft(filtered);
subplot(2,1,1)
plot(zFiltered)
subplot(2,1,2)
plot(abs(res))
My questions are: Why do I get a signal which contains also imaginary part? Why does it look like this ?
Your goal is unclear to me; here are three different approaches that your question hints at
filter your raw signal with a band-pass filter as your code attempts to do
use the fft and ifft functions to filter your raw signal
calculate the coefficients of a digital filter that would act as a band-pass filter when used with the filter function
Approach 1: filtering with bandpass function
Referring to the bandpass documentation, you would use your original signal and specify the filter band and sampling frequency as in:
filtered_signal = bandpass(zFiltered,[freq_low freq_high],sample_freq);
plot(zFiltered); hold on;
plot(filtered_signal);
where the inputs are the
zFiltered : original (unfiltered signal)
freq_low=0.5 : lowest frequency in Hz of the band pass range`
freq_high=3 : highest frequency in Hz of the band pass range
sample_freq=405 : the sampling frequency in Hz
Your approach using digital fast Fourier transform function fft produces complex results because you are looking at the actual components computed by the transform (which by definition are complex having both real and imaginary parts). You can compute the power of the signal with:
P = abs(res/n).^2;
which gives you the power of the signal for each frequency represented in the Fourier transform (see the fft function docs here for more information).
Approach 2: Filtering with fft ifft functions
Use the Fourier transform and inverse Fourier transform functions to filter the signal. The steps here are to use fft to get the signal into the frequency domain. Set the elements you want filtered to zero and then apply the inverse Fourier transform (ifft) to get the filtered signal. Each component represents a given discrete frequencies in the range between 0Hz and F_s/2 that contributes to the signal. Set components of the FFT you want to suppress to zoro and apply ifft to get back a filter signal. Please see the fft docs and ifft docs for information on these functions and some of the intricacies of working with signals in the frequency domain.
Approach 3: Filtering with the coefficeints of the standard difference equation
Computing the coefficients of a digital band pass filter. This approach calculates the coefficients (vectors A and B) of the standard difference equation (see filter docs for details). An example of a function that does this is butter which gives the coefficients that represent a Butterworth filter of a given frequency. You could also look at the designfilt function for more options.

white noise has flat power spectral density

I am trying to prove that the white noise has constant power spectral density using matlab
but the amplitude of the spectrum looks like random amplitude.
can anyone tell me why?
here is my code.
noise = randn(1,10000);
fft_noise=fft(noise);
plot(abs(fft_noise(1:5000)))
thanks.
You need to average a bunch (law of large numbers) of FFTs of white noise to approach the average power spectral density.
If you take the FFT of an independent set of random variables from the same distribution, then you'll get an independent set of random variables from the same distribution since the inverse Fourier transform is (more or less) the same as the Fourier transform. The point is that the expected value for each frequency is the same.
you need to multiple the fft by the complex conjugate of the fft to show a flat PSD. i.e. change
fft_noise=fft(noise);
to
fft_noise=fft(noise).*conj(fft(noise));

How to get coefficients for sine/cosine function from complex FFT in Matlab?

I'm working on a control system that measures the movement of a vibrating robot arm. Because there is some deadtime, I need to look into the future of the somewhat noisy signal.
My idea was to use the frequencies in the sampled signal and produce a fourier function that could be used for extrapolation.
My question: I already have the FFT of the signal vector (containing 60-100 values e.g.) and can see the main frequencies in the amplitude spectrum. Now I want to have a function f(t) which fits to the signal, removes some noise, and can be used to predict the near future of the signal. How do I calculate the coefficients for the sine/cosine functions out of the complex FFT data?
Thank you so much!
AFAIR FFT essentially produces output as a sum of sine functions with different frequencies. The importance of each frequency is the height of each peak. So what you really want to do here is filter out some frequencies (ie. high frequencies for the arm to move gently) and then come back to the time domain.
In matlab this should be like going through the vector of what you got from fft, setting some values to 0 (or doing something more complex to it) and then use ifft to come back to time domain and make the prediction based on what you get.
There's also one thing you should consider while doing this - Nyquist frequency - this means that the highest frequency that you get on your fft is half of the sampling frequency.
If you use an FFT for data that isn't periodic within the FFT aperture length, then you may need to use a window to reduce spurious frequencies due to "spectral leakage". Frequency estimation techniques to better estimate "between bin" frequency content may also be appropriate. The phase of each cosine sinusoid, relative to the edge of the window, is usually atan2(imag[i], real[i]). The frequency depends on the sample rate and bin number versus the length of the FFT.
You might also want to look into using a Kalman filter instead of an FFT.
Added: If your signal isn't exactly integer periodic in the FFT length, then you may want to do an fftshift before the FFT to move the resulting phase measurement reference point to the center of your data vector, instead of a possibly discontinuous circular edge.