2011-10-27 10 views
0

J'ai un signal qui est créé de 0 à 1 pour le carré, le rectangle et les signaux en dents de scie sur l'axe y comment puis-je décaler le signal (décalage vertical) pour que le signal passe de -0,5 à 0,5 sur l'axe y, et changer le signal de triangle de 0,5 à 1,0 à -0,5 à 0,5?Décalage du signal

clear all 
% SCRIPT BEGINS 
t=linspace(0,1,22050) 
freq=5%how many times it repeats in 1 sec 
A = 1; % amplitude 
T = 1/freq; % period of the signal 

% square 
square = mod(t * A/T, A) > A/2; 
plot(t, square) 
title('Square'); 

% rectangle 
l = 0.2; % percentage the signal spends on low value 
rectangle = mod(t * A/T, A) > A * l; 
figure; 
plot(t, rectangle); 
title('Rectangle'); 

% sawtooth 
sawtooth = mod(t * A/T, A); 
figure; 
plot(t, sawtooth); 
title('Sawtooth'); 

% triangle 
triangle = (mod(t * A/T, A) > 0.5).*mod(t * A/T, A) + (mod(t * A/T, A) <= 0.5).*(1 - mod(t * A/T, A)); 
figure; 
plot(t, triangle); 
title('triangle'); 

merci J'utilise octave/Matlab

Répondre

0
function x_new = rescale(x, new_min, new_max) 

x_min = min(x); 
x_max = max(x); 

x_new = new_min + (new_max - new_min) * (x - x_min)/(x_max - x_min); 

(BTW ce qui est très mathématique de base qui aurait pu être facilement googlé)

0

Voici le code dans le cas où il aide la personne suivante

clear all 
% SCRIPT BEGINS 
t=linspace(0,1,22050); 
freq=5; %how many in 1 sec 
%t = 0:0.01:1; %time vector 
A = 1; % amplitude 
T = 1/freq; % period of the signal 

vertoffset=0.5; 
% square 
square = mod(t * A/T, A) > A/2; 
square = square - vertoffset; 
plot(t, square) 
title('Square'); 

% rectangle 
l = 0.2; % percentage the signal spends on low value 
rectangle = mod(t * A/T, A) > A * l; 
rectangle = rectangle - vertoffset; 
figure; 
plot(t, rectangle); 
title('Rectangle'); 

% sawtooth 
sawtooth = mod(t * A/T, A); 
sawtooth = sawtooth -vertoffset; 
figure; 
plot(t, sawtooth); 
title('Sawtooth'); 

% triangle 
triangle = (mod(t * A/T, A) > 0.5).*mod(t * A/T, A) + (mod(t * A/T, A) <= 0.5).*(1 - mod(t * A/T, A)); 
triangle = 2*triangle - 1.5; 
figure; 
plot(t, triangle); 
title('triangle');