Wavplay

3 views (last 30 days)
Vagelis Kounis
Vagelis Kounis on 4 Apr 2011
Commented: mariam sleiman on 4 Jan 2019
I have created a .m file that includes a Fourier transformation of a square wave function without the use of the fft or any other matlab expression. Now i want to listen to the created function using wavplay but i can't. It seems that i have to build a matrix but the problem is that i used syms for my variable and therefore my function is symbolic and not a matrix of numbers.. Can anyone help me? I have tried to convert from syms t to t=1:.1:100 but then i get an error that matrix dimensions don't agree.. here is my code:
syms t
T=pi;
N=15;
for n=1:2:N
y(n)=4/pi*1/n*sin(2*pi*n*t/T);
end
palmos=sum(y);
ezplot(palmos)
axis([0 2*T -1.5 1.5])

Answers (1)

Jarrod Rivituso
Jarrod Rivituso on 5 Apr 2011
When you switch t to being a vector, you can't store an entire vector into a single basic element y(n). You could do this in a single cell with y{n}, but since you are just summing it later, you could also perform the sum within the loop.
Here is how I'd change your code. Note I made a few other adjustments too, namely a higher sampling frequency and shorter vector.
fs = 8000;
t = 0:1/fs:10;
T = pi;
N = 15;
y = zeros(size(t));
for n = 1:2:N
y = y + (4/pi)*(1/n)*sin(2*pi*n*t/T);
end
plot(t,y);
wavplay(y,fs);
  1 Comment
mariam sleiman
mariam sleiman on 4 Jan 2019
please can usend me wavplay.m function becouse i work ondenoising a speech an need this func.,thank u. regards

Sign in to comment.

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!