i am adding gaussian noise signal to an audio signal. but in plotting i am receiving an error " ??? Error using ==> plot Vectors must be the same lengths" how can i make equal vectors?

3 ビュー (過去 30 日間)
[y,fs,nbits]=wavread('C:\Users\HP\Desktop\s1.wav');
n=randn(size(y))*sigma+mu*ones(size(y));
ny=length(y);
nn=length(n);
N=min([ny nn]);
Y=y(1:N);
Z=n(1:N);
signal=Y+Z;
%%%%%%%%%
t = 0:1/fs:1-1/fs;
y = cos(2*pi*1000*t)+1/2*sin(2*pi*2000*t)+randn(size(t));
DF = fs/length(y);
ydft = fftshift(fft(y))
N = length(y);
f=(-1/2:1/N:1/2-1/N)*fs; %%%%%%%%%%%
t = 0:1/fs:1-1/fs;
y = cos(2*pi*1000*t)+1/2*sin(2*pi*2000*t)+randn(size(t));
DF = fs/length(signal);
signaldft = fftshift(fft(signal));
plot(f,abs(signaldft))

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 4 月 29 日
When you use y(1:N) then you are going to have difficulty if y has multiple channels (e.g., 2 channels for stereo) y(1:N,:) would extract the first N in each channel; y(1:N,1) for the first channel.
At the command line, please command
dbstop if error
and run your program. When it stops, please show
N, size(y), size(signal), size(signaldft), size(f)
Side note: another way of expressing
f=(-1/2:1/N:1/2-1/N)*fs;
would be
f = linspace(-fs/2, fs/2, N+1);
f(end) = [];

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by