Anyone know how to normalise my signal ( want to restrict it's range to plus/minus 1 i.e. mean=0)?

2 views (last 30 days)
I'm basically trying to normalise the "M" signal here (but it can be the same for the "Q" signal as well) and I know that I just need to take the mean away from it in order to restrict the range to plus minus 1. I tried putting in x(1) - length(M) etc but that didn't work. Just wondering if anyone can help thanks!
Fclk = 200000000/208;
Q = csvread('sin11k_0_9615MSPS.csv');%read in data points (undistorted)
M = csvread('Distorted_Data.csv');
Npt=length(M);
%VARIABLES FOR SINE WAVE CREATION
Amp=20000; %from roughly max of values
DC=32000;
Phi=-1.5; %phase difference
Fsig = 11000;
x0=[Amp DC Phi Fsig];
x=fminsearch(@ModelData, x0);
PPT= 250;
% Create array of time values
t = 0 : 1/Fclk : (Npt/Fclk);
t = t(1:Npt);
s1 = x(2) + x(1)*cos(2 * pi * x(4) * t + x(3));
% plot(t(1:PPT),s1(1:PPT))
% hold on
% plot(t(1:PPT),M(1:PPT),'red')
% hold off
% title('Rough Sine wave')
% ylabel('Amp')
% figure;
%
% plot(t(Npt-PPT:Npt),s1(Npt-PPT:Npt))
% hold on
% plot(t(Npt-PPT:Npt),M(Npt-PPT:Npt),'red')
% hold off
% title('Last samples')
% ylabel('Amp')
Nfit = 1000; % number of samples in the segment (rows in matrix)
A = [ ((M(1:Nfit)).^3)' ((M(1:Nfit)).^2)' (M(1:Nfit))' ones(Nfit,1)]; % Create matrix of powers of data segment (last column all 1s)
B = (s1(1:Nfit))'; % Desired output is undistorted sinusoid (column vector)
C = A\B;
Hp = spectrum.periodogram('hann');
PSD_A=psd(Hp, M, 'Fs', Fclk);
D=polyval(C,M);
PSD_D=psd(Hp, D, 'Fs', Fclk);
hold on
h1 = plot(PSD_A);
set(h1,'Color','b');
h2 = plot(PSD_D);
set(h2,'Color','r');
title('PSD of input (blue) and corrected sine wave (red)')
hold off

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 22 Jan 2013
Edited: Azzi Abdelmalek on 22 Jan 2013
y=randi(10,1,100) % your signal
new_y=2*(y-min(y))/(max(y)-min(y))-1

Community Treasure Hunt

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

Start Hunting!