help me to write a code for processing an audio signal using taylor series
1 次查看(过去 30 天)
显示 更早的评论
clc;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x = x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x); xlabel('Seconds'); ylabel('Amplitude');
h = spectrum.periodogram; % create a periodogram spectral estimator.
figure(2)
psd(h,x,'Fs',Fs); % Calculates and plots the two-sided PSD.
%plot(psd(spectrum.periodogram,x,'Fs',Fs,'NFFT',length(x)));
y = interp(x,4);%resample data at a higher rate using lowpass interpolation
%[y, ty] = resample(x,t,Fs);
%y =resample(x,3,2);
figure(3)
subplot(211);
stem(x);
title('Original Signal');
subplot(212);
stem(y);
title('Interpolated Signal');
SNR = snr(x);
SNR1 = snr(y);
a=2;
N =2;
z = taylor(x,a,N);
plot(z);
3 个评论
Elavarasi E
2019-9-20
i need to sum up three different dimensions, which is in taylor series. this is in matrix and the equation is :
(x+h) = x + (h.*diff(x)) + (h^2.*diff(x,2))./factorial(2);
(x+h) is of same length of 'x' while first derivative is one lessthan 'x' and second derivative is of two lessthan of 'x'.
Elavarasi E
2019-9-28
In an audio signal, I need to find the intermediate samples. To read the intermediate I make use of taylor series. Audio signal is read thro’ [x,Fs] = audioread('audioe.wav');
The taylor series am using is f(x+h) = f(x) + hf’(x) + h2f’’(x)/2! .
Were f(x) is ‘x’ . Accordingly f(x+h) should be x(t)+h but this doesn’t work. ‘h’ is some intermediate value.
clc;
close all;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x= x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x);
xlabel('Seconds');
ylabel('Amplitude');
dx = gradient(x);
dx2 = gradient(dx);
for t = 0:dt:(length(x)/4*dt)-dt
for x = 0:dt:(length(x)/4*dt)-dt
h = 0.347;
y(t+h) = x + (h.*dx) + (h^2.*dx2)./factorial(2);
end
end
figure(2)
% hold on
plot(t,x,'blue',t,y, 'red')
% hold off
legend('actual','taylorseries')
for loop doesnt work
采纳的回答
darova
2019-9-20
Try gradient instead of diff
dx = gradient(x);
dx2 = gradient(dx);
result = x + (h.*dx) + (h^2.*dx2)./factorial(2);
21 个评论
Elavarasi E
2019-9-23
this is my code to read an audio signal
clc;
close all;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x= x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x);
xlabel('Seconds');
ylabel('Amplitude');
h = 0.347;
dx = gradient(x);
dx2 = gradient(dx);
for t1 = 0:dt:(length(x)*dt)-dt
(x+h) == x + (h.*dx) + (h^2.*dx2)./factorial(2);
end
figure(2)
hold on
plot(t,x,'blue',t1(:,1:length(x+h)),(x+h), 'red')
hold off
legend('actual','taylorseries')
the lengths same now. but, the for loop does not excecute nor do it shows me any error except doble equal sign. the second figure does appear at all.
darova
2019-9-23
What does it mean?
for t1 = 0:dt:(length(x)*dt)-dt
(x+h) == x + (h.*dx) + (h^2.*dx2)./factorial(2);
end
Elavarasi E
2019-9-23
am equating the time t1 to t which nothing but dt . in this for loop i get an error wrt equal sign
Elavarasi E
2019-9-23
i need to process the read audio signal through taylor series. the length of the fine processed audio signal will be same as that of the actual signal. so i use a 'for' loop as the length of time 't' and plot the fine processed signal wrt 't'. but the for loop is not exceuting nor does it show me any error.
Elavarasi E
2019-9-23
the only error it shows is about equal sign n it guides me to use double equal sign.
Elavarasi E
2019-9-23
f(x+h) = f(x) + hf'(x) + h^2f''(x)/2!
i need to find the intermediate value of f(x) at instance z = x+dt where both time n signal are variable.
darova
2019-9-23
Please show the error occurs and why it guides you to use double sign
Why it doesn't work?
result = x + (h.*dx) + (h^2.*dx2)./factorial(2);
Elavarasi E
2019-9-28
In an audio signal, I need to find the intermediate samples. To read the intermediate I make use of taylor series. Audio signal is read thro’ [x,Fs] = audioread('audioe.wav');
The taylor series am using is f(x+h) = f(x) + hf’(x) + h2f’’(x)/2! .
Were f(x) is ‘x’ . Accordingly f(x+h) should be x(t)+h but this doesn’t work. ‘h’ is some intermediate value.
this my modified code again does not work for the "for" loop
clc;
close all;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x= x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x);
xlabel('Seconds');
ylabel('Amplitude');
dx = gradient(x);
dx2 = gradient(dx);
for t = 0:dt:(length(x)/4*dt)-dt
for x = 0:dt:(length(x)/4*dt)-dt
h = 0.347;
y(t+h) = x + (h.*dx) + (h^2.*dx2)./factorial(2);
end
end
figure(2)
% hold on
plot(t,x,'blue',t,y, 'red')
% hold off
legend('actual','taylorseries')
Elavarasi E
2019-9-30
clc;
close all;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x= x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x);
xlabel('Seconds');
ylabel('Amplitude');
for t = 1:dt:(length(x)/4*dt)-dt
for k = 1:length(x)/32
dx(k) = gradient(x(k));
dx2(k) = gradient(dx(k));
h = 0.347;
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2);
end
end
figure(2)
% hold on
plot(t,x,'blue',t,y, 'red')
% hold off
legend('actual','taylorseries')
Results :
Name Size Bytes Class Attributes
x 2395137x2 38322192 double 44100
Array indices must be positive integers or logical values.
Error in eaudiodiff (line 24)
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2);
1) guide me to solve theabove error.
2) when i execute these statements individually on comment window
k = 1:length(x)/32
dx(k) = gradient(x(k))
dx2(k) = gradient(dx(k))
h = 0.347
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2)
I get an error as memoryspace exceeded.
darova
2019-9-30
I don't have your data so i generated some random
n = 100;
Fs = 2000;
dt = 1/Fs;
t = 0:dt:(n*dt)-dt;
x = 0.05*sin(2000*t) + cos(100*t); % random data
dx = gradient(x);
dx2 = gradient(dx);
h = 0.347;
x1 = x + h.*dx + h^2.*dx2./factorial(2);
plot(t,x,'blue',t,x1, '.r')
legend('actual','taylorseries')
xlabel('Seconds');
ylabel('Amplitude');
And here are the results
![img1.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/240514/img1.png)
![img2.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/240515/img2.png)
Slightly differs is it?
Elavarasi E
2019-10-1
Appreciate your kindness. Ya it differs. Actually I have to process it on any audio signal.
when I execute the entire code I get these errors
Array indices must be positive integers or logical values.
Error in eaudiodiff (line 24)
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2);
1) guide me to solve the above error.
2) when i execute these statements individually on comment window
k = 1:length(x)/32
dx(k) = gradient(x(k))
dx2(k) = gradient(dx(k))
h = 0.347
I get the correct values but when the below equation is executed
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2)
I get an error as memoryspace exceeded.
need to rectify these two errors.
Elavarasi E
2019-10-1
ur code is correct but its only for one instance at x1, which should actually be x+h, i.e x1 = (x+h). i need to evaluate it for all the values of x displaced by the instance 'h' wrt to 't'.
i.e., y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2)
y(0+h) is the output at instance x(0). were x(0) is calculated using taylor series. this has to repeat for all 't'.
darova
2019-10-1
Maybe try this
result = x + (h.*dx) + (h^2.*dx2)./factorial(2);
result = result + h;
% result = result - h;
Elavarasi E
2019-10-2
Very much appreciate your prompt response.
here I need to find the value at instance (t+h) but result = result + h will give me output + h and not output at time (t+h).
i.e if output is 20 , t= 5 and h = 0.112
as per result = result + h; i'll get the result as 20.112 at time t = 5 but at the instance t = 5.112 it will be some 'xx' value.
I need this 'xx' value. this can be done only by varying both time and amplitude.
darova
2019-10-2
So add it to t
x1 = x + (h.*dx) + (h^2.*dx2)./factorial(2);
t1 = t + h;
plot(t,x,t1,x1)
Elavarasi E
2019-10-23
hi !
let 'n' be a sequence. it should be broken down into samples of length 1024.
i.e n/1024 = y spectrum.
i should plot this 'y' spectrum as overlapped spectrums with an overlap of 48 samples on each spectrum. the last spectrum can be padded with zeroes at the last.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Generation and Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)