Borrar filtros
Borrar filtros

adding of signals

71 visualizaciones (últimos 30 días)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran el 26 de Abr. de 2012
Respondida: Sk Group el 8 de Feb. de 2021
Hi, When we add two images, we need to maintain same dimension to add. I need to add two wave signals. How to alter their dimensions, so that i can add.

Respuesta aceptada

Image Analyst
Image Analyst el 26 de Abr. de 2012
The imresize in your Image Processing Toolbox will also work on one dimensional signals.
% Make wave 2 the same length as wave 1.
resizedWave2 = imresize(wave2, length(wave1));
  12 comentarios
meziane madani
meziane madani el 4 de Mayo de 2017
Editada: meziane madani el 4 de Mayo de 2017
hello; i tried to do what you said, but i have this error :imresize: IM must be a grayscale or RGB image, so i don't think that we can applicate it from a song
Image Analyst
Image Analyst el 4 de Mayo de 2017
It can be a song. Here's proof for two stereo waveforms:
[y1, fs1] = audioread('C:\Users\Public\Music\Sample Music\Sleep Away.mp3'); % Stereo
[y2, fs2] = audioread('C:\Users\Public\Music\Sample Music\Maid with the Flaxen Hair.mp3'); % Stereo
% [y2, fs2] = audioread('guitartune.wav'); % Mono signal
whos y1 fs1
% Name Size Bytes Class Attributes
%
% fs1 1x1 8 double
% y1 8845056x2 141520896 double
whos y2 fs2
% Name Size Bytes Class Attributes
%
% fs2 1x1 8 double
% y2 7483391x2 119734256 double
[rows1, columns1] = size(y1)
[rows2, columns2] = size(y2)
% Make wave 2 the same length as wave 1. Code if both are stereo.
resizedWave2 = imresize(y1, [rows2, columns2]);
whos resizedWave2 % Proves y1 same size as y2.
It can get a little tricky if one is stereo and one is mono. Is that what you had?

Iniciar sesión para comentar.

Más respuestas (2)

Richard Brown
Richard Brown el 26 de Abr. de 2012
Also you can use interp1 if you don't have the image processing toolbox

Sk Group
Sk Group el 8 de Feb. de 2021
MATLAB CODE:
function [y n] = sigadd(x1,n1,x2,n2)
if n1(1)< n2(1)
a = n1(1)
x1 = [zeros(1,abs(n1(1)-n2(1))) x1]
else
a = n2(1)
x1 = [zeros(1,abs(n1(1)-n2(1))) x1]
end
if n1(end)>n2(end)
b = n1(end)
x2 = [x2 zeros(1,abs(n1(end)-n2(end)))]
else
b = n2(end)
x2 = [x2 zeros(1,abs(n1(end)-n2(end)))]
end
n = a:b;
y = x1+x2;
MATLAB CODE:
function [y n] = sigadd_another_method(x1,n1,x2,n2)
n = min(min(n1),min(n2)):max(max(n1),max(n2));
y1 = zeros(1,length(n));
y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y = y1+y2;

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by