Fourier transformation input parameters

Hello,
I have a question about the Fourier transformation.
I have a matrix 290x2. The first column is time values ​​in seconds. The second column are amplitudes in V.
Do I apply the Fourier transformation to the first + second column (data(:,1) + data(:,2)) or only to the second column (data(:,2)) or data(:,1:2)?
greetings
Christin

 Accepted Answer

Only take the Fourier transform of the second column. Having the first column is necessary in order to calculate the frequency vector.
Example:
data = sortrows(rand(290,2)); % Create ‘data’ (Use Your Own Data)
L = size(data,1); % Matrix Length
Ts = mean(diff(data(:,1))); % Sampling Interval (Assumes Regular Sampling Interval)
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
FTdata = fft(data(:,2))/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector (For One-Sided Spectrum)
Iv = 1:numel(Fv); % Index Vector (For One-Sided Spectrum)
figure
plot(Fv, abs(FTdata(Iv))*2)
grid
That should work with your data, although you may first need to subtract the mean from ‘data(:,2)’ if you have a large d-c (constant) offset that obscures the other peaks.

24 Comments

As always, my pleasure.
Hello,
I have another question about the problem.
After the Fourier transformation, I want to use the butter filter. This works in the range of 0 to 1 or the plot goes from 0 to 1. Now I would like to normalize the frequency axis (from 0 to 1).
So you can say for example: "Above you can see the Fourier transformation and below the applied filter" and both graphics are visually comparable.
I've tried to normalize the signal (the FFT), which did not really work.
signal=abs(FTdata(Iv))*2;
[maxsignal, indmax]=max(signal); %Maximum und Minimum des Signalabschnittes
[minsignal,indmin]=min(signal);
diff=maxsignal-minsignal; %maximale Amplitude des Signalabschnittes:
normiertessignal=(signal-minsignal)./diff; %Normierung
plot(Fv, abs(normiertessignal));
If I normalize the x-axis (frequency) directly, the values ​​of the graph jump around the x-axis when zoomed in / arrange differently. Somehow the link between the signal and the axis is missing.
xAchse = ( get(gca,'xtick')-min(get(gca,'xtick')) ) ...
./ ...
( max(get(gca,'xtick')-min(get(gca,'xtick'))) );
set(gca,'xticklabel',xAchse);
For example, the value of the graph no longer belongs to 0.65 but to 0.5.
Is the normalization of the signal still somehow possible?
I am not certain what you are doing.
To normalise the frequencies for the MATLAB filter functions, you need to divide the passband and stopband frequencies by the Nyquist frequency (½ the sampling frequency). Then to design a Butterworth filter, use this example (where ‘Signal’ is the data you want to filter):
Fs = 1000; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = 250/Fn; % Passband Frequency (Lowpass Filter)
Ws = 260/Fn; % Stopband Frequency (Lowpass Filter)
Rp = 1; % Passband Ripple
Rs = 50; % Stopband Ripple
[n,Wn] = buttord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = butter(n,Wn,'low'); % Filter Coefficients (Zero-Pole-Gain)
[sos,g] = zp2sos(z,p,k); % Second-Order-Section For Stability
figure
freqz(sos, 2^14, Fs)
filteredSignal = filtfilt(sos, g, Signal);
Change the necessary parts of this code to design the filter you want. This lowpass design has a cutoff frequency of 250.
Christin Butzlaff’s Answer moved here:
Hello, yes, getting the x-axis of the fft on a range of 0 to 1 was also just bauble.
I solve the filter like this:
y=bandpass(FTdata(Iv),[200000 230000], Fs);
plot(abs(y));
and the corresponding inverse transformation like this:
X=ifft(y);
plot(real(y));
the x-axis of the filter and the ifft are now from 0 to 9000. Is there a way to get the x-axis of the ifft back into the time range as in the output signal?
Please describe what you want to do.
Here, you are filtering the Fourier transform of your signal. That simply does not make sense if you want to filter your original signal.
Also, the bandpass function designs and implements a very efficient elliptical filter. I would have suggested using bandpass, however you said you wanted a Butterworth design.
Christin Butzlaff’s Answer moved here:
Oh wow, am I so wrong on the way?
I have several files with ultrasonic runtime measurements. I now want to examine these files to "listen" to damage developments during print attempts out. First, I determined the speed of the waves at the receiver (in the unfiltered signal). Of course, some speeds are beyond the scope. Therefore, now the Fourier transform to identify interfering frequencies. The device itself emits a frequency of 230Khz. Now my idea was to filter in the frequency spectrum and throw everything under 230Khz out. Then make a time signal again and calculate the speeds again to see if they are in the normal range. But I also have to say that the more I comment on the subject signal analysis, fft, fensterung ... I am all the more confused.
I am not certain what you are doing, or what you want to do.
Here are some possibilities:
If you have R2018a or later, you can use the bandpass function to do the filtering. (If you do not, I can help you design a similar filter.) I would use a bandpass, rather than a highpass, filter in order to eliminate high-frequency noise.
All (analogue and) discrete filters operate in the time-domain (even though they are designed in the frequency-domain), so everything the filters do remains in the time-domain. There is no reason to do a Fourier transform, unless you want to see the spectrum before and after you apply the filter.
If the frequency of your signal varies considerably over time, consider using the spectrogram function to see the frequency variation over time.
If the 230 kHz signal is a carrrier frequency, and it is modulated by other signals, consider using the demod function to recover the modulating signals.
Christin Butzlaff’s Answer moved here:
Hello,
Thanks for your time. Although the Fourier transformation does not provide the frequency and frequency of the transient processes, the frequency itself does. That should be enough for me then. The Youtube video for wavelet is running, but I do not get programmed anymore today. ^^ Now I have fft frequencies from 0 Hz to 400000Hz. If I now adjust the Fs in your filter, replace the signal with my amplitude column, turn low into high and do wp = 200000 / Fn and ws = 260000 / Fn, I get the error message -The cutoff frequencies must be within the interval of (0,1) - But I can not set my Fn higher, since it is given to me with my time interval of the measurement result.
If the upper limit of your Fourier transform is 400000 Hz, and assuming you calculated the frequency vector correctly, that is also the Nyquist frequency, Fn. Your calculated passbands and stopbands will then be between 0 and 1.
Oh, the upper limit of my Fourier transform is 8000000 Hz.
O.K., then that is your Nyquist frequency. Your sampling frequency is 16000000 Hz.
Your passband and stopband frequencies are still well within the [0,1] limits. I definitely suggest that you use an elliptical filter, not a Butterworth design, for those sampling, passband, and stopband frequencies:
Fs = 16000000; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = 200000 / Fn; % Normalised Passband Frequencies
Ws = 260000 / Fn; % Normalised Stopband Frequencies
Rp = 1; % Passband Ripple
Rs = 50; % Stopband Ripple (Attenuation)
[n_b,Wn_b] = ellipord(Wp, Ws, Rp, Rs)
[z,p,k] = ellip(n_b, Rp, Rs, Wp); % Use Z,P,K For Precision
[sos, g] = zp2sos(z, p, k); % Use Second-Order Sections For Stability
figure
freqz(sos, 2^14, Fs) % View Filter Bode Plot
X_Filtered = filtfilt(sos, g, X); % Filter Signal
This assumes ‘X’ is your signal.
They are great.
But this is a low pass filter right? So he puts everything before 260000.
If I try now to make a high pass filter there are Frequemzen that were not there before.
Fs = 16000000; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = 50000 / Fn; % Normalised Passband Frequencies
Ws = 100000 / Fn; % Normalised Stopband Frequencies
Rp = 1; % Passband Ripple
Rs = 50; % Stopband Ripple (Attenuation)
[n_b,Wn_b] = ellipord(Wp, Ws, Rp, Rs)
[z,p,k] = ellip(n_b, Rp, Rs, Wp/Ws,'high'); % Use Z,P,K For Precision
[sos, g] = zp2sos(z, p, k); % Use Second-Order Sections For Stability
figure
freqz(sos, 2^14, Fs) % View Filter Bode Plot
X_Filtered = filtfilt(sos, g, data(:,2));
If I try now to make a high pass filter there are Frequemzen that were not there before.
They were there. They just had such low amplitude that you could not see them. Note that the maximum amplitude is about , while in your earlier fft plot, the maximum amplitude was about . You would see them if you converted the amplitudes in your earlier fft plot to dB or used semilogy to plot them.
Oh yes, I did not pay attention to the scaling of the y-axis. Semilogy is also good and helps me. How can I show my filtered signal back to "normal". So as originally with the time as x-axis and with the amplitude as y-axis? or is not that possible because too many connections have been lost on the way?
I am not certain what you are plotting.
If ‘t’ is your time vector, I would plot it as:
figure
plot(t, X_Filtered)
or:
figure
semilogy(t, X_Filtered)
Nothing should be ‘lost’ in the filtering process, except the frequencies you want to filter out.
Yes, I had read in a file that came from the end of the print attempt, so it looks so weird. Thank you
They really helped me a lot with that.
I still have a last problem.^^
I want to determine the center of gravity of the surface from my utter, unfiltered fft. The idea is to divide the surface into lower surfaces. Determine the focal points of the lower surfaces. To sum this up and divide by the number. As far as the theory ^^ Is there any commands in matlab that I can look at it more closely? Respectively in the integration, the surfaces are also divided into lower surfaces. Can I have them displayed and continue to use them to determine the centroids of it?
I have absolutely no idea what you are referring to.
Perhaps the medfreq or meanfreq functions are appropriate for this.
Hello,
I meant something like that.
data(:,2:8)=[];
time=data;
Ampli=abs(FTdata(Iv))';
for i=1:(length(Ampli)-1)
x_main_emphasis(i)=((Ampli(i+1))*(time(i+1)-time(i)))*(time(i)+((time(i+1)-time(i))/2));
Area(i)=Ampli(i+1)*(time(i+1)-time(i));
end
counter=sum(x_main_emphasis);
denominator=sum(Area);
main_emphasis=counter/denominator
Probably a bit stupid / complicated at the top, because I do not know how to answer it myself. But that was not so bad.
Again briefly to the code of the Fourier transformation. Why do I multiply the FTdata (Iv) again with 2 at the plot? So plot (Fv, (FTdata (Iv) * 2));
The relation you describe:
is a simple weighted average of vector ‘x’ with ‘A’ as the weighting vector. The easiest way to calculate it is:
x_wa = sum(A.*x) / sum(A);
The loop is (probably) not necessary, although I cannot follow what you are doing in it. (Note the use of (.*), indicating element-wise array — not matrix — multiplication.)
Why do I multiply the FTdata (Iv) again with 2 at the plot? So plot (Fv, (FTdata (Iv) * 2));
The fft function divides the energy of the time-domain signal equally between the positive and negative frequencies of the Fourier transform, so the amplitudes of the two symmetric peaks are half the amplitude of the original time-domain signal. In plotting a one-sided fft, it is then necessary to multiply by 2 in order to approximate the original time-domain amplitudes.
Thanks that helped.
Again to filter, I'm still a little unclear how he works.
subplot(3,2,2);
FsF =15625000; % Sampling Frequency
FnF = FsF/2; % Nyquist Frequency
Wp = 200 / FnF; % Normalised Passband Frequencies
Ws = 2000 / FnF; % Normalised Stopband Frequencies
Rp = 1; % Passband Ripple
Rs = 50; % Stopband Ripple (Attenuation)
[n_b,Wn_b] = ellipord(Wp, Ws, Rp, Rs);
[z,p,k] = ellip(n_b, Rp, Rs, Wp/Ws,'high'); % Use Z,P,K For Precision
[sos, g] = zp2sos(z, p, k); % Use Second-Order Sections For Stability
X_Filtered = filtfilt(sos, g, data(:,2));
plot(data(:,1),X_Filtered);
With this ratio of Wp to Ws, I get filter according to filter plot before 200kHz (file 1). But my filtered fft still shows frequencies before 200kHz, or the display looks generally different than the unfiltered fft (file 2). does the representation of the filtered fft in the direction semilogy?
These specify passband and stopband frequencies of 200 Hz and 2000 Hz respectively, not 200 kHz:
Wp = 200 / FnF; % Normalised Passband Frequencies
Ws = 2000 / FnF; % Normalised Stopband Frequencies
If you want appropriate passband and stopband frequencies for this filter, I would use:
Wp = 200E+3 / FnF; % Normalised Passband Frequencies
Ws = 200.1E+3 / FnF; % Normalised Stopband Frequencies
You also did not call ellip correctly. The ‘Wp’ and ‘Ws’ parameters area already normalised. Please do not normalise them with respect to each other.
This filter design works, and appears to produce the response you want:
FsF =15625000; % Sampling Frequency
FnF = FsF/2; % Nyquist Frequency
Wp = 200E+3 / FnF; % Normalised Passband Frequencies
Ws = 200.1E+3 / FnF; % Normalised Stopband Frequencies
Rp = 1; % Passband Ripple
Rs = 50; % Stopband Ripple (Attenuation)
[n_b,Wn_b] = ellipord(Wp, Ws, Rp, Rs);
[z,p,k] = ellip(n_b, Rp, Rs, Wp,'high'); % Use Z,P,K For Precision
[sos, g] = zp2sos(z, p, k);
figure
freqz(sos, 2^16, FsF)
That should produce the filtered signal you want.

Sign in to comment.

More Answers (1)

Hello,
with the hint that the filter is applied to the time range, you have really saved me from a big mistake. ^^
But I'm still not so clear in my signal analysis. I have now come to the point that a Fourier transformation is not good for transient processes / gives bad results. Since the frequencies are averaged and you can no longer say, when exactly the frequencies occur.
This fact, of course, nullifies my original idea of ​​signal analysis. I calculated the speeds from the output signal (setting a threshold). Of course, the speeds are very high. Then I wanted to watch the frequencies with the Fourier transformation and describe that everything below 20000Hz can be taken out. Wanted to filter my time signal (: D) and then with a renewed fft show if it worked and then again calculate the speeds. With the high frequencies we also want to be able to detect errors in the mm range.
It's about ultrasonic waves going through a concrete body. These will then be examined in terms of energy content and speed.
But now my question : Are these signals, as I unfortunately suspect (ultrasound by a concrete body that is subjected to a pressure test) unsteady? The frequency changes with time, right? If so, do you still get the application of the short-time Fourier transform (spectrogram) justified? On the whole, it also retains the properties of the Fourier transformation. Otherwise, then probably would use the wavelet method or?

1 Comment

I have no background in acoustics, so I do not know the physics or characteristics of sound propagation, specifically through concrete.
You may be able to get some time information from the Fourier transform phase analysis (use the angle function, and perhaps also the unwrap function). I do not know if that would be appropriate for your signals.
The spectrogram is probably sufficient for doing a time-frequency analysis of your signal, although I cannot determine if it is appropriate to your application.
I would certainly experiment with wavelets. They have the ability to do a time-frequency analysis of your signal that might be what you want.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!