Sine wave change zero crossing and increase amplification

Hi
I have attached a picture of a sine wave, can it be modified ie all centred around zero, all peaks and troughs the same size?
Any help would be appreciated.
David

2 Kommentare

What exactly do you want to extract from the data, after you have manipulated as you describe? Have you considered a Fourier analysis of the data?
Please attach your data in a .mat file if you want people to try anything to help you.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 7 Sep. 2020

0 Stimmen

First, use the fft function to do a Fourier transform to see what the signal frequency components are.
After that, it should be straightforward to design a highpass filter to eliminate both the D-C offset and baseline drift, so the result will be close to what you want.

7 Kommentare

Hi
Thanks for getting back, I havent been using Matlab much I can create an fft but am usure of how to use the x axis to display the fft correctly my sample rate is 2500000 and number of samples are 200000 can you please advice me.
Thanks
Have a look at the first example inf the link to the fft-function provided by Star Strider. It does exactly what you want to do. Or is there something unclear with that example?
Johannes Fischer — Thank you for your Comment!
One way to compute the Fourier transform is:
L = 200000;
Fs = 2500000;
Fn = Fs/2; % Nyquist Frequency
t = linspace(0, 200000, L)/Fs; % Create Time Vector
s = sin(2*pi*2*t)+0.124; % Create Signal Vector
sm = mean(s);
FTs = fft(s - sm)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FTs(Iv))*2)
grid
title('Fourier Transform - Original Signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude (?)')
xlim([0 1E3]) % Optional
There should be at least 2 peaks, one (or more) for the very slow baseline variation and another for the signal itself. It will likely be necessary to limit the frequency axis (as I did here) to see them clearly. Set the cutoff frequency of the highpass filter to a value between the lower-frequency peaks in the Fourier transform plot and the signal frequency peak. The purpose of subtracting the mean of the signal before taking the Fourier transform is to eliminate the baselkine offset, making the signal peaks more apparent.
Thank you for your excellent help greatly appreciated.
I have one last question what is the best way (most accurate) after using the high pass filter to turn the Sine wave to a Square.
Thank You
My pleasure!
The only way that I am aware of to turn a single sine wave into a square wave is to use a comparator (in hardware) or simply to take the sign (in software):
s2 = sin(2*pi*t*2);
sqwv = sign(s2);
figure
plot(t, s2)
hold on
plot(t, sqwv, 'LineWidth',1.5)
hold off
grid
xlabel('Time')
ylabel('Amplitude')
ylim([-1.1 1.1])
producing this plot:
There might be other ways. This is the easiest.
A square wave is composed of the sum of the scaled odd harmonics of the original signal:
t = linspace(0, 1, 250);
s = sin((1:2:12).'*2*pi*2*t) ./ (1:2:12).';
ss = sum(s);
figure
plot(t, s)
hold on
plot(t, ss, 'LineWidth',2)
hold off
grid
xlabel('Time')
ylabel('Amplitude')
producing this plot:
So conversely, with a frequency-selective filter, it is possible to create a sine wave out of a square wave by filtering out the harmonics (or selected harmonics) with a lowpass or bandpass filter.
David Jones
David Jones am 10 Sep. 2020
Bearbeitet: David Jones am 10 Sep. 2020
Thank you for all your help
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by